-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathvalidation.ts
More file actions
80 lines (70 loc) · 1.82 KB
/
Copy pathvalidation.ts
File metadata and controls
80 lines (70 loc) · 1.82 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { VideoModelOption } from '@/lib/types';
export type { GenerateVideoRequest } from '@/lib/types';
export interface ValidationResult {
isValid: boolean;
error?: { message: string; status: number };
}
export function validateGenerateVideoRequest(body: unknown): ValidationResult {
if (!body || typeof body !== 'object') {
return {
isValid: false,
error: { message: 'Invalid request body', status: 400 },
};
}
const { prompt, model, durationSeconds, generateAudio } = body as Record<
string,
unknown
>;
if (!prompt || typeof prompt !== 'string') {
return {
isValid: false,
error: { message: 'Prompt is required', status: 400 },
};
}
if (prompt.length < 3 || prompt.length > 1000) {
return {
isValid: false,
error: { message: 'Prompt must be 3-1000 characters', status: 400 },
};
}
const validModels: VideoModelOption[] = [
'veo-3.1-fast-generate-preview',
'veo-3.1-generate-preview',
'veo-3.0-fast-generate-preview',
'veo-3.0-generate-preview',
];
if (!model || !validModels.includes(model as VideoModelOption)) {
return {
isValid: false,
error: {
message: `Model must be: ${validModels.join(', ')}`,
status: 400,
},
};
}
if (durationSeconds !== undefined) {
if (
typeof durationSeconds !== 'number' ||
durationSeconds < 1 ||
durationSeconds > 60
) {
return {
isValid: false,
error: {
message: 'Duration must be between 1 and 60 seconds',
status: 400,
},
};
}
}
if (generateAudio !== undefined && typeof generateAudio !== 'boolean') {
return {
isValid: false,
error: {
message: 'generateAudio must be a boolean',
status: 400,
},
};
}
return { isValid: true };
}