26 lines
861 B
TypeScript
26 lines
861 B
TypeScript
import { listGenerationJobs } from "@/lib/server/data-store";
|
|
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
|
|
import { requestOrigin } from "@/lib/server/runtime";
|
|
import { submitVideoJob, type SubmitVideoJobInput } from "@/lib/server/video-generation-service";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const jobs = (await listGenerationJobs()).filter((job) => job.capability === "video.generate");
|
|
return jsonOk({ jobs });
|
|
} catch (error) {
|
|
return jsonError(error, 500);
|
|
}
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await readJsonBody<SubmitVideoJobInput & Record<string, unknown>>(request);
|
|
const job = await submitVideoJob(body, requestOrigin(request));
|
|
return jsonOk({ job }, { status: 202 });
|
|
} catch (error) {
|
|
return jsonError(error);
|
|
}
|
|
}
|