From 548db29a47e1596dda7f41c3ee0da7423522b1ea Mon Sep 17 00:00:00 2001 From: hjlarry Date: Thu, 16 Oct 2025 16:59:46 +0800 Subject: [PATCH] add var name check for webhook node --- .../nodes/trigger-webhook/use-config.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/web/app/components/workflow/nodes/trigger-webhook/use-config.ts b/web/app/components/workflow/nodes/trigger-webhook/use-config.ts index 76a3be2509..58cfe428fc 100644 --- a/web/app/components/workflow/nodes/trigger-webhook/use-config.ts +++ b/web/app/components/workflow/nodes/trigger-webhook/use-config.ts @@ -10,7 +10,7 @@ import { fetchWebhookUrl } from '@/service/apps' import type { Variable } from '@/app/components/workflow/types' import { VarType } from '@/app/components/workflow/types' import Toast from '@/app/components/base/toast' -import { hasDuplicateStr } from '@/utils/var' +import { checkKeys, hasDuplicateStr } from '@/utils/var' import { WEBHOOK_RAW_VARIABLE_NAME, ensureWebhookRawVariable } from './utils/raw-variable' const useConfig = (id: string, payload: WebhookTriggerNodeType) => { @@ -70,6 +70,34 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => { if (!draft.variables) draft.variables = [] + const hasReservedConflict = newData.some(item => item.name === WEBHOOK_RAW_VARIABLE_NAME) + if (hasReservedConflict) { + Toast.notify({ + type: 'error', + message: t('appDebug.varKeyError.keyAlreadyExists', { + key: t('appDebug.variableConfig.varName'), + }), + }) + return false + } + + const existingOtherVarNames = new Set( + draft.variables + .filter(v => v.label !== sourceType && v.variable !== WEBHOOK_RAW_VARIABLE_NAME) + .map(v => v.variable), + ) + + const crossScopeConflict = newData.find(item => existingOtherVarNames.has(item.name)) + if (crossScopeConflict) { + Toast.notify({ + type: 'error', + message: t('appDebug.varKeyError.keyAlreadyExists', { + key: crossScopeConflict.name, + }), + }) + return false + } + if(hasDuplicateStr(newData.map(item => item.name))) { Toast.notify({ type: 'error', @@ -80,6 +108,19 @@ const useConfig = (id: string, payload: WebhookTriggerNodeType) => { return false } + for (const item of newData) { + const { isValid, errorMessageKey } = checkKeys([item.name], false) + if (!isValid) { + Toast.notify({ + type: 'error', + message: t(`appDebug.varKeyError.${errorMessageKey}`, { + key: t('appDebug.variableConfig.varName'), + }), + }) + return false + } + } + // Create set of new variable names for this source const newVarNames = new Set(newData.map(item => item.name))