// POST /api/offcloud/rescan — force re-analysis of the Offcloud library. // // Normal syncing never touches content that is already ready to play, which is // what you want day to day. Use this endpoint only after changing detection // rules, when every Offcloud video genuinely has to go through the pipeline // again. TeraBox and Blomp libraries are left alone. import { NextResponse } from "next/server"; import { db } from "@/lib/db"; import { syncOnce } from "@/lib/sync-engine"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; export async function POST() { try { // Reset only Offcloud content that still exists upstream. const targets = await db.video.findMany({ where: { source: "offcloud", availability: "available", status: "ready", }, select: { id: true }, }); if (targets.length > 0) { const ids = targets.map((v) => v.id); await db.video.updateMany({ where: { id: { in: ids } }, data: { status: "pending", lastScannedAt: null }, }); await db.queueItem.deleteMany({ where: { videoId: { in: ids } } }); } const result = await syncOnce({ mode: "full", trigger: "force", force: true }); return NextResponse.json({ ok: !result.error, message: `Force re-scan started — ${targets.length} reset, ${result.requeued} queued`, resetCount: targets.length, queuedCount: result.requeued, error: result.error, }); } catch (err) { const msg = err instanceof Error ? err.message : "Unknown error"; return NextResponse.json({ error: msg }, { status: 500 }); } }