import { NextResponse } from "next/server"; import { authorizeWorkerRequest } from "yt-dlp-transcript-common/lib/workerToken"; import { cancelWorkerJob, cleanupWorkerJob, } from "yt-dlp-transcript-common/controller/workerServer"; export const dynamic = "force-dynamic"; const ID_RE = /^[A-Za-z0-9_-]+$/; // Cancel (if running) and clean up the job's scratch dir. Called when the // requester has the result or aborted. Idempotent. export async function DELETE( 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 }); } cancelWorkerJob(id); await cleanupWorkerJob(id); return NextResponse.json({ ok: true }); }