fix: bugs && release v0.7.4 (#432)

This commit is contained in:
Dream Hunter
2024-08-24 15:07:07 +08:00
committed by GitHub
parent 4c6fd3c2af
commit a24cc1f642
3 changed files with 28 additions and 6 deletions

View File

@@ -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<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,

View File

@@ -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[] => {