feat(app.js, i18n, index.html): add request logging and WebSocket authentication settings

- Introduced toggles for enabling request logging and WebSocket authentication in the UI.
- Implemented methods to load and update the respective settings in the CLIProxyManager.
- Updated internationalization strings to support new features in both English and Chinese.
This commit is contained in:
Supra4E8C
2025-11-11 12:32:56 +08:00
parent 1d7408cb25
commit 6f1c7b168d
3 changed files with 124 additions and 0 deletions

88
app.js
View File

@@ -515,6 +515,8 @@ class CLIProxyManager {
const switchProjectToggle = document.getElementById('switch-project-toggle'); const switchProjectToggle = document.getElementById('switch-project-toggle');
const switchPreviewToggle = document.getElementById('switch-preview-model-toggle'); const switchPreviewToggle = document.getElementById('switch-preview-model-toggle');
const usageStatisticsToggle = document.getElementById('usage-statistics-enabled-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) { if (debugToggle) {
debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked)); debugToggle.addEventListener('change', (e) => this.updateDebug(e.target.checked));
@@ -537,6 +539,12 @@ class CLIProxyManager {
if (usageStatisticsToggle) { if (usageStatisticsToggle) {
usageStatisticsToggle.addEventListener('change', (e) => this.updateUsageStatisticsEnabled(e.target.checked)); 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'); const loggingToFileToggle = document.getElementById('logging-to-file-toggle');
@@ -1540,6 +1548,18 @@ class CLIProxyManager {
// 显示或隐藏日志查看栏目 // 显示或隐藏日志查看栏目
this.toggleLogsNavItem(config['logging-to-file']); 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 密钥 // API 密钥
if (config['api-keys']) { if (config['api-keys']) {
@@ -1567,6 +1587,8 @@ class CLIProxyManager {
this.loadRetrySettings(), this.loadRetrySettings(),
this.loadQuotaSettings(), this.loadQuotaSettings(),
this.loadUsageStatisticsSettings(), this.loadUsageStatisticsSettings(),
this.loadRequestLogSetting(),
this.loadWsAuthSetting(),
this.loadApiKeys(), this.loadApiKeys(),
this.loadGeminiKeys(), this.loadGeminiKeys(),
this.loadCodexKeys(), 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) { async updateUsageStatisticsEnabled(enabled) {
try { 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) { async updateLoggingToFile(enabled) {
try { try {

10
i18n.js
View File

@@ -113,6 +113,9 @@ const i18n = {
'basic_settings.usage_statistics_enable': '启用使用统计', 'basic_settings.usage_statistics_enable': '启用使用统计',
'basic_settings.logging_title': '日志记录', 'basic_settings.logging_title': '日志记录',
'basic_settings.logging_to_file_enable': '启用日志记录到文件', '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 密钥管理
'api_keys.title': 'API 密钥管理', 'api_keys.title': 'API 密钥管理',
@@ -407,6 +410,8 @@ const i18n = {
'notification.quota_switch_preview_updated': '预览模型切换设置已更新', 'notification.quota_switch_preview_updated': '预览模型切换设置已更新',
'notification.usage_statistics_updated': '使用统计设置已更新', 'notification.usage_statistics_updated': '使用统计设置已更新',
'notification.logging_to_file_updated': '日志记录设置已更新', 'notification.logging_to_file_updated': '日志记录设置已更新',
'notification.request_log_updated': '请求日志设置已更新',
'notification.ws_auth_updated': 'WebSocket 鉴权设置已更新',
'notification.api_key_added': 'API密钥添加成功', 'notification.api_key_added': 'API密钥添加成功',
'notification.api_key_updated': 'API密钥更新成功', 'notification.api_key_updated': 'API密钥更新成功',
'notification.api_key_deleted': 'API密钥删除成功', 'notification.api_key_deleted': 'API密钥删除成功',
@@ -576,6 +581,9 @@ const i18n = {
'basic_settings.usage_statistics_enable': 'Enable usage statistics', 'basic_settings.usage_statistics_enable': 'Enable usage statistics',
'basic_settings.logging_title': 'Logging', 'basic_settings.logging_title': 'Logging',
'basic_settings.logging_to_file_enable': 'Enable logging to file', '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 management
'api_keys.title': '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.quota_switch_preview_updated': 'Preview model switch settings updated',
'notification.usage_statistics_updated': 'Usage statistics settings updated', 'notification.usage_statistics_updated': 'Usage statistics settings updated',
'notification.logging_to_file_updated': 'Logging 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_added': 'API key added successfully',
'notification.api_key_updated': 'API key updated successfully', 'notification.api_key_updated': 'API key updated successfully',
'notification.api_key_deleted': 'API key deleted successfully', 'notification.api_key_deleted': 'API key deleted successfully',

View File

@@ -316,6 +316,32 @@
<span class="toggle-label" <span class="toggle-label"
data-i18n="basic_settings.logging_to_file_enable">启用日志记录到文件</span> data-i18n="basic_settings.logging_to_file_enable">启用日志记录到文件</span>
</div> </div>
<div class="toggle-group">
<label class="toggle-switch">
<input type="checkbox" id="request-log-toggle">
<span class="slider"></span>
</label>
<span class="toggle-label"
data-i18n="basic_settings.request_log_enable">启用请求日志</span>
</div>
</div>
</div>
<!-- WebSocket 鉴权 -->
<div class="card">
<div class="card-header">
<h3><i class="fas fa-shield-alt"></i> <span
data-i18n="basic_settings.ws_auth_title">WebSocket 鉴权</span></h3>
</div>
<div class="card-content">
<div class="toggle-group">
<label class="toggle-switch">
<input type="checkbox" id="ws-auth-toggle">
<span class="slider"></span>
</label>
<span class="toggle-label"
data-i18n="basic_settings.ws_auth_enable">启用 /ws/* 鉴权</span>
</div>
</div> </div>
</div> </div>