# -*- coding: utf-8 -*-
r"""下载区简化成"一个链接"(用户要求)。
用户:"没有,你就放一个下载连接就行了"
所以把原来那套(文件列表 + 大小 + 大文件提示 + Gitee 备用入口)
全部去掉,只留**一行一个链接**,点了就能下。
链接指向中转自己的下载区(/v1/downloads 里最新的那个文件),
这样不管叫什么都自动指向最新的,不用每次改页面。
同时保留流式发送(19MB 走隧道本来就慢,
一次性读进内存再发更容易被 Cloudflare 100 秒上限掐断)。
"""
from __future__ import annotations
import ast
import re
import sys
from pathlib import Path
RELAY = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\relay" r"\relay.py")
NEW_CARD = '''
'''
NEW_JS = '''// ---------------- 下载(就一个链接)----------------
(async () => {
const body = document.getElementById('dlBody');
if (!body) return;
try {
const r = await fetch('/v1/downloads');
const j = await r.json();
const files = (j && j.files) || [];
if (!files.length) {
body.innerHTML = '服务器上还没有成品。';
return;
}
// 按名字里的版本号挑最新的那个整包;没有就挑第一个
const pick = files.find(f => /agent/i.test(f.name))
|| files.find(f => /\\.zip$/i.test(f.name))
|| files[0];
const mb = (pick.size / 1024 / 1024).toFixed(2);
body.innerHTML =
''
+ '⬇ 下载 ' + pick.name + ''
+ '';
} catch (e) {
body.innerHTML = '读不到:' + e + '';
}
})();
// ---------------- 自动刷新 ----------------'''
def main() -> int:
text = RELAY.read_text(encoding="utf-8")
if "下载最新版" in text:
print(" 已经是简化版")
return 0
# 1) 卡片:把原来那张(可能已经改过)整块换掉
card = re.search(
r' .*?\n
\n', text, re.S)
if card:
text = text[:card.start()] + NEW_CARD + "\n" + text[card.end():]
print(" 卡片简化成一个「下载最新版」")
else:
print(" [失败] 找不到下载卡片")
return 1
# 2) JS:把"下载区"那一整段换成新的(从注释到"自动刷新"之前)
js = re.search(
r'// ---------------- 下载.*?// ---------------- 自动刷新 ----------------',
text, re.S)
if js:
text = text[:js.start()] + NEW_JS + text[js.end():]
print(" JS 简化成一个链接")
else:
print(" [失败] 找不到下载 JS 段")
return 1
RELAY.write_text(text, encoding="utf-8", newline="\n")
try:
ast.parse(text)
print(" relay.py 语法 OK")
except SyntaxError as exc:
print(f" 语法错误: 行 {exc.lineno}: {exc.msg}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())