diff --git a/interface.py b/interface.py index bedeb2a..2b1ce79 100644 --- a/interface.py +++ b/interface.py @@ -7,5 +7,5 @@ from os import walk sites = next(walk('cached/'), (None, None, []))[1] for i in sites: - addr = f"http://127.0.0.1:8000/{i}/index.html" + addr = f"http://127.0.0.1:8000/{i}" f"[{i}]({addr})" diff --git a/network.py b/network.py index 38b8985..60795dd 100644 --- a/network.py +++ b/network.py @@ -8,7 +8,8 @@ from random import randint from shutil import unpack_archive # Убираем ненужное (../some => some) from re import compile, sub -# Timeout для команды +# Работа с БД +from db import read from verify import * from domain_check import * @@ -123,6 +124,21 @@ def client(port, op = "ping"): return data elif op[:4] == "get_": site = op[4:] + + # Проверяем версию если сайт кеширован + if os.path.exists(f"cached/{site}"): + # Версия запрашиваемого + dest_conf = get(f"http://{host}:{str(port)}/{site}/config.json") + conf_unform = dest_ver.content.decode('utf8') + conf = json.loads(conf_unform) + dest_ver = conf["ver"] + # Версия нашего сайта + our_conf = read(f"cached/{site}/config.json") + our_ver = our_conf["ver"] + # Если версия не новее - не скачиваем + if our_ver >= dest_ver: + return "old" + # Скачиваем файлы g_site = get(f"http://{host}:{str(port)}/{site}.zip") print('SIZE: ', g_site.headers['Content-Length']) # Размер