From 1e79f918e20620cdf2b8c085ed51f2fe09a1df48 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:24:43 +0800 Subject: [PATCH] fix(ui): harden key list rendering and config handling --- app.js | 70 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/app.js b/app.js index dcdc186..41a9afd 100644 --- a/app.js +++ b/app.js @@ -1498,24 +1498,16 @@ class CLIProxyManager { } // Gemini 密钥 - if (config['generative-language-api-key']) { - await this.renderGeminiKeys(config['generative-language-api-key']); - } + await this.renderGeminiKeys(Array.isArray(config['generative-language-api-key']) ? config['generative-language-api-key'] : []); // Codex 密钥 - if (config['codex-api-key']) { - await this.renderCodexKeys(config['codex-api-key']); - } + await this.renderCodexKeys(Array.isArray(config['codex-api-key']) ? config['codex-api-key'] : []); // Claude 密钥 - if (config['claude-api-key']) { - await this.renderClaudeKeys(config['claude-api-key']); - } + await this.renderClaudeKeys(Array.isArray(config['claude-api-key']) ? config['claude-api-key'] : []); // OpenAI 兼容提供商 - if (config['openai-compatibility']) { - await this.renderOpenAIProviders(config['openai-compatibility']); - } + await this.renderOpenAIProviders(Array.isArray(config['openai-compatibility']) ? config['openai-compatibility'] : []); } // 回退方法:原来的逐个加载方式 @@ -2179,9 +2171,8 @@ class CLIProxyManager { async loadGeminiKeys() { try { const config = await this.getConfig(); - if (config['generative-language-api-key']) { - await this.renderGeminiKeys(config['generative-language-api-key']); - } + const keys = Array.isArray(config['generative-language-api-key']) ? config['generative-language-api-key'] : []; + await this.renderGeminiKeys(keys); } catch (error) { console.error('加载Gemini密钥失败:', error); } @@ -2190,8 +2181,12 @@ class CLIProxyManager { // 渲染Gemini密钥列表 async renderGeminiKeys(keys) { const container = document.getElementById('gemini-keys-list'); + if (!container) { + return; + } + const list = Array.isArray(keys) ? keys : []; - if (keys.length === 0) { + if (list.length === 0) { container.innerHTML = `