fix: 优化Schema校验逻辑

修复了以下问题:
1. 当视频链接为空时,原本的校验逻辑会导致首次点击生成笔记时报错“Required”而不是“视频链接不能为空”。
2. 当选择抖音时无法判断URL是否合法,即使填入“123”也能触发后面的逻辑。
This commit is contained in:
Karasukaigan
2025-07-02 04:05:04 +08:00
parent ce76b78b34
commit 8fecf293bb

View File

@@ -43,7 +43,7 @@ import { useNavigate } from 'react-router-dom'
/* -------------------- 校验 Schema -------------------- */
const formSchema = z
.object({
video_url: z.string(),
video_url: z.string().optional(),
platform: z.string().nonempty('请选择平台'),
quality: z.enum(['fast', 'medium', 'slow']),
screenshot: z.boolean().optional(),
@@ -60,10 +60,10 @@ const formSchema = z
.optional(),
})
.superRefine(({ video_url, platform }, ctx) => {
if (platform === 'local' || platform === 'douyin') {
if (!video_url) {
if (platform === 'local' && !video_url) {
ctx.addIssue({ code: 'custom', message: '本地视频路径不能为空', path: ['video_url'] })
}
} else if (!video_url) {
ctx.addIssue({ code: 'custom', message: '视频链接不能为空', path: ['video_url'] })
} else {
try {
const url = new URL(video_url)