mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 14:50:45 +00:00
阶段1 网络加速 - 发现隧道在跑 QUIC(ExecStart 丢了 --protocol http2), 实测 QUIC 可用率 48% vs HTTP/2 80%+,是重大性能回退。 恢复后公网延迟从 4141ms 降到 690ms(快 6 倍),可用率 92%。 - 优选 IP 结论:无效。hosts 覆盖确实生效了(日志里连的就是指定 IP), 但落点仍是 lax —— 运营商把所有 Cloudflare anycast 都路由到美西。 已清掉这段无效配置。 - BBR 不可用:设备是自定义内核 6.4.0-rc4-jsbsbxjxh66, 没编 tcp_bbr 模块也没配置项。改用 cubic + 调优: TCP 缓冲 4MB、tcp_fastopen=3、tcp_slow_start_after_idle=0 (长轮询场景关键)、tcp_tw_reuse=1。 阶段2 官网重做 - 拆出独立模块 relay/landing.py(relay.py 已两千多行, 再塞 HTML 没法看) - 信息结构参考成熟产品站:吸顶导航 / Hero / 九宫格功能 / 三步上手 / 下载 / FAQ / 页脚 - 保持白色简洁:底白、浅灰面板、细边框、大量留白 - logo 用内联 SVG(ICO 放 img 里实测是破图) - 管理入口从官网移除(管理不对外开放) 过程中被自己的测试抓到两个 bug: - 模块叫 site.py 会和 Python 标准库重名,import site 拿到的是标准库 - _logo() 里把 % 格式化和字符串拼接混用,直接抛 TypeError
89 lines
2.8 KiB
Python
89 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
r'''把官网渲染换成新的独立模块 site.render_site()。
|
||
|
||
原来的 _site_page() 是内联在 relay.py 里的一大段 HTML。
|
||
现在拆到 relay/site.py,relay.py 里只留一个薄封装。
|
||
'''
|
||
from __future__ import annotations
|
||
|
||
import ast
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
||
RELAY = ROOT / "relay" / "relay.py"
|
||
|
||
# 找出 _site_page 函数的起止,整段替换
|
||
NEW_FUNC = '''def _site_page() -> str:
|
||
"""官网首页(公开,不用登录)。
|
||
|
||
实际渲染在 relay/site.py —— relay.py 已经两千多行,
|
||
再放几百行 HTML 就没法看了。网站属于展示层,
|
||
跟中转逻辑分开更清楚。
|
||
"""
|
||
try:
|
||
from site import render_site
|
||
except ImportError:
|
||
# 打包/部署时 relay 目录就是工作目录,用相对导入兜底
|
||
import importlib.util
|
||
spec = importlib.util.spec_from_file_location(
|
||
"ykxmz_site", Path(__file__).resolve().parent / "site.py")
|
||
module = importlib.util.module_from_spec(spec)
|
||
spec.loader.exec_module(module)
|
||
render_site = module.render_site
|
||
return render_site(_list_downloads())
|
||
'''
|
||
|
||
|
||
def main() -> int:
|
||
text = RELAY.read_text(encoding="utf-8")
|
||
|
||
if "from site import render_site" in text:
|
||
print(" 已经接过了")
|
||
return 0
|
||
|
||
start = text.find("def _site_page() -> str:")
|
||
if start < 0:
|
||
print(" [失败] 找不到 _site_page")
|
||
return 1
|
||
|
||
# 找到下一个顶层 def
|
||
nxt = text.find("\ndef ", start + 10)
|
||
if nxt < 0:
|
||
print(" [失败] 找不到 _site_page 的结尾")
|
||
return 1
|
||
|
||
text = text[:start] + NEW_FUNC + "\n" + text[nxt + 1:]
|
||
|
||
# 确保 Path 和 _list_downloads 可用
|
||
if "\nfrom pathlib import Path" not in text:
|
||
text = text.replace("import os\n", "import os\nfrom pathlib import Path\n", 1)
|
||
print(" 补 from pathlib import Path")
|
||
|
||
RELAY.write_text(text, encoding="utf-8", newline="\n")
|
||
print(" _site_page 改成调用 site.render_site()")
|
||
|
||
try:
|
||
ast.parse(text)
|
||
print(" relay.py 语法 OK")
|
||
except SyntaxError as exc:
|
||
print(" [失败] 语法错误: 行 %s: %s" % (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(" %d: %s" % (i + 1, lines[i][:90]))
|
||
return 1
|
||
|
||
# site.py 也检查一下
|
||
try:
|
||
ast.parse((ROOT / "relay" / "site.py").read_text(encoding="utf-8"))
|
||
print(" site.py 语法 OK")
|
||
except SyntaxError as exc:
|
||
print(" [失败] site.py 语法错误: 行 %s: %s" % (exc.lineno, exc.msg))
|
||
return 1
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|