// POST /api/offcloud/scan — reconcile the library with Offcloud. // // This is now an INCREMENTAL sync: videos that are already indexed and ready to // play are never re-analyzed, only new Offcloud content is queued, and items // deleted from Offcloud are hidden. Add ?force=1 to re-analyze everything. // // The same sync also runs automatically every few seconds and on every boot, so // pressing this is only ever an impatience button. import { NextRequest, NextResponse } from "next/server"; import { syncOnce } from "@/lib/sync-engine"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; export async function POST(req: NextRequest) { try { const force = new URL(req.url).searchParams.get("force") === "1"; const result = await syncOnce({ mode: "full", trigger: force ? "force" : "manual", force, }); return NextResponse.json({ started: !result.error, // Back-compat field for older clients. queuedCount: result.requeued, added: result.added, skippedReady: result.skippedReady, markedMissing: result.markedMissing, pruned: result.pruned, discovered: result.discovered, mode: result.offcloudMode, error: result.error, }); } catch (err) { const msg = err instanceof Error ? err.message : "Unknown error"; return NextResponse.json({ error: msg }, { status: 500 }); } }