File size: 1,451 Bytes
5c0175e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // 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 });
}
}
|