Admin: analytics date-range toggle (7d / 30d / 90d)
/api/admin/stats accepts ?days= (clamped to 7/30/90, default 30) → passed to
admin_stats, which already windows visitors, retention, funnel, sharing, daily
trend, and the top lists by that span. Frontend adds a Window picker on the
analytics tabs (Overview/Content/Audience); changing it refetches and the
windowed labels ("Visitors (Nd)", "Last N days", "Returning visitors (Nd)")
follow. Corpus totals + source health are unaffected (not time-windowed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -848,10 +848,11 @@ def create_app() -> FastAPI:
|
||||
return {"ok": True, "flag": body.flag}
|
||||
|
||||
@app.get("/api/admin/stats")
|
||||
def admin_stats(request: Request) -> dict:
|
||||
def admin_stats(request: Request, days: int = Query(30)) -> dict:
|
||||
days = days if days in (7, 30, 90) else 30 # clamp to the offered windows
|
||||
with get_conn() as conn:
|
||||
_require_admin(conn, request)
|
||||
return queries.admin_stats(conn)
|
||||
return queries.admin_stats(conn, days=days)
|
||||
|
||||
@app.get("/api/summary/{article_id}")
|
||||
def article_summary(article_id: int, background_tasks: BackgroundTasks) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user