feat: 经文数据外置 sutras/*.json,加减经不改代码
- 7部经文迁移至 sutras/ 目录,/api/sutras 实时扫描返回清单 - 前端改为按需懒加载经文 JSON(selectToken 防快速切换乱序) - add_sutra.sh:校验+上传/删除 一键管理,免重启 - 修正生僻异体字(𫗪→喂、𫄨→絺、𦈎→繟、鬪→斗) - run.md 同步新架构与经文管理文档 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
CACHE_DIR = BASE_DIR / "cache"
|
||||
SUTRA_DIR = BASE_DIR / "sutras"
|
||||
ENV_PATH = BASE_DIR / ".env"
|
||||
|
||||
|
||||
@@ -71,6 +72,27 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, directory=str(BASE_DIR), **kwargs)
|
||||
|
||||
def do_GET(self) -> None:
|
||||
"""处理 GET 请求:/api/sutras 返回经典目录清单,其余按静态文件处理。"""
|
||||
if self.path == "/api/sutras":
|
||||
try:
|
||||
items = []
|
||||
if SUTRA_DIR.is_dir():
|
||||
for f in sorted(SUTRA_DIR.glob("*.json")):
|
||||
d = json.loads(f.read_text(encoding="utf-8"))
|
||||
items.append({
|
||||
"id": d.get("id") or f.stem,
|
||||
"name": d.get("name") or f.stem,
|
||||
"cat": d.get("cat") or "其他",
|
||||
"order": d.get("order", 99),
|
||||
})
|
||||
items.sort(key=lambda x: (x["order"], x["id"]))
|
||||
self._send_json({"sutras": items})
|
||||
except Exception as exc: # noqa: BLE001
|
||||
self._send_json({"error": f"读取经典目录失败:{exc}"}, status=500)
|
||||
return
|
||||
super().do_GET()
|
||||
|
||||
def do_POST(self) -> None:
|
||||
"""处理 POST 请求,目前仅支持 /api/tts。"""
|
||||
if self.path != "/api/tts":
|
||||
|
||||
Reference in New Issue
Block a user