features: auto-next w/ 5s countdown, prev/next, playback speed, hide fillers, recent searches
This commit is contained in:
1 parent
9fdf3944fc
commit
98fb4e5461
6 files changed
+269
-25
No files matched your search
@@ -175,6 +175,40 @@ def api_history_post(entry: dict = Body(...), request: Request = None):
|
||||
return entry
|
||||
|
||||
|
||||
SEARCH_DIR = Path(os.environ.get("ANIWEB_DATA", Path(__file__).parent / "data")) / "searches"
|
||||
|
||||
|
||||
def _load_searches(user: str):
|
||||
try:
|
||||
return json.loads((SEARCH_DIR / f"{user}.json").read_text())
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return []
|
||||
|
||||
|
||||
def _save_searches(user: str, items):
|
||||
SEARCH_DIR.mkdir(exist_ok=True)
|
||||
(SEARCH_DIR / f"{user}.json").write_text(json.dumps(items, indent=1))
|
||||
|
||||
|
||||
@app.get("/api/searches")
|
||||
def api_searches(request: Request):
|
||||
return JSONResponse(_load_searches(request.state.user),
|
||||
headers={"Cache-Control": "no-store"})
|
||||
|
||||
|
||||
@app.post("/api/searches")
|
||||
def api_searches_post(item: dict = Body(...), request: Request = None):
|
||||
q = str(item.get("q", "")).strip()[:60]
|
||||
if not q:
|
||||
raise HTTPException(422, "q required")
|
||||
u = request.state.user
|
||||
# dedupe case-insensitively, newest first, cap 8
|
||||
items = [x for x in _load_searches(u) if x.lower() != q.lower()]
|
||||
items.insert(0, q)
|
||||
_save_searches(u, items[:8])
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
def _b64(url: str) -> str:
|
||||
return base64.urlsafe_b64encode(url.encode()).decode()
|
||||
|
||||
|
||||
Reference in new issue
Block a user