56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
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 },
|
|
);
|
|
}
|
|
}
|