|
"use server" |
|
|
|
|
|
import { Ratelimit } from "@upstash/ratelimit" |
|
import { Redis } from "@upstash/redis" |
|
import { ClapProject, ClapImageRatio } from "@aitube/clap" |
|
import { createClap as apiCreateClap } from "@aitube/client" |
|
|
|
import { getToken } from "./getToken" |
|
import { RESOLUTION_LONG, RESOLUTION_SHORT, MAX_PROMPT_LENGTH_IN_CHARS } from "../config" |
|
import { getRateLimit } from "../redis/getRateLimit" |
|
|
|
const rateLimit = getRateLimit() |
|
|
|
export async function createClap({ |
|
prompt = "", |
|
imageRatio = ClapImageRatio.PORTRAIT, |
|
turbo = false, |
|
}: { |
|
prompt: string |
|
imageRatio?: ClapImageRatio |
|
turbo?: boolean |
|
}): Promise<ClapProject> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clap: ClapProject = await apiCreateClap({ |
|
prompt: prompt.slice(0, MAX_PROMPT_LENGTH_IN_CHARS), |
|
|
|
height: imageRatio === ClapImageRatio.PORTRAIT ? RESOLUTION_LONG : RESOLUTION_SHORT, |
|
width: imageRatio === ClapImageRatio.PORTRAIT ? RESOLUTION_SHORT : RESOLUTION_LONG, |
|
|
|
turbo, |
|
|
|
token: await getToken() |
|
}) |
|
|
|
return clap |
|
} |
|
|