From 08ea915d24de33e25ac4d0218c7bd12ed32af7ea Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Thu, 12 Jun 2025 14:03:29 +0800 Subject: [PATCH] fix: #786 --- .../tencentcloud-eo/tencentcloud_eo.go | 2 +- ...ployNodeConfigFormTencentCloudEOConfig.tsx | 2 +- .../i18n/locales/zh/nls.workflow.nodes.json | 2 +- ui/src/utils/validators.ts | 32 +++++++++++++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/internal/pkg/core/deployer/providers/tencentcloud-eo/tencentcloud_eo.go b/internal/pkg/core/deployer/providers/tencentcloud-eo/tencentcloud_eo.go index 138fb84a..1a4a199b 100644 --- a/internal/pkg/core/deployer/providers/tencentcloud-eo/tencentcloud_eo.go +++ b/internal/pkg/core/deployer/providers/tencentcloud-eo/tencentcloud_eo.go @@ -23,7 +23,7 @@ type DeployerConfig struct { SecretKey string `json:"secretKey"` // 站点 ID。 ZoneId string `json:"zoneId"` - // 加速域名(不支持泛域名)。 + // 加速域名(支持泛域名)。 Domain string `json:"domain"` } diff --git a/ui/src/components/workflow/node/DeployNodeConfigFormTencentCloudEOConfig.tsx b/ui/src/components/workflow/node/DeployNodeConfigFormTencentCloudEOConfig.tsx index 5c93600c..44e277eb 100644 --- a/ui/src/components/workflow/node/DeployNodeConfigFormTencentCloudEOConfig.tsx +++ b/ui/src/components/workflow/node/DeployNodeConfigFormTencentCloudEOConfig.tsx @@ -38,7 +38,7 @@ const DeployNodeConfigFormTencentCloudEOConfig = ({ .trim(), domain: z .string({ message: t("workflow_node.deploy.form.tencentcloud_eo_domain.placeholder") }) - .refine((v) => validDomainName(v), t("common.errmsg.domain_invalid")), + .refine((v) => validDomainName(v, { allowWildcard: true }), t("common.errmsg.domain_invalid")), }); const formRule = createSchemaFieldRule(formSchema); diff --git a/ui/src/i18n/locales/zh/nls.workflow.nodes.json b/ui/src/i18n/locales/zh/nls.workflow.nodes.json index a27ec30a..88d2b934 100644 --- a/ui/src/i18n/locales/zh/nls.workflow.nodes.json +++ b/ui/src/i18n/locales/zh/nls.workflow.nodes.json @@ -667,7 +667,7 @@ "workflow_node.deploy.form.tencentcloud_eo_zone_id.placeholder": "请输入腾讯云 EdgeOne 站点 ID", "workflow_node.deploy.form.tencentcloud_eo_zone_id.tooltip": "这是什么?请参阅 https://console.cloud.tencent.com/edgeone", "workflow_node.deploy.form.tencentcloud_eo_domain.label": "腾讯云 EdgeOne 加速域名", - "workflow_node.deploy.form.tencentcloud_eo_domain.placeholder": "请输入腾讯云 EdgeOne 加速域名", + "workflow_node.deploy.form.tencentcloud_eo_domain.placeholder": "请输入腾讯云 EdgeOne 加速域名(支持泛域名)", "workflow_node.deploy.form.tencentcloud_eo_domain.tooltip": "这是什么?请参阅 https://console.cloud.tencent.com/edgeone", "workflow_node.deploy.form.tencentcloud_scf_region.label": "腾讯云 SCF 产品地域", "workflow_node.deploy.form.tencentcloud_scf_region.placeholder": "输入腾讯云 SCF 产品地域(例如:ap-guangzhou)", diff --git a/ui/src/utils/validators.ts b/ui/src/utils/validators.ts index 05d43edd..c170ce40 100644 --- a/ui/src/utils/validators.ts +++ b/ui/src/utils/validators.ts @@ -1,4 +1,6 @@ -import { validCronExpression as _validCronExpression } from "./cron"; +import { z } from "zod"; + +import { validCronExpression as _validCronExpression } from "./cron"; export const validCronExpression = (value: string) => { return _validCronExpression(value); @@ -10,20 +12,30 @@ export const validDomainName = (value: string, { allowWildcard = false }: { allo }; export const validEmailAddress = (value: string) => { - const re = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; - return re.test(value); + try { + z.string().email().parse(value); + return true; + } catch (_) { + return false; + } }; export const validIPv4Address = (value: string) => { - const re = - /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/; - return re.test(value); + try { + z.string().ip({ version: "v4" }).parse(value); + return true; + } catch (_) { + return false; + } }; export const validIPv6Address = (value: string) => { - const re = - /^([\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)|::([\da−fA−F]1,4:)0,4((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|::([\da−fA−F]1,4:)0,4((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|^([\da-fA-F]{1,4}:):([\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)|([\da−fA−F]1,4:)2:([\da−fA−F]1,4:)0,2((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|([\da−fA−F]1,4:)2:([\da−fA−F]1,4:)0,2((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|^([\da-fA-F]{1,4}:){3}:([\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)|([\da−fA−F]1,4:)4:((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|([\da−fA−F]1,4:)4:((25[0−5]|2[0−4]\d|[01]?\d\d?)\.)3(25[0−5]|2[0−4]\d|[01]?\d\d?)|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}|:((:[\da−fA−F]1,4)1,6|:)|:((:[\da−fA−F]1,4)1,6|:)|^[\da-fA-F]{1,4}:((:[\da-fA-F]{1,4}){1,5}|:)|([\da−fA−F]1,4:)2((:[\da−fA−F]1,4)1,4|:)|([\da−fA−F]1,4:)2((:[\da−fA−F]1,4)1,4|:)|^([\da-fA-F]{1,4}:){3}((:[\da-fA-F]{1,4}){1,3}|:)|([\da−fA−F]1,4:)4((:[\da−fA−F]1,4)1,2|:)|([\da−fA−F]1,4:)4((:[\da−fA−F]1,4)1,2|:)|^([\da-fA-F]{1,4}:){5}:([\da-fA-F]{1,4})?|([\da−fA−F]1,4:)6:|([\da−fA−F]1,4:)6:/; - return re.test(value); + try { + z.string().ip({ version: "v6" }).parse(value); + return true; + } catch (_) { + return false; + } }; export const validHttpOrHttpsUrl = (value: string) => { @@ -36,5 +48,5 @@ export const validHttpOrHttpsUrl = (value: string) => { }; export const validPortNumber = (value: string | number) => { - return parseInt(value + "") === +value && +value >= 1 && +value <= 65535; + return parseInt(value + "") === +value && String(+value) === String(value) && +value >= 1 && +value <= 65535; };