mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-05-06 20:42:52 +08:00
fix: 优化Schema校验逻辑
修复了以下问题: 1. 当视频链接为空时,原本的校验逻辑会导致首次点击生成笔记时报错“Required”而不是“视频链接不能为空”。 2. 当选择抖音时无法判断URL是否合法,即使填入“123”也能触发后面的逻辑。
This commit is contained in:
@@ -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) {
|
||||
ctx.addIssue({ code: 'custom', message: '本地视频路径不能为空', path: ['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)
|
||||
|
||||
Reference in New Issue
Block a user