mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 03:10:50 +08:00
fix(app.js):尝试修复codex配置异常丢失数据的问题
This commit is contained in:
48
app.js
48
app.js
@@ -2315,6 +2315,30 @@ class CLIProxyManager {
|
|||||||
.replace(/'/g, ''');
|
.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密钥模态框
|
// 显示添加API密钥模态框
|
||||||
showAddApiKeyModal() {
|
showAddApiKeyModal() {
|
||||||
const modal = document.getElementById('modal');
|
const modal = document.getElementById('modal');
|
||||||
@@ -2695,15 +2719,9 @@ class CLIProxyManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await this.makeRequest('/codex-api-key');
|
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 };
|
const newConfig = this.buildCodexConfig(apiKey, baseUrl, proxyUrl);
|
||||||
if (baseUrl) {
|
|
||||||
newConfig['base-url'] = baseUrl;
|
|
||||||
}
|
|
||||||
if (proxyUrl) {
|
|
||||||
newConfig['proxy-url'] = proxyUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentKeys.push(newConfig);
|
currentKeys.push(newConfig);
|
||||||
|
|
||||||
@@ -2761,14 +2779,16 @@ class CLIProxyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newConfig = { 'api-key': apiKey };
|
const listResponse = await this.makeRequest('/codex-api-key');
|
||||||
if (baseUrl) {
|
const currentList = this.normalizeArrayResponse(listResponse, 'codex-api-key');
|
||||||
newConfig['base-url'] = baseUrl;
|
|
||||||
}
|
if (!Array.isArray(currentList) || index < 0 || index >= currentList.length) {
|
||||||
if (proxyUrl) {
|
throw new Error('Invalid codex configuration index');
|
||||||
newConfig['proxy-url'] = proxyUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const original = currentList[index] ? { ...currentList[index] } : {};
|
||||||
|
const newConfig = this.buildCodexConfig(apiKey, baseUrl, proxyUrl, original);
|
||||||
|
|
||||||
await this.makeRequest('/codex-api-key', {
|
await this.makeRequest('/codex-api-key', {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify({ index, value: newConfig })
|
body: JSON.stringify({ index, value: newConfig })
|
||||||
|
|||||||
Reference in New Issue
Block a user