From 75911667a65b4770b5e948d0e6889de4dfe63859 Mon Sep 17 00:00:00 2001 From: pumpkinperson996 Date: Thu, 9 Jul 2026 16:00:13 -0500 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=E8=A7=86=E9=A2=91=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E7=BC=BA=E5=8D=8F=E8=AE=AE=E5=A4=B4=E6=97=B6=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=A1=A5=20https://=20=E8=80=8C=E9=9D=9E=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=8B=92=E7=BB=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户从各处摘抄的链接常常没有 https:// 前缀(如 bilibili.com/...), 表单校验用 new URL() 解析会直接失败,提示"请输入正确的视频链接"。 校验时对无 scheme 的输入先补 https:// 再解析;提交时同样补全后再发 给后端(本地视频路径除外)。已有明确 scheme 的输入不受影响,ftp:// 等非 http(s) 协议仍被拒绝。 Co-Authored-By: Claude Fable 5 --- .../src/pages/HomePage/components/NoteForm.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BillNote_frontend/src/pages/HomePage/components/NoteForm.tsx b/BillNote_frontend/src/pages/HomePage/components/NoteForm.tsx index 9e9cbfa..8a04b7c 100644 --- a/BillNote_frontend/src/pages/HomePage/components/NoteForm.tsx +++ b/BillNote_frontend/src/pages/HomePage/components/NoteForm.tsx @@ -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 || '', }