feat: 增加视频清单搜索,并在开发期缓存剧目清单

This commit is contained in:
Nixevol
2026-09-27 04:21:00 +08:00
parent cc930cd1ed
commit f010426f94
7 changed files with 268 additions and 21 deletions
+41
View File
@@ -0,0 +1,41 @@
"""开发期剧目清单缓存。
只缓存分类和剧目清单,不缓存封面。封面仍由 cache/covers 负责。
手动刷新会删掉这份缓存并重新请求。
正式打包时 Tauri 会把 RAPTD_CATALOG_CACHE 设为 0,从而关闭这里。
"""
import json
import os
from pathlib import Path
PATH = Path(__file__).resolve().parents[2] / "cache" / "catalog.json"
def enabled() -> bool:
flag = os.environ.get("RAPTD_CATALOG_CACHE", "1").strip().lower()
return flag not in ("0", "false", "no")
def read() -> list[dict] | None:
if not PATH.is_file():
return None
try:
data = json.loads(PATH.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return None
events = data.get("events") if isinstance(data, dict) else None
if not isinstance(events, list) or not events:
return None
return events
def write(events: list[dict]) -> None:
PATH.parent.mkdir(parents=True, exist_ok=True)
temporary = PATH.with_suffix(".json.tmp")
temporary.write_text(json.dumps({"events": events}, ensure_ascii=False), encoding="utf-8")
temporary.replace(PATH)
def clear() -> None:
PATH.unlink(missing_ok=True)