62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { ChatSDKError } from "@/lib/errors";
|
|
import { requireAdmin } from "@/lib/middleware/admin";
|
|
import { listVideoStoryboardTasks } from "@/lib/video-agent/task-store";
|
|
|
|
const querySchema = z.object({
|
|
page: z.coerce.number().int().min(1).default(1),
|
|
pageSize: z.coerce.number().int().min(1).max(200).default(20),
|
|
status: z.string().trim().optional(),
|
|
providerType: z.string().trim().optional(),
|
|
chatId: z.string().uuid().optional(),
|
|
userId: z.string().uuid().optional(),
|
|
});
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
await requireAdmin();
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const parsed = querySchema.parse({
|
|
page: searchParams.get("page") || "1",
|
|
pageSize: searchParams.get("pageSize") || "20",
|
|
status: searchParams.get("status") || undefined,
|
|
providerType: searchParams.get("providerType") || undefined,
|
|
chatId: searchParams.get("chatId") || undefined,
|
|
userId: searchParams.get("userId") || undefined,
|
|
});
|
|
|
|
const result = await listVideoStoryboardTasks({
|
|
page: parsed.page,
|
|
pageSize: parsed.pageSize,
|
|
status: parsed.status,
|
|
providerType: parsed.providerType,
|
|
chatId: parsed.chatId,
|
|
userId: parsed.userId,
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
...result,
|
|
});
|
|
} catch (error) {
|
|
if (error instanceof ChatSDKError) {
|
|
return error.toResponse();
|
|
}
|
|
if (error instanceof z.ZodError) {
|
|
return NextResponse.json(
|
|
{ success: false, error: error.message },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : "查询任务失败",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|