- Track MiroSociety source: backend (FastAPI), frontend (Vue3/Vite), docs, configs. - Add start.sh / deploy.sh for local dev (uv venv + npm + dev servers on 31400/31401). - Fix pyproject.toml: missing httpx dependency. - Tighten .gitignore: .env, .venv, node_modules, data/, *.log, uv.lock, frontend/dist, etcd. Co-Authored-By: Claude <noreply@anthropic.com>
28 lines
990 B
Python
28 lines
990 B
Python
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
|