import { NextResponse } from "next/server"; import { dropSavedAlternateAction } from "../../../channels/[slug]/videos/[id]/videoActions"; import { ops, opsFail, optBool, reqSlug, reqString, reqVideoId } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, id, file, dryRun?, confirmOriginal?, confirmFormerOriginal? } // -> { ok, dryRun, file, path, existed, bytes, remaining, alternate } // // Drop ONE saved alternate of one video — a copy kept beside a newer download // (ytdlp/savedAlternates.ts), listed by `get saved-alternates` — after it has // been checked. The video page's "Drop this alternate" button. It is // dropSavedAlternate (lib/savedVideo-server.ts): refused unless `file` is a // bare name the pointer lists as an alternate (never the active copy, never a // path), and while the saved-video store is being moved. The file is deleted // from the store and its entry from the pointer; everything else in the pointer // is left as it was. A file already gone but still listed is cleaned from the // pointer (`existed: false`). "dryRun": true answers the same and changes // nothing. No undo. // // AN ORIGINAL (`keptAs: "original"`, the source a compacted copy was made // from) is refused unless "confirmOriginal": true; before the drop the // compacted copy is read back from disk and must match its recorded sha256; // and a video not known to be on its platform needs its review recorded first // (review-compacted-original). `get compaction-review` lists each one's state. // A FORMER original (`keptAs: "former-original"`) needs its own // "confirmFormerOriginal": true — a person's word, never an automatic step's. export async function POST(request: Request) { return ops(request, ["slug", "id", "file", "dryRun", "confirmOriginal", "confirmFormerOriginal"], async (body) => { const res = await dropSavedAlternateAction( reqSlug(body, "slug"), reqVideoId(body, "id"), reqString(body, "file"), { dryRun: optBool(body, "dryRun") ?? false, confirmOriginal: optBool(body, "confirmOriginal") ?? false, confirmFormerOriginal: optBool(body, "confirmFormerOriginal") ?? false, }, ); if (!res.ok) return opsFail(res.error); const r = res.result; return NextResponse.json({ ok: true, dryRun: r.dryRun, file: r.alternate.file, path: r.path, existed: r.existed, bytes: r.bytes, remaining: r.remaining, alternate: r.alternate, }); }); }