From e2ef325ebac14c6c3e66e7da1dcd5b6054767128 Mon Sep 17 00:00:00 2001 From: cnlimiter Date: Mon, 16 Mar 2026 01:04:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E7=BB=9F=E4=B8=80=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=9F=9F=E5=90=8D=E6=9C=8D=E5=8A=A1=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=AD=97=E6=AE=B5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将自定义域名服务配置中的 `api_url` 字段重命名为 `base_url` - 将 `domain` 字段重命名为 `default_domain` - 更新相关的前端表单、后端API及数据库查询逻辑以保持兼容性 - 在注册任务处理中自动处理新旧字段名的转换 --- .gitignore | 1 + src/web/routes/registration.py | 10 ++++++++++ static/js/email_services.js | 14 +++++++------- static/js/utils.js | 4 ++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index e58d61a..267cd1d 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ Thumbs.db # Project specific backups/ +/out/ diff --git a/src/web/routes/registration.py b/src/web/routes/registration.py index 41c006e..5ba459e 100644 --- a/src/web/routes/registration.py +++ b/src/web/routes/registration.py @@ -225,6 +225,11 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy: if db_service: config = db_service.config.copy() if db_service.config else {} + # 兼容旧版字段名 api_url -> base_url + if 'api_url' in config and 'base_url' not in config: + config['base_url'] = config.pop('api_url') + if 'domain' in config and 'default_domain' not in config: + config['default_domain'] = config.pop('domain') # 更新任务关联的邮箱服务 crud.update_registration_task(db, task_uuid, email_service_id=db_service.id) logger.info(f"使用数据库邮箱服务: {db_service.name} (ID: {db_service.id})") @@ -249,6 +254,11 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy: if db_service and db_service.config: config = db_service.config.copy() + # 兼容旧版字段名 api_url -> base_url + if 'api_url' in config and 'base_url' not in config: + config['base_url'] = config.pop('api_url') + if 'domain' in config and 'default_domain' not in config: + config['default_domain'] = config.pop('domain') crud.update_registration_task(db, task_uuid, email_service_id=db_service.id) logger.info(f"使用数据库自定义域名服务: {db_service.name}") elif settings.custom_domain_base_url and settings.custom_domain_api_key: diff --git a/static/js/email_services.js b/static/js/email_services.js index b48e6eb..4ffd2dc 100644 --- a/static/js/email_services.js +++ b/static/js/email_services.js @@ -288,7 +288,7 @@ async function loadCustomServices() { ${selectedCustom.has(service.id) ? 'checked' : ''}> ${escapeHtml(service.name)} - ${escapeHtml(service.config?.api_url || '-')} + ${escapeHtml(service.config?.base_url || '-')} ${service.enabled ? '启用' : '禁用'} @@ -403,9 +403,9 @@ async function handleAddCustom(e) { service_type: 'custom_domain', name: formData.get('name'), config: { - api_url: formData.get('api_url'), + base_url: formData.get('api_url'), api_key: formData.get('api_key'), - domain: formData.get('domain') + default_domain: formData.get('domain') }, enabled: formData.get('enabled') === 'on', priority: parseInt(formData.get('priority')) || 0 @@ -553,14 +553,14 @@ async function editCustomService(id) { // 填充表单 document.getElementById('edit-custom-id').value = service.id; document.getElementById('edit-custom-name').value = service.name || ''; - document.getElementById('edit-custom-api-url').value = service.config?.api_url || ''; + document.getElementById('edit-custom-api-url').value = service.config?.base_url || ''; document.getElementById('edit-custom-api-key').value = service.config?.api_key || ''; document.getElementById('edit-custom-domain').value = service.config?.domain || ''; document.getElementById('edit-custom-priority').value = service.priority || 0; document.getElementById('edit-custom-enabled').checked = service.enabled; // 清空密码提示 - document.getElementById('edit-custom-api-key').placeholder = service.config?.api_key ? '已设置,留空保持不变' : 'API Key'; + document.getElementById('edit-custom-api-key').placeholder = service.config?.has_api_key ? '已设置,留空保持不变' : 'API Key'; // 显示模态框 elements.editCustomModal.classList.add('active'); @@ -586,8 +586,8 @@ async function handleEditCustom(e) { // 构建配置 const config = { - api_url: formData.get('api_url'), - domain: formData.get('domain') + base_url: formData.get('api_url'), + default_domain: formData.get('domain') }; // 只有在填写了 API Key 时才更新 diff --git a/static/js/utils.js b/static/js/utils.js index 4a1e14b..43c39ea 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -225,6 +225,10 @@ class ApiClient { return this.request(path, { ...options, method: 'PUT', body }); } + patch(path, body, options = {}) { + return this.request(path, { ...options, method: 'PATCH', body }); + } + delete(path, options = {}) { return this.request(path, { ...options, method: 'DELETE' }); }