feat: channel/category dropdown with API filter; AI auto-categories embedded

This commit is contained in:
Gan, Jimmy
2026-06-24 18:20:12 +08:00
parent 63d42594d0
commit 94ef5e2bb2
4 changed files with 131 additions and 12 deletions
+22 -2
View File
@@ -37,6 +37,21 @@ async def startup():
async def health():
return {"status": "ok"}
@app.get("/auto_categories.json")
async def auto_categories():
import json, os
path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "frontend", "src", "auto_categories.json")
if os.path.exists(path):
with open(path) as f:
return json.load(f)
return {}
@app.get("/api/channels")
async def get_channels(db: aiosqlite.Connection = Depends(get_db)):
cursor = await db.execute("SELECT DISTINCT channel_name, channel_id FROM videos ORDER BY channel_name")
rows = await cursor.fetchall()
return [dict(row) for row in rows]
@app.get("/")
async def root():
from fastapi.responses import FileResponse
@@ -46,10 +61,15 @@ async def root():
async def get_videos(
status: Optional[str] = "pending",
limit: int = 50,
channel: Optional[str] = None,
db: aiosqlite.Connection = Depends(get_db)
):
query = "SELECT * FROM videos WHERE status = ? ORDER BY publish_date DESC, created_at DESC LIMIT ?"
cursor = await db.execute(query, (status, limit))
if channel:
query = "SELECT * FROM videos WHERE status = ? AND channel_name = ? ORDER BY publish_date DESC, created_at DESC LIMIT ?"
cursor = await db.execute(query, (status, channel, limit))
else:
query = "SELECT * FROM videos WHERE status = ? ORDER BY publish_date DESC, created_at DESC LIMIT ?"
cursor = await db.execute(query, (status, limit))
rows = await cursor.fetchall()
return [dict(row) for row in rows]