mirror of
https://github.com/cnlimiter/codex-register.git
synced 2026-07-07 23:31:46 +08:00
refactor(core): 统一自定义域名服务配置字段名
- 将自定义域名服务配置中的 `api_url` 字段重命名为 `base_url` - 将 `domain` 字段重命名为 `default_domain` - 更新相关的前端表单、后端API及数据库查询逻辑以保持兼容性 - 在注册任务处理中自动处理新旧字段名的转换
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -54,3 +54,4 @@ Thumbs.db
|
|||||||
|
|
||||||
# Project specific
|
# Project specific
|
||||||
backups/
|
backups/
|
||||||
|
/out/
|
||||||
|
|||||||
@@ -225,6 +225,11 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
|
|||||||
|
|
||||||
if db_service:
|
if db_service:
|
||||||
config = db_service.config.copy() if db_service.config else {}
|
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)
|
crud.update_registration_task(db, task_uuid, email_service_id=db_service.id)
|
||||||
logger.info(f"使用数据库邮箱服务: {db_service.name} (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:
|
if db_service and db_service.config:
|
||||||
config = db_service.config.copy()
|
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)
|
crud.update_registration_task(db, task_uuid, email_service_id=db_service.id)
|
||||||
logger.info(f"使用数据库自定义域名服务: {db_service.name}")
|
logger.info(f"使用数据库自定义域名服务: {db_service.name}")
|
||||||
elif settings.custom_domain_base_url and settings.custom_domain_api_key:
|
elif settings.custom_domain_base_url and settings.custom_domain_api_key:
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ async function loadCustomServices() {
|
|||||||
${selectedCustom.has(service.id) ? 'checked' : ''}>
|
${selectedCustom.has(service.id) ? 'checked' : ''}>
|
||||||
</td>
|
</td>
|
||||||
<td>${escapeHtml(service.name)}</td>
|
<td>${escapeHtml(service.name)}</td>
|
||||||
<td style="font-size: 0.75rem;">${escapeHtml(service.config?.api_url || '-')}</td>
|
<td style="font-size: 0.75rem;">${escapeHtml(service.config?.base_url || '-')}</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="status-badge ${service.enabled ? 'active' : 'disabled'}">
|
<span class="status-badge ${service.enabled ? 'active' : 'disabled'}">
|
||||||
${service.enabled ? '启用' : '禁用'}
|
${service.enabled ? '启用' : '禁用'}
|
||||||
@@ -403,9 +403,9 @@ async function handleAddCustom(e) {
|
|||||||
service_type: 'custom_domain',
|
service_type: 'custom_domain',
|
||||||
name: formData.get('name'),
|
name: formData.get('name'),
|
||||||
config: {
|
config: {
|
||||||
api_url: formData.get('api_url'),
|
base_url: formData.get('api_url'),
|
||||||
api_key: formData.get('api_key'),
|
api_key: formData.get('api_key'),
|
||||||
domain: formData.get('domain')
|
default_domain: formData.get('domain')
|
||||||
},
|
},
|
||||||
enabled: formData.get('enabled') === 'on',
|
enabled: formData.get('enabled') === 'on',
|
||||||
priority: parseInt(formData.get('priority')) || 0
|
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-id').value = service.id;
|
||||||
document.getElementById('edit-custom-name').value = service.name || '';
|
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-api-key').value = service.config?.api_key || '';
|
||||||
document.getElementById('edit-custom-domain').value = service.config?.domain || '';
|
document.getElementById('edit-custom-domain').value = service.config?.domain || '';
|
||||||
document.getElementById('edit-custom-priority').value = service.priority || 0;
|
document.getElementById('edit-custom-priority').value = service.priority || 0;
|
||||||
document.getElementById('edit-custom-enabled').checked = service.enabled;
|
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');
|
elements.editCustomModal.classList.add('active');
|
||||||
@@ -586,8 +586,8 @@ async function handleEditCustom(e) {
|
|||||||
|
|
||||||
// 构建配置
|
// 构建配置
|
||||||
const config = {
|
const config = {
|
||||||
api_url: formData.get('api_url'),
|
base_url: formData.get('api_url'),
|
||||||
domain: formData.get('domain')
|
default_domain: formData.get('domain')
|
||||||
};
|
};
|
||||||
|
|
||||||
// 只有在填写了 API Key 时才更新
|
// 只有在填写了 API Key 时才更新
|
||||||
|
|||||||
@@ -225,6 +225,10 @@ class ApiClient {
|
|||||||
return this.request(path, { ...options, method: 'PUT', body });
|
return this.request(path, { ...options, method: 'PUT', body });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patch(path, body, options = {}) {
|
||||||
|
return this.request(path, { ...options, method: 'PATCH', body });
|
||||||
|
}
|
||||||
|
|
||||||
delete(path, options = {}) {
|
delete(path, options = {}) {
|
||||||
return this.request(path, { ...options, method: 'DELETE' });
|
return this.request(path, { ...options, method: 'DELETE' });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user