import { NextResponse } from "next/server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { adoptLocalMediaReference } from "yt-dlp-transcript-common/controller/adoptLocalMediaReference"; import { ops, optBool, reqSlug, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, sourceToken, media, fingerprint, dryRun? } // -> { ok: true, status: "attached" | "already-linked" | "conflict" | "ready" } // // VERIFY AND LINK one record the channel already holds to its local original // (controller/adoptLocalMediaReference.ts; the Local media page's Verify and // link): for a preview candidate that is "existing", the library's // .info.json and transcript are compared BYTE FOR BYTE with the record's // metadata.info.json and transcript.en.vtt (an .srt converted first), and // only on a match is external-media.json written beside them — never over one // already there ("conflict" keeps it). Nothing else in the record changes; // linking grants no playback. `dryRun` verifies and answers "ready" (or // "already-linked" / "conflict") without writing. Refused while the channel has // queued or running work. Synchronous; no job. export async function POST(request: Request) { return ops(request, ["slug", "sourceToken", "media", "fingerprint", "dryRun"], async (body) => { const result = await adoptLocalMediaReference(getPaths(), reqSlug(body, "slug"), { sourceToken: reqString(body, "sourceToken"), media: reqString(body, "media"), fingerprint: reqString(body, "fingerprint"), }, { apply: optBool(body, "dryRun") !== true }); return NextResponse.json({ ok: true, ...result }); }); }