mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-09-05 15:46:48 +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 -------------------- */
|
/* -------------------- 校验 Schema -------------------- */
|
||||||
const formSchema = z
|
const formSchema = z
|
||||||
.object({
|
.object({
|
||||||
video_url: z.string(),
|
video_url: z.string().optional(),
|
||||||
platform: z.string().nonempty('请选择平台'),
|
platform: z.string().nonempty('请选择平台'),
|
||||||
quality: z.enum(['fast', 'medium', 'slow']),
|
quality: z.enum(['fast', 'medium', 'slow']),
|
||||||
screenshot: z.boolean().optional(),
|
screenshot: z.boolean().optional(),
|
||||||
@@ -60,10 +60,10 @@ const formSchema = z
|
|||||||
.optional(),
|
.optional(),
|
||||||
})
|
})
|
||||||
.superRefine(({ video_url, platform }, ctx) => {
|
.superRefine(({ video_url, platform }, ctx) => {
|
||||||
if (platform === 'local' || platform === 'douyin') {
|
if (platform === 'local' && !video_url) {
|
||||||
if (!video_url) {
|
|
||||||
ctx.addIssue({ code: 'custom', message: '本地视频路径不能为空', path: ['video_url'] })
|
ctx.addIssue({ code: 'custom', message: '本地视频路径不能为空', path: ['video_url'] })
|
||||||
}
|
} else if (!video_url) {
|
||||||
|
ctx.addIssue({ code: 'custom', message: '视频链接不能为空', path: ['video_url'] })
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const url = new URL(video_url)
|
const url = new URL(video_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user