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:
tsymr
2026-04-02 23:13:10 +08:00
committed by GitHub
parent be1bf71a47
commit db93828a81
24 changed files with 273 additions and 57 deletions

View File

@@ -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

View File

@@ -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) {