feat(platform): 开源发布 - 初始化 Open AI Canvas
This commit is contained in:
commit
aea35896eb
365 files changed
+66410
No files matched your search
@@ -0,0 +1,19 @@
|
||||
export const VIDEO_DURATION_OPTIONS = [6, 9, 10, 15] as const;
|
||||
export const VIDEO_RESOLUTION_OPTIONS = [480, 720, 1080] as const;
|
||||
|
||||
export function normalizeVideoDuration(value: string | number | undefined) {
|
||||
const seconds = Math.floor(Number(value) || VIDEO_DURATION_OPTIONS[0]);
|
||||
return String(nearestOption(seconds, VIDEO_DURATION_OPTIONS));
|
||||
}
|
||||
|
||||
export function normalizeVideoResolution(value: string | number | undefined) {
|
||||
const token = String(value || "").trim().toLowerCase();
|
||||
if (token === "low") return "480";
|
||||
if (token === "auto" || token === "medium" || token === "high") return "720";
|
||||
const resolution = Number(token.replace(/p$/i, "")) || 720;
|
||||
return String(nearestOption(resolution, VIDEO_RESOLUTION_OPTIONS));
|
||||
}
|
||||
|
||||
function nearestOption(value: number, options: readonly number[]) {
|
||||
return options.reduce((nearest, option) => Math.abs(option - value) < Math.abs(nearest - value) ? option : nearest, options[0]);
|
||||
}
|
||||
Reference in new issue
Block a user