Keep Douyin homeVariant BMI router intact while restoring admin join-group controls, TLS-safe config fetch, and ntfy channel labels. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
"""公开远程配置 — 供抖音真机拉配置(合法域名 + 有效证书)。
|
||
|
||
门户 nomadro.cn 证书与主机名不匹配,真机会 TLS 失败;
|
||
开发者工具不校验证书所以看起来正常。
|
||
走 dyapi.nomadro.cn / api.nomadro.cn(已在 request 合法域名且证书 OK)。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
from typing import Any
|
||
|
||
from fastapi import APIRouter
|
||
from fastapi.responses import JSONResponse
|
||
|
||
from ebook_svc.services.tt_platform_config import resolve_config_file
|
||
|
||
router = APIRouter(tags=["public-config"])
|
||
|
||
|
||
def _read_full_config() -> dict[str, Any]:
|
||
path = resolve_config_file()
|
||
if not path.is_file():
|
||
return {
|
||
"version": 1,
|
||
"updatedAt": "",
|
||
"modules": {},
|
||
"flags": {},
|
||
"copy": {},
|
||
"platforms": {},
|
||
}
|
||
try:
|
||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||
return raw if isinstance(raw, dict) else {}
|
||
except Exception:
|
||
return {
|
||
"version": 1,
|
||
"updatedAt": "",
|
||
"modules": {},
|
||
"flags": {},
|
||
"copy": {},
|
||
"platforms": {},
|
||
}
|
||
|
||
|
||
@router.get("/api/config")
|
||
@router.get("/api/ebook/config")
|
||
async def public_remote_config() -> JSONResponse:
|
||
"""对齐门户 GET /api/config:{ ok, source, config }。"""
|
||
config = _read_full_config()
|
||
return JSONResponse(
|
||
content={"ok": True, "source": "file", "config": config},
|
||
headers={
|
||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||
"Access-Control-Allow-Origin": "*",
|
||
},
|
||
)
|
||
|
||
|
||
@router.get("/api/config/meta")
|
||
@router.get("/api/ebook/config/meta")
|
||
async def public_remote_config_meta() -> JSONResponse:
|
||
config = _read_full_config()
|
||
return JSONResponse(
|
||
content={
|
||
"ok": True,
|
||
"version": int(config.get("version") or 0),
|
||
"updatedAt": str(config.get("updatedAt") or ""),
|
||
},
|
||
headers={
|
||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||
"Access-Control-Allow-Origin": "*",
|
||
},
|
||
)
|