From 91b84d8f1e7b94f5c694ae461ad3e812e089c439 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 29 Mar 2024 13:01:36 +0800 Subject: [PATCH] chore: http node check --- .../components/workflow/nodes/http/default.ts | 16 +++++++++------- web/i18n/en-US/workflow.ts | 1 + web/i18n/zh-Hans/workflow.ts | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/web/app/components/workflow/nodes/http/default.ts b/web/app/components/workflow/nodes/http/default.ts index 2e26712f08..91c6604a18 100644 --- a/web/app/components/workflow/nodes/http/default.ts +++ b/web/app/components/workflow/nodes/http/default.ts @@ -29,15 +29,17 @@ const nodeDefault: NodeDefault = { const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS return nodes }, - checkValid(payload: HttpNodeType) { - let isValid = true + checkValid(payload: HttpNodeType, t: any) { let errorMessages = '' - if (payload.type) { - isValid = true - errorMessages = '' - } + + if (!errorMessages && !payload.url) + errorMessages = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.http.api') }) + + if (!errorMessages && !payload.url.startsWith('http://') && !payload.url.startsWith('https://')) + errorMessages = t('workflow.nodes.http.notStartWithHttp') + return { - isValid, + isValid: !errorMessages, errorMessage: errorMessages, } }, diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index 2313b49f3b..01cb5665de 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -203,6 +203,7 @@ const translation = { http: { inputVars: 'Input Variables', api: 'API', + notStartWithHttp: 'API should start with http:// or https://', key: 'Key', value: 'Value', bulkEdit: 'Bulk Edit', diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index 76a1973898..5063e1a32d 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -203,6 +203,7 @@ const translation = { http: { inputVars: '输入变量', api: 'API', + notStartWithHttp: 'API 应该以 http:// 或 https:// 开头', key: '键', value: '值', bulkEdit: '批量编辑',