From fbb091fd2a32a0ca90b3b979ec70ecb2a7589219 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 23 Oct 2023 00:37:30 +0800 Subject: [PATCH] fix: fix tianji domain update not support hostname problem --- src/server/trpc/routers/website.ts | 6 +++++- src/server/utils/const.ts | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index f042188..347e622 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -6,6 +6,7 @@ import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS, + hostnameRegex, } from '../../utils/const'; import { parseDateRange } from '../../utils/common'; import { getSessionMetrics, getPageviewMetrics } from '../../model/website'; @@ -160,7 +161,10 @@ export const websiteRouter = router({ z.object({ websiteId: z.string().cuid2(), name: z.string().max(100), - domain: z.union([z.string().max(500).url(), z.string().max(500).ip()]), + domain: z.union([ + z.string().max(500).regex(hostnameRegex), + z.string().max(500).ip(), + ]), monitorId: z.string().cuid2().nullish(), }) ) diff --git a/src/server/utils/const.ts b/src/server/utils/const.ts index f05fb01..0ca870d 100644 --- a/src/server/utils/const.ts +++ b/src/server/utils/const.ts @@ -117,3 +117,6 @@ export const DEFAULT_RESET_DATE = '2000-01-01'; export enum OPENAPI_TAG { USER = 'User', } + +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;