feat: add DOMAIN_LABELS for chinese domain label (#322)

This commit is contained in:
Dream Hunter
2024-06-28 22:25:06 +08:00
committed by GitHub
parent de7c3d5176
commit 881e66e484
17 changed files with 1900 additions and 1659 deletions

View File

@@ -1,6 +1,6 @@
import { Hono } from 'hono'
import { getDomains, getPasswords, getBooleanValue, getIntValue } from './utils';
import { getDomains, getPasswords, getBooleanValue, getIntValue, getStringArray } from './utils';
import { CONSTANTS } from './constants';
import { HonoCustomType } from './types';
import { isS3Enabled } from './mails_api/s3_attachment';
@@ -21,6 +21,7 @@ api.get('/open_api/settings', async (c) => {
"minAddressLen": getIntValue(c.env.MIN_ADDRESS_LEN, 1),
"maxAddressLen": getIntValue(c.env.MAX_ADDRESS_LEN, 30),
"domains": getDomains(c),
"domainLabels": getStringArray(c.env.DOMAIN_LABELS),
"needAuth": needAuth,
"adminContact": c.env.ADMIN_CONTACT,
"enableUserCreateEmail": getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL),

View File

@@ -1,5 +1,5 @@
export const CONSTANTS = {
VERSION: 'v0.5.2',
VERSION: 'v0.5.3',
// DB settings
ADDRESS_BLOCK_LIST_KEY: 'address_block_list',

View File

@@ -11,6 +11,7 @@ export type Bindings = {
MIN_ADDRESS_LEN: string | number | undefined
MAX_ADDRESS_LEN: string | number | undefined
DOMAINS: string | string[] | undefined
DOMAIN_LABELS: string | string[] | undefined
PASSWORDS: string | string[] | undefined
ADMIN_PASSWORDS: string | string[] | undefined
JWT_SECRET: string

View File

@@ -79,6 +79,24 @@ export const getIntValue = (
return defaultValue;
}
export const getStringArray = (
value: string | string[] | undefined | null
): string[] => {
if (!value) {
return [];
}
// check if value is an array, if not use json.parse
if (!Array.isArray(value)) {
try {
return JSON.parse(value);
} catch (e) {
console.error("Failed to parse value", e);
return [];
}
}
return value;
}
export const getDomains = (c: Context<HonoCustomType>): string[] => {
if (!c.env.DOMAINS) {
return [];