允许后端任务

This commit is contained in:
2026-06-17 17:58:00 +08:00
parent eac6ad2343
commit b9af979582
6 changed files with 1874 additions and 304 deletions
+55
View File
@@ -0,0 +1,55 @@
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
import { type NextRequest, NextResponse } from "next/server";
import {
AsrBatchJobError,
controlAsrBatchJob,
getAsrBatchJob,
} from "@/lib/asr-batch-jobs";
type RouteContext = {
params: Promise<{ jobId: string }>;
};
export async function GET(_req: NextRequest, { params }: RouteContext) {
const { jobId } = await params;
const job = getAsrBatchJob(jobId, true);
if (!job) {
return NextResponse.json({ error: "任务不存在" }, { status: 404 });
}
return NextResponse.json({ job });
}
export async function PATCH(req: NextRequest, { params }: RouteContext) {
const { jobId } = await params;
let body: unknown;
try {
body = await req.json();
} catch {
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
}
const action =
body && typeof body === "object" && "action" in body
? (body as { action?: unknown }).action
: undefined;
try {
const job = controlAsrBatchJob(jobId, action);
return NextResponse.json({ job });
} catch (error) {
if (error instanceof AsrBatchJobError) {
return NextResponse.json(
{ error: error.message },
{ status: error.status },
);
}
console.error("Failed to control ASR batch job:", error);
return NextResponse.json(
{ error: "Failed to control ASR batch job" },
{ status: 500 },
);
}
}