import { NextResponse } from "next/server"; import { ArchiveOrgRequestError } from "yt-dlp-transcript-common/lib/archiveOrgClient"; import { describeArchiveOrgItem } from "yt-dlp-transcript-common/controller/archiveOrgImport"; import { OpsInputError, ops, opsFail, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { item } -> { ok: true, item: { identifier, url, title?, date?, // mediatype?, creator?, collections, restricted, mediaFiles, mediaBytes, // files: [{ name, format?, source?, size?, seconds?, media, restricted, // original? }] } } // // One archive.org item's file list, read off its metadata // (archive.org/metadata/) — one request through the editor's polite // archive.org client, cached as an import's is — with each file's size, // format and length, which are the media originals an import takes (one // record each), and what archive.org restricts. Nothing is downloaded. const IDENTIFIER = /^[A-Za-z0-9._-]{1,100}$/; export async function POST(request: Request) { return ops(request, ["item"], async (body) => { const id = reqString(body, "item"); if (!IDENTIFIER.test(id)) throw new OpsInputError(`"${id}" is not an archive.org identifier`); try { return NextResponse.json({ ok: true, item: await describeArchiveOrgItem(id) }); } catch (e) { if (e instanceof ArchiveOrgRequestError) return opsFail(e.message, e.status === 404 ? 404 : 502); throw e; } }); }