import { NextResponse } from "next/server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { previewLocalMedia } from "yt-dlp-transcript-common/controller/localMediaImport"; import { ops, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug } -> { ok: true, preview: { sourceToken, counts, candidates } } // // The channel's local media library SCANNED, writing nothing // (controller/localMediaImport.ts previewLocalMedia; the Local media page's // Preview library): every .mp4 directly in `localMedia.directory` (not its // subdirectories) with its same-named .info.json and .vtt/.srt, each a // candidate "new", "existing" (its record's directory is occupied) or "issue" // (with `issues`). A candidate's `fingerprint` (import, link) or // `preparationFingerprint` (prepare, for one with no .info.json) and the // preview's `sourceToken` are what the other local-media actions take; a // changed file or config makes them stale. An unreachable library is an // error, never an empty preview. Synchronous; no job. export async function POST(request: Request) { return ops(request, ["slug"], async (body) => { const preview = await previewLocalMedia(getPaths(), reqSlug(body, "slug")); return NextResponse.json({ ok: true, preview }); }); }