import { NextResponse } from "next/server"; import { authorizeWorkerRequest } from "yt-dlp-transcript-common/lib/workerToken"; import { readWorkerUnitResult } from "yt-dlp-transcript-common/controller/workerServer"; export const dynamic = "force-dynamic"; const ID_RE = /^[A-Za-z0-9_-]+$/; // The unit's outcome plus its kind's declared output files (UTF-8 JSON text by // name), once the run is done. 404 until then. The requester applies these on // its side through the kind's guarded writers — never as a raw copy. export async function GET( request: Request, { params }: { params: Promise<{ id: string }> }, ) { const auth = authorizeWorkerRequest(request.headers.get("authorization")); if (!auth.ok) { return NextResponse.json({ error: auth.error }, { status: auth.status }); } const { id } = await params; if (!ID_RE.test(id)) { return NextResponse.json({ error: "invalid id" }, { status: 400 }); } const result = await readWorkerUnitResult(id); if (!result) { return NextResponse.json({ error: "no result yet" }, { status: 404 }); } return NextResponse.json(result, { headers: { "Cache-Control": "no-store" }, }); }