import { NextResponse } from "next/server"; import { keptFailedEncodesAction } from "../../../saved-videos/compactActions"; import { ops, reqSlug, reqVideoId, type OpsBody, OpsInputError } from "../_lib"; export const dynamic = "force-dynamic"; // POST {} | { clear: { slug, id } } // -> { ok, rows: [{ slug, id, dir, at, reason, failedChunks, kept }], bytes, cleared? } // // The encodes kept after a compaction FAILED A CHECK // (controller/compactSavedVideos.ts): each video's `.compact-scratch` holds // the chunks and the joined copy (`failed-copy.*`, never the active copy) and // a failed.json saying what failed. `compact-saved-videos` with // `"reverify": true` checks one again without encoding; `clear` removes one // video's (refused while its compaction runs). function optClear(body: OpsBody): { slug: string; id: string } | undefined { if (body.clear === undefined) return undefined; if (!body.clear || typeof body.clear !== "object" || Array.isArray(body.clear)) { throw new OpsInputError('"clear" must be { "slug", "id" }'); } const c = body.clear as OpsBody; return { slug: reqSlug(c, "slug"), id: reqVideoId(c, "id") }; } export async function POST(request: Request) { return ops(request, ["clear"], async (body) => { const clear = optClear(body); const res = await keptFailedEncodesAction(clear ? { clear } : {}); return NextResponse.json({ ok: true, ...res }); }); }