import { NextResponse } from "next/server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { configureLocalMedia } from "yt-dlp-transcript-common/controller/configureLocalMedia"; import { ops, reqSlug, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, sourceId, directory } -> { ok: true, localMedia } // // A LOCAL MEDIA LIBRARY for a video channel (controller/configureLocalMedia.ts; // the Local media page's Save library): `localMedia` = {sourceId, directory} // written through patchChannelConfig, the channel config lock and the schema. // Initial opt-in only — a channel that already has a library is refused (the // same names could identify different recordings), as are a social channel, // queued or running channel work, a relocation, a directory that does not // exist or overlaps the channel. Playback is never set here. Nothing is // scanned or imported. Synchronous; no job. export async function POST(request: Request) { return ops(request, ["slug", "sourceId", "directory"], async (body) => { const localMedia = await configureLocalMedia(getPaths(), reqSlug(body, "slug"), { sourceId: reqString(body, "sourceId"), directory: reqString(body, "directory"), }); return NextResponse.json({ ok: true, localMedia }); }); }