mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 23:00:44 +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
105 lines
3.4 KiB
Python
105 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
r'''把官网 logo 从 <img src=/favicon.ico> 换成内联 SVG。
|
||
|
||
为什么:
|
||
ICO 文件放在 <img> 标签里各浏览器支持不一致 ——
|
||
实测截图里导航栏那个 logo 是**破图**。
|
||
内联 SVG 永远能显示,还省一个请求。
|
||
'''
|
||
from __future__ import annotations
|
||
|
||
import ast
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
||
LANDING = ROOT / "relay" / "landing.py"
|
||
|
||
# 内联 SVG(用设计令牌里的主色)
|
||
LOGO_FUNC = '''def _logo(size: int = 26) -> str:
|
||
"""内联 SVG 的 logo。
|
||
|
||
为什么不用 <img src="/favicon.ico">:
|
||
ICO 放在 <img> 里各浏览器支持不一致,实测截图里是破图。
|
||
内联 SVG 永远能显示,还不用多一个请求。
|
||
"""
|
||
return (
|
||
'<svg width="%d" height="%d" viewBox="0 0 32 32" fill="none" '
|
||
'aria-hidden="true">'
|
||
'<rect x="3" y="3" width="26" height="26" rx="8" fill="' + ACCENT + '"/>'
|
||
'<rect x="10" y="9" width="12" height="14" rx="4" '
|
||
'stroke="#fff" stroke-width="2"/>'
|
||
'<path d="M13 9V6h6v3M13 23v3h6v-3" stroke="#fff" '
|
||
'stroke-width="2" stroke-linecap="round"/>'
|
||
'</svg>' % (size, size)
|
||
)
|
||
|
||
|
||
'''
|
||
|
||
OLD_IMG = '<img src="/favicon.ico" alt="">'
|
||
|
||
|
||
def main() -> int:
|
||
text = LANDING.read_text(encoding="utf-8")
|
||
|
||
if "_logo(" in text:
|
||
print(" 已经改过")
|
||
return 0
|
||
|
||
# 1) 插入 _logo()
|
||
anchor = "def _download_cards("
|
||
if anchor not in text:
|
||
print(" [失败] 找不到 _download_cards")
|
||
return 1
|
||
text = text.replace(anchor, LOGO_FUNC + anchor, 1)
|
||
print(" 加了 _logo()")
|
||
|
||
# 2) 模板里的 img 换成占位符
|
||
n = text.count(OLD_IMG)
|
||
text = text.replace(OLD_IMG, "__LOGO__")
|
||
print(" 替换 %d 处 <img> 为占位符" % n)
|
||
|
||
# 3) 返回值里把占位符换成真正的 SVG
|
||
# 模板最后是 } 形状,找一个稳妥的锚点:
|
||
# "_dlsub": (...) 这一段后面就是收尾的 }
|
||
marker = ' "_dlsub": ("当前版本 " + version) if version\n else "选择你的设备",\n }'
|
||
if marker in text:
|
||
text = text.replace(
|
||
marker,
|
||
' "_dlsub": ("当前版本 " + version) if version\n'
|
||
' else "选择你的设备",\n'
|
||
' }.replace("__LOGO__", _logo())', 1)
|
||
print(" 返回值里接了 .replace(\"__LOGO__\", _logo())")
|
||
else:
|
||
# 兜底:找 render_site 的 return ... % { ... } 结尾
|
||
idx = text.rfind(" }")
|
||
if idx < 0:
|
||
print(" [失败] 找不到返回值结尾")
|
||
return 1
|
||
text = text[:idx] + ' }.replace("__LOGO__", _logo())' + text[idx + len(" }"):]
|
||
print(" 用兜底方式接了 replace")
|
||
|
||
LANDING.write_text(text, encoding="utf-8", newline="\n")
|
||
|
||
try:
|
||
ast.parse(text)
|
||
print(" 语法 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) + 3)):
|
||
print(" %d: %s" % (i + 1, lines[i][:90]))
|
||
return 1
|
||
|
||
# 复核
|
||
left = text.count(OLD_IMG)
|
||
print()
|
||
print(" 复核: 还剩 %d 处 <img src=/favicon.ico>(link 那个不影响)" % left)
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|