from fastapi import APIRouter from fastapi.responses import JSONResponse from ..sync.engine import get_progress, run_sync_cycle router = APIRouter(prefix="/api/sync", tags=["sync"]) @router.post("") async def trigger_sync(replica_id: int | None = None): started = await run_sync_cycle( triggered_by="manual", replica_id=replica_id, ) return JSONResponse( status_code=202, content={"started": started, "message": "Sync triggered" if started else "Already running"}, ) @router.get("/running") def sync_running(): p = get_progress() return { "running": p.running, "phase": p.phase, "docs_done": p.docs_done, "docs_total": p.docs_total, }