diff --git a/app.js b/app.js index 6a6c246..59ae52a 100644 --- a/app.js +++ b/app.js @@ -2753,7 +2753,7 @@ class CLIProxyManager { async renderOpenAIProviders(providers) { const container = document.getElementById('openai-providers-list'); - if (providers.length === 0) { + if (!Array.isArray(providers) || providers.length === 0) { container.innerHTML = `
@@ -2768,12 +2768,19 @@ class CLIProxyManager { const stats = await this.getKeyStats(); container.innerHTML = providers.map((provider, index) => { - const apiKeyEntries = provider['api-key-entries'] || []; + const item = typeof provider === 'object' && provider !== null ? provider : {}; + const apiKeyEntries = Array.isArray(item['api-key-entries']) ? item['api-key-entries'] : []; + const models = Array.isArray(item.models) ? item.models : []; + const name = item.name || ''; + const baseUrl = item['base-url'] || ''; + let totalSuccess = 0; let totalFailure = 0; apiKeyEntries.forEach(entry => { - const keyStats = stats[entry['api-key']] || { success: 0, failure: 0 }; + const key = entry && entry['api-key'] ? entry['api-key'] : ''; + if (!key) return; + const keyStats = stats[key] || { success: 0, failure: 0 }; totalSuccess += keyStats.success; totalFailure += keyStats.failure; }); @@ -2781,11 +2788,11 @@ class CLIProxyManager { return `
-
${this.escapeHtml(provider.name)}
-
${i18n.t('common.base_url')}: ${this.escapeHtml(provider['base-url'])}
-
${i18n.t('ai_providers.openai_keys_count')}: ${(provider['api-key-entries'] || []).length}
-
${i18n.t('ai_providers.openai_models_count')}: ${(provider.models || []).length}
- ${this.renderOpenAIModelBadges(provider.models || [])} +
${this.escapeHtml(name)}
+
${i18n.t('common.base_url')}: ${this.escapeHtml(baseUrl)}
+
${i18n.t('ai_providers.openai_keys_count')}: ${apiKeyEntries.length}
+
${i18n.t('ai_providers.openai_models_count')}: ${models.length}
+ ${this.renderOpenAIModelBadges(models)}
成功: ${totalSuccess} @@ -2796,15 +2803,15 @@ class CLIProxyManager {
- -
- `}).join(''); + `;}).join(''); } // 显示添加OpenAI提供商模态框 @@ -2897,27 +2904,28 @@ class CLIProxyManager { const modal = document.getElementById('modal'); const modalBody = document.getElementById('modal-body'); - const apiKeyEntries = provider['api-key-entries'] || []; - const apiKeysText = apiKeyEntries.map(entry => entry['api-key'] || '').join('\n'); - const proxiesText = apiKeyEntries.map(entry => entry['proxy-url'] || '').join('\n'); + const apiKeyEntries = Array.isArray(provider?.['api-key-entries']) ? provider['api-key-entries'] : []; + const apiKeysText = apiKeyEntries.map(entry => entry?.['api-key'] || '').join('\n'); + const proxiesText = apiKeyEntries.map(entry => entry?.['proxy-url'] || '').join('\n'); + const models = Array.isArray(provider?.models) ? provider.models : []; modalBody.innerHTML = `

${i18n.t('ai_providers.openai_edit_modal_title')}

- +
- +
- +
- +
@@ -2932,7 +2940,7 @@ class CLIProxyManager { `; modal.style.display = 'block'; - this.populateModelFields('edit-provider-models-wrapper', provider.models || []); + this.populateModelFields('edit-provider-models-wrapper', models); } // 更新OpenAI提供商