From 1c535d5358bd15c3d7f2d0ffb396302a12ed3282 Mon Sep 17 00:00:00 2001 From: ThaaoBlues Date: Sun, 26 Jun 2022 18:26:19 +0200 Subject: [PATCH] new templates integrity check to ease updates --- client.py | 6 ++++-- util.py | 35 +++++++++++++++++------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/client.py b/client.py index 34f85fa..7fd6ced 100644 --- a/client.py +++ b/client.py @@ -1,6 +1,6 @@ import requests from ast import literal_eval - +from util import * def send_text_scan(text): r = requests.post("http://127.0.0.1:21987/upload",json={"type" : "text", "content" : f"{text}"}) @@ -40,4 +40,6 @@ def send_url(url): #send_file("static/qr.jpeg") #send_text_scan("test of text scan") #send_wifi("This_is_a_wifi_name","wpa","password") -#send_url("https://www.google.com") \ No newline at end of file +#send_url("https://www.google.com") + +check_templates_update() \ No newline at end of file diff --git a/util.py b/util.py index ec4888d..fba836a 100644 --- a/util.py +++ b/util.py @@ -17,6 +17,10 @@ from platform import system + +TEMPLATES_FILES = ["favicon.ico","index.html","scan_preview.html","img_preview.html","video_preview.html"] + + def notify_desktop(title,text): # initialize toaster = ToastNotifier() @@ -58,6 +62,15 @@ def make_qr_url(): def check_templates_update(): + + # check templates integrity + for ele in TEMPLATES_FILES: + if not path.exists(f"templates/{ele}"): + download_templates() + return + + + # check 10 startup rule with open("static/update.Blue","r") as f: n = int(f.read()) if n == 10: @@ -111,25 +124,11 @@ def is_server_already_running(): def download_templates(): #get the templates - r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/index.html",allow_redirects=True) - with open("templates/index.html","wb") as f: - f.write(r.content) - - r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/scan_preview.html",allow_redirects=True) - with open("templates/scan_preview.html","wb") as f: - f.write(r.content) - - r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/img_preview.html",allow_redirects=True) - with open("templates/img_preview.html","wb") as f: - f.write(r.content) + for ele in TEMPLATES_FILES: - r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/video_preview.html",allow_redirects=True) - with open("templates/img_preview.html","wb") as f: - f.write(r.content) - - r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/favicon.ico",allow_redirects=True) - with open("static/favicon.ico","wb") as f: - f.write(r.content) + r = get(f"https://raw.githubusercontent.com/copypastaofficial/copypasta/master/templates/{ele}",allow_redirects=True) + with open(f"templates/{ele}","wb") as f: + f.write(r.content) with open("static/update.Blue","w") as f: f.write("1")