mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-19 13:39:29 +08:00
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>
171 lines
6.4 KiB
JavaScript
171 lines
6.4 KiB
JavaScript
import { computed, ref } from "vue";
|
|
import {
|
|
createGlobalState, useStorage, useDark, useToggle,
|
|
useLocalStorage, useSessionStorage
|
|
} from '@vueuse/core'
|
|
|
|
export const useGlobalState = createGlobalState(
|
|
() => {
|
|
const isDark = useDark()
|
|
const toggleDark = useToggle(isDark)
|
|
const loading = ref(false);
|
|
const announcement = useLocalStorage('announcement', '');
|
|
const useSimpleIndex = useLocalStorage('useSimpleIndex', false);
|
|
const openSettings = ref({
|
|
fetched: false,
|
|
title: '',
|
|
announcement: '',
|
|
alwaysShowAnnouncement: false,
|
|
prefix: '',
|
|
addressRegex: '',
|
|
needAuth: false,
|
|
adminContact: '',
|
|
enableUserCreateEmail: false,
|
|
disableAnonymousUserCreateEmail: false,
|
|
disableCustomAddressName: false,
|
|
enableUserDeleteEmail: false,
|
|
enableAutoReply: false,
|
|
enableIndexAbout: false,
|
|
/** @type {string[]} */
|
|
defaultDomains: [],
|
|
/** @type {string[]} */
|
|
randomSubdomainDomains: [],
|
|
/** @type {Array<{label: string, value: string}>} */
|
|
domains: [],
|
|
copyright: 'Dream Hunter',
|
|
cfTurnstileSiteKey: '',
|
|
enableWebhook: false,
|
|
isS3Enabled: false,
|
|
enableSendMail: false,
|
|
showGithub: true,
|
|
disableAdminPasswordCheck: false,
|
|
enableAddressPassword: false,
|
|
statusUrl: '',
|
|
enableGlobalTurnstileCheck: false,
|
|
})
|
|
const settings = ref({
|
|
fetched: false,
|
|
send_balance: 0,
|
|
address: '',
|
|
auto_reply: {
|
|
subject: '',
|
|
message: '',
|
|
enabled: false,
|
|
source_prefix: '',
|
|
name: '',
|
|
}
|
|
});
|
|
const sendMailModel = useSessionStorage('sendMailModel', {
|
|
fromName: "",
|
|
toName: "",
|
|
toMail: "",
|
|
subject: "",
|
|
contentType: 'text',
|
|
content: "",
|
|
});
|
|
const showAuth = ref(false);
|
|
const showAddressCredential = ref(false);
|
|
const showAdminAuth = ref(false);
|
|
const auth = useStorage('auth', '');
|
|
const adminAuth = useStorage('adminAuth', '');
|
|
const jwt = useStorage('jwt', '');
|
|
const addressPassword = useSessionStorage('addressPassword', '');
|
|
const adminTab = useSessionStorage('adminTab', "account");
|
|
const adminMailTabAddress = ref("");
|
|
const adminSendBoxTabAddress = ref("");
|
|
const mailboxSplitSize = useStorage('mailboxSplitSize', 0.25);
|
|
const useIframeShowMail = useStorage('useIframeShowMail', false);
|
|
const preferShowTextMail = useStorage('preferShowTextMail', false);
|
|
const userJwt = useStorage('userJwt', '');
|
|
const userTab = useSessionStorage('userTab', 'address_management');
|
|
const indexTab = useSessionStorage('indexTab', 'mailbox');
|
|
const globalTabplacement = useStorage('globalTabplacement', 'top');
|
|
const useSideMargin = useStorage('useSideMargin', true);
|
|
const useUTCDate = useStorage('useUTCDate', false);
|
|
const autoRefresh = useStorage('autoRefresh', false);
|
|
const configAutoRefreshInterval = useStorage("configAutoRefreshInterval", 60);
|
|
const userOpenSettings = ref({
|
|
fetched: false,
|
|
enable: false,
|
|
enableMailVerify: false,
|
|
/** @type {{ clientID: string, name: string, icon?: string }[]} */
|
|
oauth2ClientIDs: [],
|
|
});
|
|
const userSettings = ref({
|
|
/** @type {boolean} */
|
|
fetched: false,
|
|
/** @type {string} */
|
|
user_email: '',
|
|
/** @type {number} */
|
|
user_id: 0,
|
|
/** @type {boolean} */
|
|
is_admin: false,
|
|
/** @type {string | null} */
|
|
access_token: null,
|
|
/** @type {string | null} */
|
|
new_user_token: null,
|
|
/** @type {null | {domains: string[] | undefined | null, role: string, prefix: string | undefined | null}} */
|
|
user_role: null,
|
|
});
|
|
const showAdminPage = computed(() =>
|
|
!!adminAuth.value
|
|
|| userSettings.value.is_admin
|
|
|| openSettings.value.disableAdminPasswordCheck
|
|
);
|
|
const telegramApp = ref(window.Telegram?.WebApp || {});
|
|
const isTelegram = ref(!!window.Telegram?.WebApp?.initData);
|
|
const _oauth2StateSession = useSessionStorage('userOauth2SessionState', '');
|
|
const _oauth2StateFallback = useStorage('userOauth2SessionState_fb', '');
|
|
const userOauth2SessionState = computed({
|
|
get: () => _oauth2StateSession.value || _oauth2StateFallback.value,
|
|
set: (v) => { _oauth2StateSession.value = v; _oauth2StateFallback.value = v; }
|
|
});
|
|
const _oauth2ClientIDSession = useSessionStorage('userOauth2SessionClientID', '');
|
|
const _oauth2ClientIDFallback = useStorage('userOauth2SessionClientID_fb', '');
|
|
const userOauth2SessionClientID = computed({
|
|
get: () => _oauth2ClientIDSession.value || _oauth2ClientIDFallback.value,
|
|
set: (v) => { _oauth2ClientIDSession.value = v; _oauth2ClientIDFallback.value = v; }
|
|
});
|
|
const browserFingerprint = ref('');
|
|
return {
|
|
isDark,
|
|
toggleDark,
|
|
loading,
|
|
settings,
|
|
sendMailModel,
|
|
announcement,
|
|
openSettings,
|
|
showAuth,
|
|
showAddressCredential,
|
|
auth,
|
|
jwt,
|
|
adminAuth,
|
|
showAdminAuth,
|
|
adminTab,
|
|
adminMailTabAddress,
|
|
adminSendBoxTabAddress,
|
|
mailboxSplitSize,
|
|
useIframeShowMail,
|
|
preferShowTextMail,
|
|
userJwt,
|
|
userTab,
|
|
indexTab,
|
|
userOpenSettings,
|
|
userSettings,
|
|
globalTabplacement,
|
|
useSideMargin,
|
|
useUTCDate,
|
|
autoRefresh,
|
|
configAutoRefreshInterval,
|
|
telegramApp,
|
|
isTelegram,
|
|
showAdminPage,
|
|
userOauth2SessionState,
|
|
userOauth2SessionClientID,
|
|
useSimpleIndex,
|
|
addressPassword,
|
|
browserFingerprint,
|
|
}
|
|
},
|
|
)
|