From a24cc1f642a50cc8f4cd2de59f2dca6c4924ce82 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sat, 24 Aug 2024 15:07:07 +0800 Subject: [PATCH] fix: bugs && release v0.7.4 (#432) --- CHANGELOG.md | 4 +++- worker/src/common.ts | 24 +++++++++++++++++++++--- worker/src/utils.ts | 6 ++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98d95d0b..3fa96eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # CHANGE LOG -## main(v0.7.4) +## v0.7.4 - feat: UI 列表页面增加最小宽度 +- fix: 修复 `name` 的校验检查 +- fix: 修复 `DEFAULT_DOMAINS` 配置为空不生效的问题 ## v0.7.3 diff --git a/worker/src/common.ts b/worker/src/common.ts index f92737f2..07ac5b17 100644 --- a/worker/src/common.ts +++ b/worker/src/common.ts @@ -1,7 +1,7 @@ import { Context } from 'hono'; import { Jwt } from 'hono/utils/jwt' -import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains } from './utils'; +import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting } from './utils'; import { HonoCustomType, UserRole } from './types'; import { unbindTelegramByAddress } from './telegram_api/common'; import { CONSTANTS } from './constants'; @@ -60,10 +60,13 @@ export const newAddress = async ( enableCheckNameRegex?: boolean, } ): Promise<{ address: string, jwt: string }> => { - // check name - if (enableCheckNameRegex) checkNameRegex(c, name); // remove special characters name = name.replace(getNameRegex(c), '') + // check name + if (enableCheckNameRegex) { + await checkNameBlockList(c, name); + checkNameRegex(c, name); + } // name min length min 1 const minAddressLength = Math.max( checkLengthByConfig ? getIntValue(c.env.MIN_ADDRESS_LEN, 1) : 1, @@ -127,6 +130,21 @@ export const newAddress = async ( } } +const checkNameBlockList = async ( + c: Context, name: string +): Promise => { + // check name block list + try { + const value = await getJsonSetting(c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY); + const blockList = (value || []) as string[]; + if (blockList.some((item) => name.includes(item))) { + throw new Error(`Name[${name}]is blocked`); + } + } catch (error) { + console.error(error); + } +} + export const cleanup = async ( c: Context, cleanType: string | undefined | null, diff --git a/worker/src/utils.ts b/worker/src/utils.ts index 0aaf0600..cc145ffa 100644 --- a/worker/src/utils.ts +++ b/worker/src/utils.ts @@ -97,9 +97,11 @@ export const getStringArray = ( } export const getDefaultDomains = (c: Context): string[] => { + if (c.env.DEFAULT_DOMAINS == undefined || c.env.DEFAULT_DOMAINS == null) { + return getDomains(c); + } const domains = getStringArray(c.env.DEFAULT_DOMAINS); - if (domains && domains.length > 0) return domains; - return getDomains(c); + return domains || getDomains(c); } export const getDomains = (c: Context): string[] => {