mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-08-21 16:23:42 +08:00
feat: add DOMAIN_LABELS for chinese domain label (#322)
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const CONSTANTS = {
|
||||
VERSION: 'v0.5.2',
|
||||
VERSION: 'v0.5.3',
|
||||
|
||||
// DB settings
|
||||
ADDRESS_BLOCK_LIST_KEY: 'address_block_list',
|
||||
|
||||
1
worker/src/types.d.ts
vendored
1
worker/src/types.d.ts
vendored
@@ -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
|
||||
|
||||
@@ -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 [];
|
||||
|
||||
Reference in New Issue
Block a user