File size: 1,126 Bytes
6215321
f24ad59
6215321
8919651
 
f24ad59
6215321
 
 
 
8919651
6215321
 
ce559ed
 
 
d2f7c95
6215321
 
 
58b1ffb
6215321
f24ad59
8919651
f24ad59
d2f7c95
 
6215321
 
ce559ed
6215321
 
 
 
 
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
import { NextResponse, NextRequest } from "next/server"
import { getValidNumber, serializeClap } from "@aitube/clap"

import { throwIfInvalidToken } from "@/app/api/v1/auth/throwIfInvalidToken"

import { create } from "."

// a helper to generate Clap stories from a few sentences
// this is mostly used by external apps such as the Stories Factory
export async function POST(req: NextRequest) {
  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/create] request:", request)

  const clap = await create({
    prompt: `${request?.prompt || ""}`.trim(),
    width: getValidNumber(request?.width, 256, 8192, 1024),
    height: getValidNumber(request?.height, 256, 8192, 576),
    turbo: request?.turbo ? true : false,
  })

  // TODO replace by Clap file streaming
  return new NextResponse(await serializeClap(clap), {
    status: 200,
    headers: new Headers({ "content-type": "application/x-gzip" }),
  })
}