Initial 智念AIGC platform
This commit is contained in:
28
app/api/assets/[id]/upscale/route.ts
Normal file
28
app/api/assets/[id]/upscale/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { getAsset } from "@/lib/server/data-store";
|
||||
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
|
||||
import { requestOrigin } from "@/lib/server/runtime";
|
||||
import { submitImageJob } from "@/lib/server/generation-service";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const { id } = await context.params;
|
||||
const asset = await getAsset(id);
|
||||
if (!asset) return jsonError(new Error("Asset not found."), 404);
|
||||
const body = await readJsonBody<{
|
||||
resolution?: "4k" | "8k";
|
||||
scale?: number;
|
||||
}>(request);
|
||||
const job = await submitImageJob({
|
||||
capability: "image.upscale",
|
||||
imageUrls: [asset.url],
|
||||
inputAssetIds: [asset.id],
|
||||
resolution: body.resolution === "8k" ? "8k" : "4k",
|
||||
scale: typeof body.scale === "number" ? body.scale : undefined
|
||||
}, requestOrigin(request));
|
||||
return jsonOk({ job }, { status: 202 });
|
||||
} catch (error) {
|
||||
return jsonError(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user