mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-05-06 20:02:51 +08:00
feat: add cloud-mail service support
This commit is contained in:
@@ -24,7 +24,8 @@ let availableServices = {
|
||||
moe_mail: { available: false, services: [] },
|
||||
temp_mail: { available: false, services: [] },
|
||||
duck_mail: { available: false, services: [] },
|
||||
freemail: { available: false, services: [] }
|
||||
freemail: { available: false, services: [] },
|
||||
cloud_mail: { available: false, services: [] }
|
||||
};
|
||||
|
||||
// WebSocket 相关变量
|
||||
@@ -376,6 +377,23 @@ function updateEmailServiceOptions() {
|
||||
|
||||
select.appendChild(optgroup);
|
||||
}
|
||||
|
||||
// Cloud Mail
|
||||
if (availableServices.cloud_mail && availableServices.cloud_mail.available) {
|
||||
const optgroup = document.createElement('optgroup');
|
||||
optgroup.label = `☁️ Cloud Mail (${availableServices.cloud_mail.count} 个服务)`;
|
||||
|
||||
availableServices.cloud_mail.services.forEach(service => {
|
||||
const option = document.createElement('option');
|
||||
option.value = `cloud_mail:${service.id}`;
|
||||
option.textContent = service.name + (service.default_domain ? ` (@${service.default_domain})` : '');
|
||||
option.dataset.type = 'cloud_mail';
|
||||
option.dataset.serviceId = service.id;
|
||||
optgroup.appendChild(option);
|
||||
});
|
||||
|
||||
select.appendChild(optgroup);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理邮箱服务切换
|
||||
@@ -426,6 +444,11 @@ function handleServiceChange(e) {
|
||||
if (service) {
|
||||
addLog('info', `[系统] 已选择 Freemail 服务: ${service.name}`);
|
||||
}
|
||||
} else if (type === 'cloud_mail') {
|
||||
const service = availableServices.cloud_mail.services.find(s => s.id == id);
|
||||
if (service) {
|
||||
addLog('info', `[系统] 已选择 Cloud Mail 服务: ${service.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// 状态
|
||||
let outlookServices = [];
|
||||
let customServices = []; // 合并 moe_mail + temp_mail + duck_mail + freemail + imap_mail
|
||||
let customServices = []; // 合并 moe_mail + temp_mail + duck_mail + freemail + cloud_mail + imap_mail
|
||||
let selectedOutlook = new Set();
|
||||
let selectedCustom = new Set();
|
||||
|
||||
@@ -52,6 +52,7 @@ const elements = {
|
||||
addTempmailFields: document.getElementById('add-tempmail-fields'),
|
||||
addDuckmailFields: document.getElementById('add-duckmail-fields'),
|
||||
addFreemailFields: document.getElementById('add-freemail-fields'),
|
||||
addCloudmailFields: document.getElementById('add-cloudmail-fields'),
|
||||
addImapFields: document.getElementById('add-imap-fields'),
|
||||
|
||||
// 编辑自定义域名模态框
|
||||
@@ -63,6 +64,7 @@ const elements = {
|
||||
editTempmailFields: document.getElementById('edit-tempmail-fields'),
|
||||
editDuckmailFields: document.getElementById('edit-duckmail-fields'),
|
||||
editFreemailFields: document.getElementById('edit-freemail-fields'),
|
||||
editCloudmailFields: document.getElementById('edit-cloudmail-fields'),
|
||||
editImapFields: document.getElementById('edit-imap-fields'),
|
||||
editCustomTypeBadge: document.getElementById('edit-custom-type-badge'),
|
||||
editCustomSubTypeHidden: document.getElementById('edit-custom-sub-type-hidden'),
|
||||
@@ -79,6 +81,7 @@ const CUSTOM_SUBTYPE_LABELS = {
|
||||
tempmail: '📮 TempMail(自部署 Cloudflare Worker)',
|
||||
duckmail: '🦆 DuckMail(DuckMail API)',
|
||||
freemail: 'Freemail(自部署 Cloudflare Worker)',
|
||||
cloudmail: '☁️ Cloud Mail(公开 API)',
|
||||
imap: '📧 IMAP 邮箱(Gmail/QQ/163等)'
|
||||
};
|
||||
|
||||
@@ -185,6 +188,7 @@ function switchAddSubType(subType) {
|
||||
elements.addTempmailFields.style.display = subType === 'tempmail' ? '' : 'none';
|
||||
elements.addDuckmailFields.style.display = subType === 'duckmail' ? '' : 'none';
|
||||
elements.addFreemailFields.style.display = subType === 'freemail' ? '' : 'none';
|
||||
elements.addCloudmailFields.style.display = subType === 'cloudmail' ? '' : 'none';
|
||||
elements.addImapFields.style.display = subType === 'imap' ? '' : 'none';
|
||||
}
|
||||
|
||||
@@ -195,6 +199,7 @@ function switchEditSubType(subType) {
|
||||
elements.editTempmailFields.style.display = subType === 'tempmail' ? '' : 'none';
|
||||
elements.editDuckmailFields.style.display = subType === 'duckmail' ? '' : 'none';
|
||||
elements.editFreemailFields.style.display = subType === 'freemail' ? '' : 'none';
|
||||
elements.editCloudmailFields.style.display = subType === 'cloudmail' ? '' : 'none';
|
||||
elements.editImapFields.style.display = subType === 'imap' ? '' : 'none';
|
||||
elements.editCustomTypeBadge.textContent = CUSTOM_SUBTYPE_LABELS[subType] || CUSTOM_SUBTYPE_LABELS.moemail;
|
||||
}
|
||||
@@ -204,7 +209,7 @@ async function loadStats() {
|
||||
try {
|
||||
const data = await api.get('/email-services/stats');
|
||||
elements.outlookCount.textContent = data.outlook_count || 0;
|
||||
elements.customCount.textContent = (data.custom_count || 0) + (data.temp_mail_count || 0) + (data.duck_mail_count || 0) + (data.freemail_count || 0) + (data.imap_mail_count || 0);
|
||||
elements.customCount.textContent = (data.custom_count || 0) + (data.temp_mail_count || 0) + (data.duck_mail_count || 0) + (data.freemail_count || 0) + (data.cloud_mail_count || 0) + (data.imap_mail_count || 0);
|
||||
elements.tempmailStatus.textContent = data.tempmail_available ? '可用' : '不可用';
|
||||
elements.totalEnabled.textContent = data.enabled_count || 0;
|
||||
} catch (error) {
|
||||
@@ -289,6 +294,9 @@ function getCustomServiceTypeBadge(subType) {
|
||||
if (subType === 'freemail') {
|
||||
return '<span class="status-badge" style="background-color:#9c27b0;color:white;">Freemail</span>';
|
||||
}
|
||||
if (subType === 'cloudmail') {
|
||||
return '<span class="status-badge" style="background-color:#1976d2;color:white;">Cloud Mail</span>';
|
||||
}
|
||||
return '<span class="status-badge" style="background-color:#0288d1;color:white;">IMAP</span>';
|
||||
}
|
||||
|
||||
@@ -306,14 +314,15 @@ function getCustomServiceAddress(service) {
|
||||
return `${escapeHtml(baseUrl)}<div style="color: var(--text-muted); margin-top: 4px;">默认域名:@${escapeHtml(domain)}</div>`;
|
||||
}
|
||||
|
||||
// 加载自定义邮箱服务(moe_mail + temp_mail + duck_mail + freemail 合并)
|
||||
// 加载自定义邮箱服务(moe_mail + temp_mail + duck_mail + freemail + cloud_mail 合并)
|
||||
async function loadCustomServices() {
|
||||
try {
|
||||
const [r1, r2, r3, r4, r5] = await Promise.all([
|
||||
const [r1, r2, r3, r4, r5, r6] = await Promise.all([
|
||||
api.get('/email-services?service_type=moe_mail'),
|
||||
api.get('/email-services?service_type=temp_mail'),
|
||||
api.get('/email-services?service_type=duck_mail'),
|
||||
api.get('/email-services?service_type=freemail'),
|
||||
api.get('/email-services?service_type=cloud_mail'),
|
||||
api.get('/email-services?service_type=imap_mail')
|
||||
]);
|
||||
customServices = [
|
||||
@@ -321,7 +330,8 @@ async function loadCustomServices() {
|
||||
...(r2.services || []).map(s => ({ ...s, _subType: 'tempmail' })),
|
||||
...(r3.services || []).map(s => ({ ...s, _subType: 'duckmail' })),
|
||||
...(r4.services || []).map(s => ({ ...s, _subType: 'freemail' })),
|
||||
...(r5.services || []).map(s => ({ ...s, _subType: 'imap' }))
|
||||
...(r5.services || []).map(s => ({ ...s, _subType: 'cloudmail' })),
|
||||
...(r6.services || []).map(s => ({ ...s, _subType: 'imap' }))
|
||||
];
|
||||
|
||||
if (customServices.length === 0) {
|
||||
@@ -466,6 +476,14 @@ async function handleAddCustom(e) {
|
||||
admin_token: formData.get('fm_admin_token'),
|
||||
domain: formData.get('fm_domain')
|
||||
};
|
||||
} else if (subType === 'cloudmail') {
|
||||
serviceType = 'cloud_mail';
|
||||
config = {
|
||||
base_url: formData.get('cm_base_url'),
|
||||
admin_email: formData.get('cm_admin_email'),
|
||||
admin_password: formData.get('cm_admin_password'),
|
||||
default_domain: formData.get('cm_domain')
|
||||
};
|
||||
} else {
|
||||
serviceType = 'imap_mail';
|
||||
config = {
|
||||
@@ -617,6 +635,8 @@ async function editCustomService(id, subType) {
|
||||
? 'duckmail'
|
||||
: service.service_type === 'freemail'
|
||||
? 'freemail'
|
||||
: service.service_type === 'cloud_mail'
|
||||
? 'cloudmail'
|
||||
: service.service_type === 'imap_mail'
|
||||
? 'imap'
|
||||
: 'moemail'
|
||||
@@ -650,6 +670,12 @@ async function editCustomService(id, subType) {
|
||||
document.getElementById('edit-fm-admin-token').value = '';
|
||||
document.getElementById('edit-fm-admin-token').placeholder = service.config?.admin_token ? '已设置,留空保持不变' : '请输入 Admin Token';
|
||||
document.getElementById('edit-fm-domain').value = service.config?.domain || '';
|
||||
} else if (resolvedSubType === 'cloudmail') {
|
||||
document.getElementById('edit-cm-base-url').value = service.config?.base_url || '';
|
||||
document.getElementById('edit-cm-admin-email').value = service.config?.admin_email || '';
|
||||
document.getElementById('edit-cm-admin-password').value = '';
|
||||
document.getElementById('edit-cm-admin-password').placeholder = service.config?.admin_password ? '已设置,留空保持不变' : '请输入管理员密码';
|
||||
document.getElementById('edit-cm-domain').value = service.config?.default_domain || '';
|
||||
} else {
|
||||
document.getElementById('edit-imap-host').value = service.config?.host || '';
|
||||
document.getElementById('edit-imap-port').value = service.config?.port || 993;
|
||||
@@ -703,6 +729,14 @@ async function handleEditCustom(e) {
|
||||
};
|
||||
const token = formData.get('fm_admin_token');
|
||||
if (token && token.trim()) config.admin_token = token.trim();
|
||||
} else if (subType === 'cloudmail') {
|
||||
config = {
|
||||
base_url: formData.get('cm_base_url'),
|
||||
admin_email: formData.get('cm_admin_email'),
|
||||
default_domain: formData.get('cm_domain')
|
||||
};
|
||||
const pwd = formData.get('cm_admin_password');
|
||||
if (pwd && pwd.trim()) config.admin_password = pwd.trim();
|
||||
} else {
|
||||
config = {
|
||||
host: formData.get('imap_host'),
|
||||
|
||||
@@ -372,7 +372,8 @@ const statusMap = {
|
||||
temp_mail: 'Temp-Mail(自部署)',
|
||||
duck_mail: 'DuckMail',
|
||||
freemail: 'Freemail',
|
||||
imap_mail: 'IMAP 邮箱'
|
||||
imap_mail: 'IMAP 邮箱',
|
||||
cloud_mail: 'Cloud Mail'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user