mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 23:47:50 +08:00
feat: add ADDRESS_REGEX (#401)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
## main(v0.7.2)
|
## main(v0.7.2)
|
||||||
|
|
||||||
- fix: worker 增加 `NO_LIMIT_SEND_ROLE` 配置, 加载失败的问题
|
- fix: worker 增加 `NO_LIMIT_SEND_ROLE` 配置, 加载失败的问题
|
||||||
|
- feat: worker 增加 `# ADDRESS_REGEX = "[^a-z.0-9]"` 配置, 用于配置地址的正则表达式
|
||||||
|
|
||||||
## v0.7.1
|
## v0.7.1
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export const useGlobalState = createGlobalState(
|
|||||||
title: '',
|
title: '',
|
||||||
announcement: '',
|
announcement: '',
|
||||||
prefix: '',
|
prefix: '',
|
||||||
|
addressRegex: '',
|
||||||
needAuth: false,
|
needAuth: false,
|
||||||
adminContact: '',
|
adminContact: '',
|
||||||
enableUserCreateEmail: false,
|
enableUserCreateEmail: false,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const { locale, t } = useI18n({
|
|||||||
login: 'Login',
|
login: 'Login',
|
||||||
pleaseGetNewEmail: 'Please login or click "Get New Email" button to get a new email address',
|
pleaseGetNewEmail: 'Please login or click "Get New Email" button to get a new email address',
|
||||||
getNewEmail: 'Create New Email',
|
getNewEmail: 'Create New Email',
|
||||||
getNewEmailTip1: 'Please input the email you want to use. only allow a-z and 0-9',
|
getNewEmailTip1: 'Please input the email you want to use. only allow: ',
|
||||||
getNewEmailTip2: 'Levaing it blank will generate a random email address.',
|
getNewEmailTip2: 'Levaing it blank will generate a random email address.',
|
||||||
getNewEmailTip3: 'You can choose a domain from the dropdown list.',
|
getNewEmailTip3: 'You can choose a domain from the dropdown list.',
|
||||||
credential: 'Email Address Credential',
|
credential: 'Email Address Credential',
|
||||||
@@ -87,7 +87,7 @@ const { locale, t } = useI18n({
|
|||||||
login: '登录',
|
login: '登录',
|
||||||
pleaseGetNewEmail: '请"登录"或点击 "注册新邮箱" 按钮来获取一个新的邮箱地址',
|
pleaseGetNewEmail: '请"登录"或点击 "注册新邮箱" 按钮来获取一个新的邮箱地址',
|
||||||
getNewEmail: '创建新邮箱',
|
getNewEmail: '创建新邮箱',
|
||||||
getNewEmailTip1: '请输入你想要使用的邮箱地址, 只允许 a-z, 0-9',
|
getNewEmailTip1: '请输入你想要使用的邮箱地址, 只允许: ',
|
||||||
getNewEmailTip2: '留空将会生成一个随机的邮箱地址。',
|
getNewEmailTip2: '留空将会生成一个随机的邮箱地址。',
|
||||||
getNewEmailTip3: '你可以从下拉列表中选择一个域名。',
|
getNewEmailTip3: '你可以从下拉列表中选择一个域名。',
|
||||||
credential: '邮箱地址凭据',
|
credential: '邮箱地址凭据',
|
||||||
@@ -101,6 +101,18 @@ const { locale, t } = useI18n({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const addressRegex = computed(() => {
|
||||||
|
try {
|
||||||
|
if (openSettings.value.addressRegex) {
|
||||||
|
return new RegExp(openSettings.value.addressRegex, 'g');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
message.error(`Invalid addressRegex: ${openSettings.value.addressRegex}`);
|
||||||
|
}
|
||||||
|
return /[^a-z0-9]/g;
|
||||||
|
});
|
||||||
|
|
||||||
const generateNameLoading = ref(false);
|
const generateNameLoading = ref(false);
|
||||||
const generateName = async () => {
|
const generateName = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -110,7 +122,7 @@ const generateName = async () => {
|
|||||||
.split('@')[0]
|
.split('@')[0]
|
||||||
.replace(/\s+/g, '.')
|
.replace(/\s+/g, '.')
|
||||||
.replace(/\.{2,}/g, '.')
|
.replace(/\.{2,}/g, '.')
|
||||||
.replace(/[^a-z0-9]/g, '')
|
.replace(addressRegex.value, '')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error.message || "error");
|
message.error(error.message || "error");
|
||||||
@@ -206,7 +218,7 @@ onMounted(async () => {
|
|||||||
<n-spin :show="generateNameLoading">
|
<n-spin :show="generateNameLoading">
|
||||||
<n-form>
|
<n-form>
|
||||||
<span>
|
<span>
|
||||||
<p>{{ t("getNewEmailTip1") }}</p>
|
<p>{{ t("getNewEmailTip1") + addressRegex.source }}</p>
|
||||||
<p>{{ t("getNewEmailTip2") }}</p>
|
<p>{{ t("getNewEmailTip2") }}</p>
|
||||||
<p>{{ t("getNewEmailTip3") }}</p>
|
<p>{{ t("getNewEmailTip3") }}</p>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ node_compat = true
|
|||||||
PREFIX = "tmp" # The mailbox name prefix to be processed
|
PREFIX = "tmp" # The mailbox name prefix to be processed
|
||||||
# (min, max) length of the adderss, if not set, the default is (1, 30)
|
# (min, max) length of the adderss, if not set, the default is (1, 30)
|
||||||
# ANNOUNCEMENT = "Custom Announcement"
|
# ANNOUNCEMENT = "Custom Announcement"
|
||||||
|
# address name REGEX, if not set, the default is [^a-z0-9]
|
||||||
|
# ADDRESS_REGEX = "[^a-z0-9]"
|
||||||
# MIN_ADDRESS_LEN = 1
|
# MIN_ADDRESS_LEN = 1
|
||||||
# MAX_ADDRESS_LEN = 30
|
# MAX_ADDRESS_LEN = 30
|
||||||
# If you want your site to be private, uncomment below and change your password
|
# If you want your site to be private, uncomment below and change your password
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ node_compat = true
|
|||||||
PREFIX = "tmp" # 要处理的邮箱名称前缀,不需要后缀可配置为空字符串
|
PREFIX = "tmp" # 要处理的邮箱名称前缀,不需要后缀可配置为空字符串
|
||||||
# (min, max) adderss的长度,如果不设置,默认为(1, 30)
|
# (min, max) adderss的长度,如果不设置,默认为(1, 30)
|
||||||
# ANNOUNCEMENT = "Custom Announcement" # 自定义公告
|
# ANNOUNCEMENT = "Custom Announcement" # 自定义公告
|
||||||
|
# address name 的正则表达式,如果不设置,默认为 [^a-z0-9]
|
||||||
|
# ADDRESS_REGEX = "[^a-z0-9]"
|
||||||
# MIN_ADDRESS_LEN = 1
|
# MIN_ADDRESS_LEN = 1
|
||||||
# MAX_ADDRESS_LEN = 30
|
# MAX_ADDRESS_LEN = 30
|
||||||
# 如果你想要你的网站私有,取消下面的注释,并修改密码
|
# 如果你想要你的网站私有,取消下面的注释,并修改密码
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ api.get('/open_api/settings', async (c) => {
|
|||||||
"title": c.env.TITLE,
|
"title": c.env.TITLE,
|
||||||
"announcement": getStringValue(c.env.ANNOUNCEMENT),
|
"announcement": getStringValue(c.env.ANNOUNCEMENT),
|
||||||
"prefix": c.env.PREFIX,
|
"prefix": c.env.PREFIX,
|
||||||
|
"addressRegex": getStringValue(c.env.ADDRESS_REGEX),
|
||||||
"minAddressLen": getIntValue(c.env.MIN_ADDRESS_LEN, 1),
|
"minAddressLen": getIntValue(c.env.MIN_ADDRESS_LEN, 1),
|
||||||
"maxAddressLen": getIntValue(c.env.MAX_ADDRESS_LEN, 30),
|
"maxAddressLen": getIntValue(c.env.MAX_ADDRESS_LEN, 30),
|
||||||
"defaultDomains": getDefaultDomains(c),
|
"defaultDomains": getDefaultDomains(c),
|
||||||
|
|||||||
+17
-1
@@ -5,6 +5,22 @@ import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles,
|
|||||||
import { HonoCustomType, UserRole } from './types';
|
import { HonoCustomType, UserRole } from './types';
|
||||||
import { unbindTelegramByAddress } from './telegram_api/common';
|
import { unbindTelegramByAddress } from './telegram_api/common';
|
||||||
|
|
||||||
|
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
|
||||||
|
|
||||||
|
const getNameRegex = (c: Context<HonoCustomType>): RegExp => {
|
||||||
|
try {
|
||||||
|
const regex = getStringValue(c.env.ADDRESS_REGEX);
|
||||||
|
if (!regex) {
|
||||||
|
return DEFAULT_NAME_REGEX;
|
||||||
|
}
|
||||||
|
return new RegExp(regex, 'g');
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error("Failed to get address regex", e);
|
||||||
|
}
|
||||||
|
return DEFAULT_NAME_REGEX;
|
||||||
|
}
|
||||||
|
|
||||||
export const newAddress = async (
|
export const newAddress = async (
|
||||||
c: Context<HonoCustomType>,
|
c: Context<HonoCustomType>,
|
||||||
name: string, domain: string | undefined | null,
|
name: string, domain: string | undefined | null,
|
||||||
@@ -14,7 +30,7 @@ export const newAddress = async (
|
|||||||
checkAllowDomains: boolean = true
|
checkAllowDomains: boolean = true
|
||||||
): Promise<{ address: string, jwt: string }> => {
|
): Promise<{ address: string, jwt: string }> => {
|
||||||
// remove special characters
|
// remove special characters
|
||||||
name = name.replace(/[^a-z0-9]/g, '')
|
name = name.replace(getNameRegex(c), '')
|
||||||
// name min length min 1
|
// name min length min 1
|
||||||
const minAddressLength = Math.max(
|
const minAddressLength = Math.max(
|
||||||
checkLengthByConfig ? getIntValue(c.env.MIN_ADDRESS_LEN, 1) : 1,
|
checkLengthByConfig ? getIntValue(c.env.MIN_ADDRESS_LEN, 1) : 1,
|
||||||
|
|||||||
Vendored
+1
@@ -15,6 +15,7 @@ export type Bindings = {
|
|||||||
TITLE: string | undefined
|
TITLE: string | undefined
|
||||||
ANNOUNCEMENT: string | undefined | null
|
ANNOUNCEMENT: string | undefined | null
|
||||||
PREFIX: string | undefined
|
PREFIX: string | undefined
|
||||||
|
ADDRESS_REGEX: string | undefined
|
||||||
MIN_ADDRESS_LEN: string | number | undefined
|
MIN_ADDRESS_LEN: string | number | undefined
|
||||||
MAX_ADDRESS_LEN: string | number | undefined
|
MAX_ADDRESS_LEN: string | number | undefined
|
||||||
DEFAULT_DOMAINS: string | string[] | undefined
|
DEFAULT_DOMAINS: string | string[] | undefined
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ node_compat = true
|
|||||||
# TITLE = "Custom Title" # custom title
|
# TITLE = "Custom Title" # custom title
|
||||||
# ANNOUNCEMENT = "Custom Announcement"
|
# ANNOUNCEMENT = "Custom Announcement"
|
||||||
PREFIX = "tmp"
|
PREFIX = "tmp"
|
||||||
|
# address name REGEX, if not set, the default is [^a-z0-9]
|
||||||
|
# ADDRESS_REGEX = "[^a-z0-9]"
|
||||||
# (min, max) length of the adderss, if not set, the default is (1, 30)
|
# (min, max) length of the adderss, if not set, the default is (1, 30)
|
||||||
# MIN_ADDRESS_LEN = 1
|
# MIN_ADDRESS_LEN = 1
|
||||||
# MAX_ADDRESS_LEN = 30
|
# MAX_ADDRESS_LEN = 30
|
||||||
|
|||||||
Reference in New Issue
Block a user