feat(gateway): 为52号接口增加客户端静态Token校验

请求头X-API-Token默认yonghe1999,可通过interface52_token覆盖;缺少或不匹配返回401/code1009,不进入派发队列。客户端Token不转发到worker,其他接口保持原样。

同步Token输入框、配置示例与调用文档。57项网关测试及临时网关连接真实worker的浏览器验证通过。
This commit is contained in:
xsl
2026-11-04 11:35:02 +08:00
parent 544c2a83d6
commit 14ec4964a0
10 changed files with 120 additions and 6 deletions
+5
View File
@@ -13,6 +13,7 @@ logger = logging.getLogger("gateway.config")
CONFIG_PATH = Path(__file__).resolve().parent / "config.json"
DEFAULTS = {
"interface52_token": "yonghe1999",
"public_base_url": "https://hair.xiangsilian.com",
"static_dir": "static/annotations",
"primary_workers": [], # 主 worker 地址列表(须为 workers 的子集);空 = 全部视为主 worker
@@ -76,6 +77,10 @@ def load_config() -> dict:
cfg = _deep_merge(DEFAULTS, raw)
# --- 校验 ---
client_token = cfg["interface52_token"]
if not isinstance(client_token, str) or not client_token:
raise ValueError("配置错误: interface52_token 必须是非空字符串")
workers: List[str] = cfg.get("workers", [])
if not workers:
raise ValueError("配置错误: workers 列表不能为空,至少需要一个 worker 地址")