diff --git a/app.js b/app.js index 9abb8e6..23fe115 100644 --- a/app.js +++ b/app.js @@ -515,6 +515,8 @@ class CLIProxyManager { const switchProjectToggle = document.getElementById('switch-project-toggle'); const switchPreviewToggle = document.getElementById('switch-preview-model-toggle'); const usageStatisticsToggle = document.getElementById('usage-statistics-enabled-toggle'); + const requestLogToggle = document.getElementById('request-log-toggle'); + const wsAuthToggle = document.getElementById('ws-auth-toggle'); if (debugToggle) { debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked)); @@ -537,6 +539,12 @@ class CLIProxyManager { if (usageStatisticsToggle) { usageStatisticsToggle.addEventListener('change', (e) => this.updateUsageStatisticsEnabled(e.target.checked)); } + if (requestLogToggle) { + requestLogToggle.addEventListener('change', (e) => this.updateRequestLog(e.target.checked)); + } + if (wsAuthToggle) { + wsAuthToggle.addEventListener('change', (e) => this.updateWsAuth(e.target.checked)); + } // 日志记录设置 const loggingToFileToggle = document.getElementById('logging-to-file-toggle'); @@ -1540,6 +1548,18 @@ class CLIProxyManager { // 显示或隐藏日志查看栏目 this.toggleLogsNavItem(config['logging-to-file']); } + if (config['request-log'] !== undefined) { + const requestLogToggle = document.getElementById('request-log-toggle'); + if (requestLogToggle) { + requestLogToggle.checked = config['request-log']; + } + } + if (config['ws-auth'] !== undefined) { + const wsAuthToggle = document.getElementById('ws-auth-toggle'); + if (wsAuthToggle) { + wsAuthToggle.checked = config['ws-auth']; + } + } // API 密钥 if (config['api-keys']) { @@ -1567,6 +1587,8 @@ class CLIProxyManager { this.loadRetrySettings(), this.loadQuotaSettings(), this.loadUsageStatisticsSettings(), + this.loadRequestLogSetting(), + this.loadWsAuthSetting(), this.loadApiKeys(), this.loadGeminiKeys(), this.loadCodexKeys(), @@ -1707,6 +1729,36 @@ class CLIProxyManager { } } + // 加载请求日志设置 + async loadRequestLogSetting() { + try { + const config = await this.getConfig(); + if (config['request-log'] !== undefined) { + const requestLogToggle = document.getElementById('request-log-toggle'); + if (requestLogToggle) { + requestLogToggle.checked = config['request-log']; + } + } + } catch (error) { + console.error('加载请求日志设置失败:', error); + } + } + + // 加载 WebSocket 鉴权设置 + async loadWsAuthSetting() { + try { + const config = await this.getConfig(); + if (config['ws-auth'] !== undefined) { + const wsAuthToggle = document.getElementById('ws-auth-toggle'); + if (wsAuthToggle) { + wsAuthToggle.checked = config['ws-auth']; + } + } + } catch (error) { + console.error('加载 WebSocket 鉴权设置失败:', error); + } + } + // 更新使用统计设置 async updateUsageStatisticsEnabled(enabled) { try { @@ -1725,6 +1777,42 @@ class CLIProxyManager { } } + // 更新请求日志设置 + async updateRequestLog(enabled) { + try { + await this.makeRequest('/request-log', { + method: 'PUT', + body: JSON.stringify({ value: enabled }) + }); + this.clearCache(); + this.showNotification(i18n.t('notification.request_log_updated'), 'success'); + } catch (error) { + this.showNotification(`${i18n.t('notification.update_failed')}: ${error.message}`, 'error'); + const requestLogToggle = document.getElementById('request-log-toggle'); + if (requestLogToggle) { + requestLogToggle.checked = !enabled; + } + } + } + + // 更新 WebSocket 鉴权设置 + async updateWsAuth(enabled) { + try { + await this.makeRequest('/ws-auth', { + method: 'PUT', + body: JSON.stringify({ value: enabled }) + }); + this.clearCache(); + this.showNotification(i18n.t('notification.ws_auth_updated'), 'success'); + } catch (error) { + this.showNotification(`${i18n.t('notification.update_failed')}: ${error.message}`, 'error'); + const wsAuthToggle = document.getElementById('ws-auth-toggle'); + if (wsAuthToggle) { + wsAuthToggle.checked = !enabled; + } + } + } + // 更新日志记录到文件设置 async updateLoggingToFile(enabled) { try { diff --git a/i18n.js b/i18n.js index ae07fc2..5560a15 100644 --- a/i18n.js +++ b/i18n.js @@ -113,6 +113,9 @@ const i18n = { 'basic_settings.usage_statistics_enable': '启用使用统计', 'basic_settings.logging_title': '日志记录', 'basic_settings.logging_to_file_enable': '启用日志记录到文件', + 'basic_settings.request_log_enable': '启用请求日志', + 'basic_settings.ws_auth_title': 'WebSocket 鉴权', + 'basic_settings.ws_auth_enable': '启用 /ws/* 鉴权', // API 密钥管理 'api_keys.title': 'API 密钥管理', @@ -407,6 +410,8 @@ const i18n = { 'notification.quota_switch_preview_updated': '预览模型切换设置已更新', 'notification.usage_statistics_updated': '使用统计设置已更新', 'notification.logging_to_file_updated': '日志记录设置已更新', + 'notification.request_log_updated': '请求日志设置已更新', + 'notification.ws_auth_updated': 'WebSocket 鉴权设置已更新', 'notification.api_key_added': 'API密钥添加成功', 'notification.api_key_updated': 'API密钥更新成功', 'notification.api_key_deleted': 'API密钥删除成功', @@ -576,6 +581,9 @@ const i18n = { 'basic_settings.usage_statistics_enable': 'Enable usage statistics', 'basic_settings.logging_title': 'Logging', 'basic_settings.logging_to_file_enable': 'Enable logging to file', + 'basic_settings.request_log_enable': 'Enable request logging', + 'basic_settings.ws_auth_title': 'WebSocket Authentication', + 'basic_settings.ws_auth_enable': 'Require auth for /ws/*', // API Keys management 'api_keys.title': 'API Keys Management', @@ -869,6 +877,8 @@ const i18n = { 'notification.quota_switch_preview_updated': 'Preview model switch settings updated', 'notification.usage_statistics_updated': 'Usage statistics settings updated', 'notification.logging_to_file_updated': 'Logging settings updated', + 'notification.request_log_updated': 'Request logging setting updated', + 'notification.ws_auth_updated': 'WebSocket authentication setting updated', 'notification.api_key_added': 'API key added successfully', 'notification.api_key_updated': 'API key updated successfully', 'notification.api_key_deleted': 'API key deleted successfully', diff --git a/index.html b/index.html index 11b5750..56efae9 100644 --- a/index.html +++ b/index.html @@ -316,6 +316,32 @@ 启用日志记录到文件 +