From 8283e999095ae8f0d6e41902a292107765c035aa Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Wed, 5 Nov 2025 18:06:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(app.js):=E5=B0=9D=E8=AF=95=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dcodex=E9=85=8D=E7=BD=AE=E5=BC=82=E5=B8=B8=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E6=95=B0=E6=8D=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/app.js b/app.js index 49c6802..80e4beb 100644 --- a/app.js +++ b/app.js @@ -2315,6 +2315,30 @@ class CLIProxyManager { .replace(/'/g, '''); } + // 兼容服务端返回的数组结构 + normalizeArrayResponse(data, key) { + if (Array.isArray(data)) { + return data; + } + if (data && Array.isArray(data[key])) { + return data[key]; + } + if (data && Array.isArray(data.items)) { + return data.items; + } + return []; + } + + // 构造Codex配置,保持未展示的字段 + buildCodexConfig(apiKey, baseUrl, proxyUrl, original = {}) { + return { + ...original, + 'api-key': apiKey, + 'base-url': baseUrl || '', + 'proxy-url': proxyUrl || '' + }; + } + // 显示添加API密钥模态框 showAddApiKeyModal() { const modal = document.getElementById('modal'); @@ -2695,15 +2719,9 @@ class CLIProxyManager { try { const data = await this.makeRequest('/codex-api-key'); - const currentKeys = data['codex-api-key'] || []; + const currentKeys = this.normalizeArrayResponse(data, 'codex-api-key').map(item => ({ ...item })); - const newConfig = { 'api-key': apiKey }; - if (baseUrl) { - newConfig['base-url'] = baseUrl; - } - if (proxyUrl) { - newConfig['proxy-url'] = proxyUrl; - } + const newConfig = this.buildCodexConfig(apiKey, baseUrl, proxyUrl); currentKeys.push(newConfig); @@ -2761,14 +2779,16 @@ class CLIProxyManager { } try { - const newConfig = { 'api-key': apiKey }; - if (baseUrl) { - newConfig['base-url'] = baseUrl; - } - if (proxyUrl) { - newConfig['proxy-url'] = proxyUrl; + const listResponse = await this.makeRequest('/codex-api-key'); + const currentList = this.normalizeArrayResponse(listResponse, 'codex-api-key'); + + if (!Array.isArray(currentList) || index < 0 || index >= currentList.length) { + throw new Error('Invalid codex configuration index'); } + const original = currentList[index] ? { ...currentList[index] } : {}; + const newConfig = this.buildCodexConfig(apiKey, baseUrl, proxyUrl, original); + await this.makeRequest('/codex-api-key', { method: 'PATCH', body: JSON.stringify({ index, value: newConfig })