(request: Request, env: Env)
| 209 | } |
| 210 | |
| 211 | async function handleVideoGenerations(request: Request, env: Env): Promise<Response> { |
| 212 | const refreshToken = await authenticate(request, env); |
| 213 | const body = (await request.json()) as any; |
| 214 | |
| 215 | if (!isString(body.prompt)) throw new Error("prompt must be a string"); |
| 216 | const { |
| 217 | model, |
| 218 | conversation_id: convId, |
| 219 | prompt, |
| 220 | image_url: imageUrl, |
| 221 | video_style: videoStyle = "", |
| 222 | emotional_atmosphere: emotionalAtmosphere = "", |
| 223 | mirror_mode: mirrorMode = "", |
| 224 | audio_id: audioId, |
| 225 | } = body; |
| 226 | |
| 227 | const validStyles = ["卡通3D", "黑白老照片", "油画", "电影感"]; |
| 228 | const validEmotions = ["温馨和谐", "生动活泼", "紧张刺激", "凄凉寂寞"]; |
| 229 | const validMirrors = ["水平", "垂直", "推近", "拉远"]; |
| 230 | if (videoStyle && !validStyles.includes(videoStyle)) throw new Error(`video_style must be one of ${validStyles.join("/")}`); |
| 231 | if (emotionalAtmosphere && !validEmotions.includes(emotionalAtmosphere)) throw new Error(`emotional_atmosphere must be one of ${validEmotions.join("/")}`); |
| 232 | if (mirrorMode && !validMirrors.includes(mirrorMode)) throw new Error(`mirror_mode must be one of ${validMirrors.join("/")}`); |
| 233 | |
| 234 | const data = await generateVideos(model, prompt, refreshToken, { |
| 235 | imageUrl: imageUrl || "", |
| 236 | videoStyle, |
| 237 | emotionalAtmosphere, |
| 238 | mirrorMode, |
| 239 | audioId: audioId || "", |
| 240 | }, convId); |
| 241 | return jsonResponse({ created: unixTimestamp(), data }); |
| 242 | } |
| 243 | |
| 244 | async function handleModels(): Promise<Response> { |
| 245 | return jsonResponse({ data: SUPPORTED_MODELS }); |
no test coverage detected