Spaces:
Running
Running
File size: 1,530 Bytes
58b1ffb 350665d 58b1ffb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import { NextResponse, NextRequest } from "next/server"
import queryString from "query-string"
import { ClapMediaOrientation, getValidNumber } from "@aitube/clap"
import { throwIfInvalidToken } from "@/app/api/v1/auth/throwIfInvalidToken"
import { getContentType } from "@/lib/data/getContentType"
import { render } from "."
export async function POST(req: NextRequest, res: NextResponse) {
await throwIfInvalidToken(req.headers.get("Authorization"))
const request = await req.json() as {
prompt: string
width: number
height: number
turbo: boolean
// can add more stuff for the V2 of Stories Factory
}
console.log("[api/v1/render] request:", request)
const qs = queryString.parseUrl(req.url || "")
const query = (qs || {}).query
const turbo = !!query?.turbo
const prompt = `${request?.prompt || ""}`.trim()
const width = getValidNumber(request?.width, 256, 8192, 1024)
const height = getValidNumber(request?.height, 256, 8192, 576)
const nbFrames = 80
const nbFPS = 24
const nbSteps = turbo ? 4 : 8
const debug = false
const assetUrl = await render({
prompt,
width,
height,
nbFrames,
nbFPS,
nbSteps,
debug,
})
const contentType = getContentType(assetUrl)
const base64String = assetUrl.split(";base64,").pop() || ""
const data = Buffer.from(base64String, "base64")
const headers = new Headers()
headers.set('Content-Type', contentType)
return new NextResponse(data, {
status: 200,
statusText: "OK",
headers
})
} |