From 987c09be2f1ae57a99c4ce495fd835cd2fb120e0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 5 Dec 2023 20:27:38 +0800 Subject: [PATCH] feat: add monitor validator --- .../components/monitor/provider/http.tsx | 15 ++++++++++++++- .../components/monitor/provider/ping.tsx | 19 ++++++++++++++++++- src/server/trpc/routers/website.ts | 2 +- src/server/utils/const.ts | 3 --- src/shared/index.ts | 1 + src/shared/regex.ts | 2 ++ 6 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/shared/regex.ts diff --git a/src/client/components/monitor/provider/http.tsx b/src/client/components/monitor/provider/http.tsx index 7ed582e..1455ccb 100644 --- a/src/client/components/monitor/provider/http.tsx +++ b/src/client/components/monitor/provider/http.tsx @@ -6,6 +6,7 @@ import { MonitorStatsBlock } from '../MonitorStatsBlock'; import dayjs from 'dayjs'; import { isEmpty } from 'lodash-es'; import { useCurrentWorkspaceId } from '../../../store/user'; +import { z } from 'zod'; const MonitorHttp: React.FC = React.memo(() => { return ( @@ -13,7 +14,19 @@ const MonitorHttp: React.FC = React.memo(() => { diff --git a/src/client/components/monitor/provider/ping.tsx b/src/client/components/monitor/provider/ping.tsx index 41bf584..ea9811d 100644 --- a/src/client/components/monitor/provider/ping.tsx +++ b/src/client/components/monitor/provider/ping.tsx @@ -1,6 +1,8 @@ import { Form, Input } from 'antd'; import React from 'react'; import { MonitorProvider } from './types'; +import { z } from 'zod'; +import { hostnameRegex } from '../../../../shared'; export const MonitorPing: React.FC = React.memo(() => { return ( @@ -8,7 +10,22 @@ export const MonitorPing: React.FC = React.memo(() => { diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index 3379223..24994db 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -12,12 +12,12 @@ import { FILTER_COLUMNS, OPENAPI_TAG, SESSION_COLUMNS, - hostnameRegex, } from '../../utils/const'; import { parseDateRange } from '../../utils/common'; import { getSessionMetrics, getPageviewMetrics } from '../../model/website'; import { websiteInfoSchema } from '../../model/_schema'; import { OpenApiMeta } from 'trpc-openapi'; +import { hostnameRegex } from '../../../shared'; export const websiteRouter = router({ onlineCount: workspaceProcedure diff --git a/src/server/utils/const.ts b/src/server/utils/const.ts index c744ace..74fa3b3 100644 --- a/src/server/utils/const.ts +++ b/src/server/utils/const.ts @@ -120,6 +120,3 @@ export enum OPENAPI_TAG { WEBSITE = 'Website', MONITOR = 'Monitor', } - -export const hostnameRegex = - /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/gim; diff --git a/src/shared/index.ts b/src/shared/index.ts index c63001a..842b65e 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,2 +1,3 @@ export * from './date'; export * from './server'; +export * from './regex'; diff --git a/src/shared/regex.ts b/src/shared/regex.ts new file mode 100644 index 0000000..b37ddd3 --- /dev/null +++ b/src/shared/regex.ts @@ -0,0 +1,2 @@ +export const hostnameRegex = + /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;