mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-08-28 19:46:57 +08:00
fix(frontend): 视频链接缺协议头时自动补 https:// 而非直接拒绝
用户从各处摘抄的链接常常没有 https:// 前缀(如 bilibili.com/...), 表单校验用 new URL() 解析会直接失败,提示"请输入正确的视频链接"。 校验时对无 scheme 的输入先补 https:// 再解析;提交时同样补全后再发 给后端(本地视频路径除外)。已有明确 scheme 的输入不受影响,ftp:// 等非 http(s) 协议仍被拒绝。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
6d67e5a76a
commit
75911667a6
@@ -42,6 +42,9 @@ import { useNavigate } from 'react-router-dom'
|
||||
import toast from 'react-hot-toast'
|
||||
|
||||
/* -------------------- 校验 Schema -------------------- */
|
||||
/** 用户粘贴的链接常缺协议头(如 bilibili.com/...),无任何 scheme 时自动补 https:// */
|
||||
const withScheme = (url: string) => (/^[a-z][a-z0-9+.-]*:\/\//i.test(url) ? url : `https://${url}`)
|
||||
|
||||
const formSchema = z
|
||||
.object({
|
||||
video_url: z.string().optional(),
|
||||
@@ -72,7 +75,7 @@ const formSchema = z
|
||||
}
|
||||
else {
|
||||
try {
|
||||
const url = new URL(video_url)
|
||||
const url = new URL(withScheme(video_url))
|
||||
if (!['http:', 'https:'].includes(url.protocol))
|
||||
throw new Error()
|
||||
}
|
||||
@@ -221,6 +224,8 @@ const NoteForm = () => {
|
||||
console.log('Not even go here')
|
||||
const payload: NoteFormValues = {
|
||||
...values,
|
||||
video_url:
|
||||
values.platform === 'local' ? values.video_url : withScheme(values.video_url || ''),
|
||||
provider_id: modelList.find(m => m.model_name === values.model_name)!.provider_id,
|
||||
task_id: currentTaskId || '',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user