This commit is contained in:
2026-09-27 00:41:00 +08:00
parent e87cb869ba
commit 2d4f9230b1
119 changed files with 28773 additions and 28616 deletions
+27 -27
View File
@@ -1,27 +1,27 @@
from __future__ import annotations
from fastapi import APIRouter, Request, HTTPException
router = APIRouter(prefix="/api")
@router.get("/gallery")
async def list_gallery(request: Request, sort: str = "recent"):
sims = await request.app.state.store.list_simulations(public_only=True, sort=sort)
return {"simulations": sims}
@router.get("/gallery/{sim_id}")
async def get_gallery_item(sim_id: str, request: Request):
store = request.app.state.store
sim = await store.get_simulation(sim_id)
if not sim or not sim.get("is_public"):
raise HTTPException(404, "Simulation not found in gallery")
await store.increment_view_count(sim_id)
cached = await store.get_report(sim_id)
if cached and cached.get("status") == "ready":
return cached["report"]
narrator = request.app.state.narrator
report = await narrator.generate_report(sim_id, store)
if "error" not in report:
await store.save_report(sim_id, report)
return report
from __future__ import annotations
from fastapi import APIRouter, Request, HTTPException
router = APIRouter(prefix="/api")
@router.get("/gallery")
async def list_gallery(request: Request, sort: str = "recent"):
sims = await request.app.state.store.list_simulations(public_only=True, sort=sort)
return {"simulations": sims}
@router.get("/gallery/{sim_id}")
async def get_gallery_item(sim_id: str, request: Request):
store = request.app.state.store
sim = await store.get_simulation(sim_id)
if not sim or not sim.get("is_public"):
raise HTTPException(404, "Simulation not found in gallery")
await store.increment_view_count(sim_id)
cached = await store.get_report(sim_id)
if cached and cached.get("status") == "ready":
return cached["report"]
narrator = request.app.state.narrator
report = await narrator.generate_report(sim_id, store)
if "error" not in report:
await store.save_report(sim_id, report)
return report