mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-07-09 22:42:19 +08:00
feat: add MIN_ADDRESS_LEN && MAX_ADDRESS_LEN (#304)
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
<!-- markdownlint-disable-file MD004 MD024 MD034 MD036 -->
|
<!-- markdownlint-disable-file MD004 MD024 MD034 MD036 -->
|
||||||
# CHANGE LOG
|
# CHANGE LOG
|
||||||
|
|
||||||
|
## main branch
|
||||||
|
|
||||||
|
- 添加 `mail-parser-wasm-worker` 用于 worker 解析邮件, [文档](https://temp-mail-docs.awsl.uk/zh/guide/feature/mail_parser_wasm_worker.html)
|
||||||
|
- 添加校验用户邮箱长度配置 `MIN_ADDRESS_LEN` 和 `MAX_ADDRESS_LEN`
|
||||||
|
- 修复 `pages function` 未转发 `telegram` api 问题
|
||||||
|
|
||||||
## v0.5.0
|
## v0.5.0
|
||||||
|
|
||||||
- UI: 增加本地缓存进行地址管理
|
- UI: 增加本地缓存进行地址管理
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ const getOpenSettings = async (message) => {
|
|||||||
Object.assign(openSettings.value, {
|
Object.assign(openSettings.value, {
|
||||||
title: res["title"] || "",
|
title: res["title"] || "",
|
||||||
prefix: res["prefix"] || "",
|
prefix: res["prefix"] || "",
|
||||||
|
minAddressLen: res["minAddressLen"] || 1,
|
||||||
|
maxAddressLen: res["maxAddressLen"] || 30,
|
||||||
needAuth: res["needAuth"] || false,
|
needAuth: res["needAuth"] || false,
|
||||||
domains: res["domains"].map((domain) => {
|
domains: res["domains"].map((domain) => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -189,7 +189,8 @@ onMounted(async () => {
|
|||||||
<n-input-group-label v-if="openSettings.prefix">
|
<n-input-group-label v-if="openSettings.prefix">
|
||||||
{{ openSettings.prefix }}
|
{{ openSettings.prefix }}
|
||||||
</n-input-group-label>
|
</n-input-group-label>
|
||||||
<n-input v-model:value="emailName" />
|
<n-input v-model:value="emailName" show-count :minlength="openSettings.minAddressLen"
|
||||||
|
:maxlength="openSettings.maxAddressLen" />
|
||||||
<n-input-group-label>@</n-input-group-label>
|
<n-input-group-label>@</n-input-group-label>
|
||||||
<n-select v-model:value="emailDomain" :consistent-menu-width="false"
|
<n-select v-model:value="emailDomain" :consistent-menu-width="false"
|
||||||
:options="openSettings.domains" />
|
:options="openSettings.domains" />
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
const API_PATHS = ["/api/", "/open_api/", "/user_api/", "/admin/"]
|
const API_PATHS = [
|
||||||
|
"/api/",
|
||||||
|
"/open_api/",
|
||||||
|
"/user_api/",
|
||||||
|
"/admin/",
|
||||||
|
"/telegram/"
|
||||||
|
];
|
||||||
|
|
||||||
export async function onRequest(context) {
|
export async function onRequest(context) {
|
||||||
const reqPath = new URL(context.request.url).pathname;
|
const reqPath = new URL(context.request.url).pathname;
|
||||||
|
|||||||
@@ -76,6 +76,9 @@ node_compat = true
|
|||||||
[vars]
|
[vars]
|
||||||
# TITLE = "Custom Title" # The title of the site
|
# TITLE = "Custom Title" # The title of the site
|
||||||
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_ADDRESS_LEN = 1
|
||||||
|
# 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
|
||||||
# PASSWORDS = ["123", "456"]
|
# PASSWORDS = ["123", "456"]
|
||||||
# admin console password, if not configured, access to the console is not allowed
|
# admin console password, if not configured, access to the console is not allowed
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ node_compat = true
|
|||||||
[vars]
|
[vars]
|
||||||
# TITLE = "Custom Title" # 自定义网站标题
|
# TITLE = "Custom Title" # 自定义网站标题
|
||||||
PREFIX = "tmp" # 要处理的邮箱名称前缀,不需要后缀可配置为空字符串
|
PREFIX = "tmp" # 要处理的邮箱名称前缀,不需要后缀可配置为空字符串
|
||||||
|
# (min, max) adderss的长度,如果不设置,默认为(1, 30)
|
||||||
|
# MIN_ADDRESS_LEN = 1
|
||||||
|
# MAX_ADDRESS_LEN = 30
|
||||||
# 如果你想要你的网站私有,取消下面的注释,并修改密码
|
# 如果你想要你的网站私有,取消下面的注释,并修改密码
|
||||||
# PASSWORDS = ["123", "456"]
|
# PASSWORDS = ["123", "456"]
|
||||||
# admin 控制台密码, 不配置则不允许访问控制台
|
# admin 控制台密码, 不配置则不允许访问控制台
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ api.post('/admin/new_address', async (c) => {
|
|||||||
return c.text("Please provide a name", 400)
|
return c.text("Please provide a name", 400)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await newAddress(c, name, domain, enablePrefix);
|
const res = await newAddress(c, name, domain, enablePrefix, false);
|
||||||
return c.json(res);
|
return c.json(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return c.text(`Failed create address: ${(e as Error).message}`, 400)
|
return c.text(`Failed create address: ${(e as Error).message}`, 400)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
|
|
||||||
import { getDomains, getPasswords, getBooleanValue } from './utils';
|
import { getDomains, getPasswords, getBooleanValue, getIntValue } from './utils';
|
||||||
import { CONSTANTS } from './constants';
|
import { CONSTANTS } from './constants';
|
||||||
import { HonoCustomType } from './types';
|
import { HonoCustomType } from './types';
|
||||||
import { isS3Enabled } from './mails_api/s3_attachment';
|
import { isS3Enabled } from './mails_api/s3_attachment';
|
||||||
@@ -18,6 +18,8 @@ api.get('/open_api/settings', async (c) => {
|
|||||||
return c.json({
|
return c.json({
|
||||||
"title": c.env.TITLE,
|
"title": c.env.TITLE,
|
||||||
"prefix": c.env.PREFIX,
|
"prefix": c.env.PREFIX,
|
||||||
|
"minAddressLen": getIntValue(c.env.MIN_ADDRESS_LEN, 1),
|
||||||
|
"maxAddressLen": getIntValue(c.env.MAX_ADDRESS_LEN, 30),
|
||||||
"domains": getDomains(c),
|
"domains": getDomains(c),
|
||||||
"needAuth": needAuth,
|
"needAuth": needAuth,
|
||||||
"adminContact": c.env.ADMIN_CONTACT,
|
"adminContact": c.env.ADMIN_CONTACT,
|
||||||
|
|||||||
@@ -1,28 +1,39 @@
|
|||||||
import { Context } from 'hono';
|
import { Context } from 'hono';
|
||||||
import { Jwt } from 'hono/utils/jwt'
|
import { Jwt } from 'hono/utils/jwt'
|
||||||
|
|
||||||
import { getBooleanValue, getDomains, getStringValue } from './utils';
|
import { getBooleanValue, getDomains, getStringValue, getIntValue } from './utils';
|
||||||
import { HonoCustomType } from './types';
|
import { HonoCustomType } from './types';
|
||||||
import { unbindTelegramByAddress } from './telegram_api/common';
|
import { unbindTelegramByAddress } from './telegram_api/common';
|
||||||
|
|
||||||
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,
|
||||||
enablePrefix: boolean
|
enablePrefix: boolean,
|
||||||
|
checkLengthByConfig: boolean = true
|
||||||
): Promise<{ address: string, jwt: string }> => {
|
): Promise<{ address: string, jwt: string }> => {
|
||||||
// remove special characters
|
// remove special characters
|
||||||
name = name.replace(/[^a-zA-Z0-9.]/g, '')
|
name = name.replace(/[^a-zA-Z0-9.]/g, '')
|
||||||
|
// name min length min 1
|
||||||
|
const minAddressLength = Math.max(
|
||||||
|
checkLengthByConfig ? getIntValue(c.env.MIN_ADDRESS_LEN, 1) : 1,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
// name max length min 1
|
||||||
|
const maxAddressLength = Math.max(
|
||||||
|
checkLengthByConfig ? getIntValue(c.env.MAX_ADDRESS_LEN, 30) : 30,
|
||||||
|
1
|
||||||
|
);
|
||||||
// check name length
|
// check name length
|
||||||
if (name.length <= 0) {
|
if (name.length < minAddressLength) {
|
||||||
throw new Error("Name too short")
|
throw new Error(`Name too short (min ${minAddressLength})`);
|
||||||
|
}
|
||||||
|
if (name.length > maxAddressLength) {
|
||||||
|
throw new Error(`Name too long (max ${maxAddressLength})`);
|
||||||
}
|
}
|
||||||
// create address
|
// create address
|
||||||
if (enablePrefix) {
|
if (enablePrefix) {
|
||||||
name = getStringValue(c.env.PREFIX) + name;
|
name = getStringValue(c.env.PREFIX) + name;
|
||||||
}
|
}
|
||||||
if (name.length >= 30) {
|
|
||||||
throw new Error("Name too long (max 30)")
|
|
||||||
}
|
|
||||||
// check domain, generate random domain
|
// check domain, generate random domain
|
||||||
const domains = getDomains(c);
|
const domains = getDomains(c);
|
||||||
if (!domain || !domains.includes(domain)) {
|
if (!domain || !domains.includes(domain)) {
|
||||||
|
|||||||
2
worker/src/types.d.ts
vendored
2
worker/src/types.d.ts
vendored
@@ -8,6 +8,8 @@ export type Bindings = {
|
|||||||
// config
|
// config
|
||||||
TITLE: string | undefined
|
TITLE: string | undefined
|
||||||
PREFIX: string | undefined
|
PREFIX: string | undefined
|
||||||
|
MIN_ADDRESS_LEN: string | number | undefined
|
||||||
|
MAX_ADDRESS_LEN: string | number | undefined
|
||||||
DOMAINS: string | string[] | undefined
|
DOMAINS: string | string[] | undefined
|
||||||
PASSWORDS: string | string[] | undefined
|
PASSWORDS: string | string[] | undefined
|
||||||
ADMIN_PASSWORDS: string | string[] | undefined
|
ADMIN_PASSWORDS: string | string[] | undefined
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ node_compat = true
|
|||||||
[vars]
|
[vars]
|
||||||
# TITLE = "Custom Title" # custom title
|
# TITLE = "Custom Title" # custom title
|
||||||
PREFIX = "tmp"
|
PREFIX = "tmp"
|
||||||
|
# (min, max) length of the adderss, if not set, the default is (1, 30)
|
||||||
|
# MIN_ADDRESS_LEN = 1
|
||||||
|
# MAX_ADDRESS_LEN = 30
|
||||||
# IF YOU WANT TO MAKE YOUR SITE PRIVATE, UNCOMMENT THE FOLLOWING LINES
|
# IF YOU WANT TO MAKE YOUR SITE PRIVATE, UNCOMMENT THE FOLLOWING LINES
|
||||||
# PASSWORDS = ["123", "456"]
|
# PASSWORDS = ["123", "456"]
|
||||||
# For admin panel
|
# For admin panel
|
||||||
|
|||||||
Reference in New Issue
Block a user