mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 16:00:43 +00:00
中转站加下载区 + 大文件流式发送
下载区
- 管理页加一张「下载最新版」卡片,就一个按钮
自动指向 /v1/downloads 里最新的被控端整包,不用每次改页面
- GET /v1/downloads 列出成品
- GET /download/<文件> 直接给文件
只允许白名单后缀(.apk/.zip/.txt/.exe/.idsig)
文件名严格校验,挡目录穿越(../ 和 ..%2F 都试过)
- 卡片下面附一个 Gitee 历史版本入口
大文件
- 原来 read_bytes() 一次性读进内存再 write。
19MB 在 460MB 的设备上勉强,更要命的是 Cloudflare
有 100 秒的源站响应上限,数据越晚开始流动越容易被掐。
- 改成 64KB 分块流式发送,边读边发
实测:19MB 公网下载 40 秒完成,字节数完全一致
版本
- 三端分开打包(原来是一个合并 zip)
ykxmz-agent-1.5.0.zip 被控端
ykxmz-server-1.5.0.zip 服务器端
ykxmz-watch-1.5.0.apk 控制端(直接给 APK)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
r"""修上一步闯的祸:JS 在 f-string 里,大括号必须写两遍。
|
||||
|
||||
上一步把下载区的 JS 换成新版时用了单大括号 { },
|
||||
但那一段是 f-string —— 单大括号会被当成占位符,
|
||||
于是 relay.py 报 "f-string: invalid syntax"。
|
||||
|
||||
(原来那段用的是 {{ }},我漏看了。)
|
||||
"""
|
||||
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")
|
||||
|
||||
# f-string 里要写双大括号的版本
|
||||
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 = '<span style="color:#8b949e">服务器上还没有成品。</span>';
|
||||
return;
|
||||
}}
|
||||
// 优先挑被控端整包;没有就挑第一个 zip;再没有就第一个
|
||||
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 =
|
||||
'<a href="/download/' + encodeURIComponent(pick.name) + '" '
|
||||
+ 'style="display:inline-block;padding:10px 20px;border-radius:6px;'
|
||||
+ 'background:#238636;color:#fff;text-decoration:none;'
|
||||
+ 'font-weight:600;font-size:15px">'
|
||||
+ '⬇ 下载 ' + pick.name + '</a>'
|
||||
+ '<div style="color:#6e7681;font-size:12px;margin-top:8px">'
|
||||
+ mb + ' MB · 也可以去 '
|
||||
+ '<a href="https://gitee.com/xmz7891/ykxmz/releases" target="_blank" '
|
||||
+ 'rel="noopener" style="color:#79c0ff">Gitee 历史版本</a>'
|
||||
+ '</div>';
|
||||
}} catch (e) {{
|
||||
body.innerHTML = '<span style="color:#f85149">读不到:' + e + '</span>';
|
||||
}}
|
||||
}})();
|
||||
|
||||
// ---------------- 自动刷新 ----------------'''
|
||||
|
||||
|
||||
def main() -> int:
|
||||
text = RELAY.read_text(encoding="utf-8")
|
||||
|
||||
# 先确认现在确实是坏的
|
||||
try:
|
||||
ast.parse(text)
|
||||
print(" 语法本来就是好的,不用修")
|
||||
return 0
|
||||
except SyntaxError as exc:
|
||||
print(f" 当前语法错误在行 {exc.lineno}(预期之内)")
|
||||
|
||||
# 把"下载"注释到"自动刷新"之间整段换掉
|
||||
pattern = re.compile(
|
||||
r'// ---------------- 下载.*?// ---------------- 自动刷新 ----------------',
|
||||
re.S)
|
||||
match = pattern.search(text)
|
||||
if not match:
|
||||
print(" [失败] 找不到要替换的 JS 段")
|
||||
return 1
|
||||
|
||||
text = text[:match.start()] + NEW_JS + text[match.end():]
|
||||
RELAY.write_text(text, encoding="utf-8", newline="\n")
|
||||
|
||||
try:
|
||||
ast.parse(text)
|
||||
print(" ✓ relay.py 语法恢复正常(大括号改成 {{ }})")
|
||||
except SyntaxError as exc:
|
||||
print(f" ✗ 还有错:行 {exc.lineno}: {exc.msg}")
|
||||
# 打印出错行附近,便于定位
|
||||
lines = text.splitlines()
|
||||
for i in range(max(0, (exc.lineno or 1) - 3),
|
||||
min(len(lines), (exc.lineno or 1) + 2)):
|
||||
print(f" {i + 1}: {lines[i][:100]}")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user