From 4b255567bfc53fc4cfbdce89ef59b28d9ef9b88e Mon Sep 17 00:00:00 2001 From: jiangwel Date: Thu, 28 Aug 2025 14:36:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DAPI=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ModelModal中添加URL协议验证 - 移除modelkit.go中不必要的404检查条件 - 清理ModelModal中多余的错误显示逻辑 --- ui/ModelModal/package.json | 2 +- ui/ModelModal/src/ModelModal.tsx | 12 +++++------- usecase/modelkit.go | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ui/ModelModal/package.json b/ui/ModelModal/package.json index 5a1afcc..e6ac4a5 100644 --- a/ui/ModelModal/package.json +++ b/ui/ModelModal/package.json @@ -1,6 +1,6 @@ { "name": "@yokowu/modelkit-ui", - "version": "0.7.0", + "version": "0.7.1", "description": "A reusable AI model configuration modal component for React applications", "private": false, "type": "module", diff --git a/ui/ModelModal/src/ModelModal.tsx b/ui/ModelModal/src/ModelModal.tsx index f40381d..77e363b 100644 --- a/ui/ModelModal/src/ModelModal.tsx +++ b/ui/ModelModal/src/ModelModal.tsx @@ -507,6 +507,11 @@ export const ModelModal: React.FC = ({ value: true, message: 'URL 不能为空', }, + validate: (value) => { + if (!value) return true; // 空值由required规则处理 + const hasScheme = /^https?:\/\//i.test(value); + return hasScheme || 'API地址必须包含协议(http://或https://)'; + }, }} render={({ field }) => ( = ({ ) : modelUserList.length === 0 ? ( - <> - {addModelError && ( - - {addModelError} - - )} - ) : ( <> diff --git a/usecase/modelkit.go b/usecase/modelkit.go index 0d8889d..190d9f6 100644 --- a/usecase/modelkit.go +++ b/usecase/modelkit.go @@ -446,12 +446,12 @@ func generateBaseURLFixSuggestion(errContent string, baseURL string) string { hasPath = true } - errType := consts.AddModelBaseURLErrTypeHost + var errType consts.AddModelBaseURLErrType // 404 且是本地地址,建议使用宿主机主机名 if is404 && isLocal { errType = consts.AddModelBaseURLErrTypeHost - } else if !isLocal && !hasPath && !is404 { - // 不是本地地址,且没有path,且不是404,建议在API地址末尾添加/v1 + } else if !isLocal && !hasPath { + // 不是本地地址,且没有path,建议在API地址末尾添加/v1 errType = consts.AddModelBaseURLErrTypeV1Path } else { return ""