Files
douyin-archive/app/api/admin/asr/jobs/route.ts
T
2026-06-17 17:58:00 +08:00

46 lines
1.1 KiB
TypeScript

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
import { type NextRequest, NextResponse } from "next/server";
import {
AsrBatchJobError,
createAsrBatchJob,
getActiveAsrBatchJob,
listAsrBatchJobs,
} from "@/lib/asr-batch-jobs";
export async function GET() {
return NextResponse.json({
jobs: listAsrBatchJobs(),
activeJob: getActiveAsrBatchJob(),
});
}
export async function POST(req: NextRequest) {
let body: unknown;
try {
body = await req.json();
} catch {
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
}
try {
const job = await createAsrBatchJob(
body && typeof body === "object" ? body : {},
);
return NextResponse.json({ job }, { status: 201 });
} catch (error) {
if (error instanceof AsrBatchJobError) {
return NextResponse.json(
{ error: error.message },
{ status: error.status },
);
}
console.error("Failed to create ASR batch job:", error);
return NextResponse.json(
{ error: "Failed to create ASR batch job" },
{ status: 500 },
);
}
}