mirror of
https://github.com/imputnet/cobalt.git
synced 2026-11-01 07:14:36 +00:00
api: use zod for request schema validation
This commit is contained in:
parent
b510cbf9e0
commit
f32f624916
7 changed files with 62 additions and 70 deletions
42
api/src/processing/schema.js
Normal file
42
api/src/processing/schema.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { z } from "zod";
|
||||
|
||||
import { normalizeURL } from "./url.js";
|
||||
import { verifyLanguageCode } from "../misc/utils.js";
|
||||
|
||||
export const apiSchema = z.object({
|
||||
url: z.string()
|
||||
.min(1)
|
||||
.transform((url) => normalizeURL(decodeURIComponent(url))),
|
||||
|
||||
audioFormat: z.enum(
|
||||
["best", "mp3", "ogg", "wav", "opus"]
|
||||
).default("mp3"),
|
||||
|
||||
downloadMode: z.enum(
|
||||
["auto", "audio", "mute"]
|
||||
).default("auto"),
|
||||
|
||||
filenameStyle: z.enum(
|
||||
["classic", "pretty", "basic", "nerdy"]
|
||||
).default("classic"),
|
||||
|
||||
youtubeVideoCodec: z.enum(
|
||||
["h264", "av1", "vp9"]
|
||||
).default("h264"),
|
||||
|
||||
videoQuality: z.enum([
|
||||
"max", "4320", "2160", "1440", "1080", "720", "480", "360", "240", "144"
|
||||
]).default("720"),
|
||||
|
||||
youtubeDubLang: z.string()
|
||||
.length(2)
|
||||
.transform(verifyLanguageCode)
|
||||
.optional(),
|
||||
|
||||
disableMetadata: z.boolean().default(false),
|
||||
tiktokFullAudio: z.boolean().default(false),
|
||||
tiktokH265: z.boolean().default(false),
|
||||
twitterGif: z.boolean().default(false),
|
||||
youtubeDubBrowserLang: z.boolean().default(false),
|
||||
})
|
||||
.strict();
|
||||
Loading…
Add table
Add a link
Reference in a new issue