Skip to content

Commit

Permalink
fix: bugs && release v0.7.4 (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 authored Aug 24, 2024
1 parent 4c6fd3c commit a24cc1f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!-- markdownlint-disable-file MD004 MD024 MD034 MD036 -->
# CHANGE LOG

## main(v0.7.4)
## v0.7.4

- feat: UI 列表页面增加最小宽度
- fix: 修复 `name` 的校验检查
- fix: 修复 `DEFAULT_DOMAINS` 配置为空不生效的问题

## v0.7.3

Expand Down
24 changes: 21 additions & 3 deletions worker/src/common.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -127,6 +130,21 @@ export const newAddress = async (
}
}

const checkNameBlockList = async (
c: Context<HonoCustomType>, name: string
): Promise<void> => {
// 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<HonoCustomType>,
cleanType: string | undefined | null,
Expand Down
6 changes: 4 additions & 2 deletions worker/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ export const getStringArray = (
}

export const getDefaultDomains = (c: Context<HonoCustomType>): 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<HonoCustomType>): string[] => {
Expand Down

0 comments on commit a24cc1f

Please sign in to comment.