From 86d8ef420710580332f4cc1b2fddd67b33ec2b03 Mon Sep 17 00:00:00 2001 From: wcbing Date: Sun, 25 Aug 2024 01:41:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=96=87=E4=BB=B6=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E8=B7=AF=E5=BE=84=EF=BC=8C=E4=BE=BF=E4=BA=8E=E5=B0=86?= =?UTF-8?q?=E9=83=A8=E5=88=86=E8=AF=B7=E6=B1=82=E9=87=8D=E5=AE=9A=E5=90=91?= =?UTF-8?q?=E5=88=B0=E5=AE=98=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++++++++++++++++ get/module/check.py | 7 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c223623..4e8fce5 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,25 @@ crontab 样例:0 11,15,19 * * * cd [THIS_DIR] && ./update_gen.sh > ./deb/statu 这个仓库使用了[扁平仓库格式(Flat Repository Format)](https://wiki.debian.org/DebianRepository/Format#Flat_Repository_Format)。建立好后使用 Web 服务器将 `deb` 目录暴露出去即可。 使用时可参考前面已有的配置,先将第3部提到的 GPG 公钥导入,再新建软件源配置文件。 + +实际使用中官网提供的下载链接一般是 CDN 链接,为提升下载速度,减轻自建源压力,建议将这些请求重定向到官网上。而国内下载 Github 上的文件时比较慢,仍然从自建源下载。 + +nginx 配置参考: +```nginx +server { + server_name packages.wcbing.top; + autoindex on; + autoindex_exact_size off; + autoindex_localtime on; + charset 'utf-8'; + location ~ ^/deb/https:/github.com { + root /packages; + } + location ~ ^/deb/https:/(.+)$ { + return 302 https://$1; + } + location / { + root /packages; + } +} +``` \ No newline at end of file diff --git a/get/module/check.py b/get/module/check.py index 64c48ad..295cc4c 100644 --- a/get/module/check.py +++ b/get/module/check.py @@ -4,7 +4,10 @@ import sqlite3 def download(url, file_type): - file_path = os.path.join(file_type, str(url.split("/")[-1])) + file_dir = os.path.join(file_type, "/".join(url.split("/")[:-1])) + if not os.path.exists(file_dir): + os.makedirs(file_dir) + file_path = os.path.join(file_type, url) with requests.get(url, stream=True) as res: with open(file_path, "wb") as fw: for chunk in res.iter_content(chunk_size=8192): @@ -32,7 +35,7 @@ def check_download(name, version, url, arch, file_type): (version, url, name), ) # remove old version - old_file_path = os.path.join(file_type, str(db_url.split("/")[-1])) + old_file_path = os.path.join(file_type, db_url) if os.path.exists(old_file_path): os.remove(old_file_path) else: