更改文件保存路径,便于将部分请求重定向到官网

This commit is contained in:
wcbing 2024-08-25 01:41:02 +08:00
parent 8e33fb6f7d
commit 86d8ef4207
2 changed files with 27 additions and 2 deletions

View File

@ -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;
}
}
```

View File

@ -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: