Skip to content

Commit

Permalink
new templates integrity check to ease updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaaoBlues committed Jun 26, 2022
1 parent 3c87df6 commit 1c535d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 4 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
@@ -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}"})
Expand Down Expand Up @@ -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")
#send_url("https://www.google.com")

check_templates_update()
35 changes: 17 additions & 18 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 1c535d5

Please sign in to comment.