mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-08-06 22:14:09 +08:00
feat(subdomain): add random second-level mailbox support (#924)
Summary: add random second-level subdomain mailbox creation for web, admin, and Telegram. Scope: worker config, UI toggle, and README/VitePress documentation. Co-authored-by: wufei <fwu@creams.io>
This commit is contained in:
@@ -7,7 +7,8 @@ import { LocaleMessages } from "../i18n/type";
|
||||
|
||||
export const tgUserNewAddress = async (
|
||||
c: Context<HonoCustomType>, userId: string, address: string,
|
||||
msgs: LocaleMessages
|
||||
msgs: LocaleMessages,
|
||||
enableRandomSubdomain: boolean = false
|
||||
): Promise<{ address: string, jwt: string, password?: string | null }> => {
|
||||
if (c.env.RATE_LIMITER) {
|
||||
const { success } = await c.env.RATE_LIMITER.limit(
|
||||
@@ -41,6 +42,7 @@ export const tgUserNewAddress = async (
|
||||
name: finalName,
|
||||
domain,
|
||||
enablePrefix: true,
|
||||
enableRandomSubdomain,
|
||||
sourceMeta: `tg:${userId}`
|
||||
});
|
||||
// for mail push to telegram
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Context } from "hono";
|
||||
import { Jwt } from 'hono/utils/jwt'
|
||||
import { CONSTANTS } from "../constants";
|
||||
import { bindTelegramAddress, jwtListToAddressData, tgUserNewAddress, unbindTelegramAddress } from "./common";
|
||||
import { checkCfTurnstile, checkIsAdmin } from "../utils";
|
||||
import { checkCfTurnstile, checkIsAdmin, getBooleanValue } from "../utils";
|
||||
import { TelegramSettings } from "./settings";
|
||||
import i18n from "../i18n";
|
||||
|
||||
@@ -83,7 +83,7 @@ async function getTelegramBindAddress(c: Context<HonoCustomType>): Promise<Respo
|
||||
}
|
||||
|
||||
async function newTelegramAddress(c: Context<HonoCustomType>): Promise<Response> {
|
||||
const { initData, address, cf_token } = await c.req.json();
|
||||
const { initData, address, cf_token, enableRandomSubdomain } = await c.req.json();
|
||||
const msgs = i18n.getMessagesbyContext(c);
|
||||
// check cf turnstile
|
||||
try {
|
||||
@@ -94,7 +94,13 @@ async function newTelegramAddress(c: Context<HonoCustomType>): Promise<Response>
|
||||
try {
|
||||
const userId = await checkTelegramAuth(c, initData);
|
||||
// get the address list from the KV
|
||||
const res = await tgUserNewAddress(c, userId, address, msgs)
|
||||
const res = await tgUserNewAddress(
|
||||
c,
|
||||
userId,
|
||||
address,
|
||||
msgs,
|
||||
getBooleanValue(enableRandomSubdomain)
|
||||
)
|
||||
return c.json(res);
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user