Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/frontend/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default {
switchFailed: 'Switch Failed',
reorderFailed: 'Reorder Failed',
collapse: 'Collapse',
expand: 'Expand'
expand: 'Expand',
testTipSuccess: 'Connection test passed',
testTipFailed: 'Connection test failed or endpoint does not support API testing',
testTipUnknown: 'Not tested or test result unknown'
},
modal: {
addEndpoint: 'Add Endpoint',
Expand Down
5 changes: 4 additions & 1 deletion app/frontend/src/i18n/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default {
switchFailed: '切换失败',
reorderFailed: '排序失败',
collapse: '收起',
expand: '展开'
expand: '展开',
testTipSuccess: '已测试连接成功',
testTipFailed: '测试连接失败或当前端点不支持接口测试',
testTipUnknown: '未测试或测试结果未知'
},
modal: {
addEndpoint: '添加端点',
Expand Down
69 changes: 9 additions & 60 deletions app/frontend/src/modules/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getEndpointStats } from './stats.js';
import { toggleEndpoint, testAllEndpointsZeroCost } from './config.js';

const ENDPOINT_TEST_STATUS_KEY = 'ccNexus_endpointTestStatus';
const CURRENT_ENDPOINT_KEY = 'ccNexus_currentEndpoint';

// 获取端点测试状态
export function getEndpointTestStatus(endpointName) {
Expand All @@ -27,29 +26,6 @@ export function saveEndpointTestStatus(endpointName, success) {
}
}

// 获取端点显示状态(只看测试状态,不看历史请求统计)
export function getEndpointDisplayStatus(endpointName) {
return getEndpointTestStatus(endpointName);
}

// 获取保存的当前端点名称
export function getSavedCurrentEndpoint() {
try {
return localStorage.getItem(CURRENT_ENDPOINT_KEY) || '';
} catch {
return '';
}
}

// 保存当前端点名称
export function saveCurrentEndpoint(endpointName) {
try {
localStorage.setItem(CURRENT_ENDPOINT_KEY, endpointName);
} catch (error) {
console.error('Failed to save current endpoint:', error);
}
}

let currentTestButton = null;
let currentTestButtonOriginalText = '';
let currentTestIndex = -1;
Expand Down Expand Up @@ -94,33 +70,6 @@ export async function renderEndpoints(endpoints) {
console.error('Failed to get current endpoint:', error);
}

// 检查 localStorage 中保存的当前端点,如果与后端不一致则同步
const savedEndpoint = getSavedCurrentEndpoint();
if (savedEndpoint && savedEndpoint !== currentEndpointName) {
// 检查保存的端点是否存在且启用
const savedExists = endpoints.some(ep => ep.name === savedEndpoint && (ep.enabled !== false));
if (savedExists) {
try {
await window.go.main.App.SwitchToEndpoint(savedEndpoint);
currentEndpointName = savedEndpoint;
} catch (error) {
console.error('Failed to restore saved endpoint:', error);
// 如果恢复失败,更新 localStorage 为后端的当前端点
if (currentEndpointName) {
saveCurrentEndpoint(currentEndpointName);
}
}
} else {
// 保存的端点不存在或未启用,更新 localStorage
if (currentEndpointName) {
saveCurrentEndpoint(currentEndpointName);
}
}
} else if (!savedEndpoint && currentEndpointName) {
// localStorage 没有保存,初始化保存当前端点
saveCurrentEndpoint(currentEndpointName);
}

if (endpoints.length === 0) {
container.innerHTML = `
<div class="empty-state">
Expand Down Expand Up @@ -152,21 +101,23 @@ export async function renderEndpoints(endpoints) {
item.draggable = true;
item.dataset.name = ep.name;
item.dataset.index = index;
// 获取显示状态(只看测试状态)
const displayStatus = getEndpointDisplayStatus(ep.name);
let testStatusIcon = '⚠️'; // 默认未测试
if (displayStatus === true) {
// 获取测试状态:true=成功显示✅,false=失败显示❌,undefined/unknown=未测试/未知显示⚠️
const testStatus = getEndpointTestStatus(ep.name);
let testStatusIcon = '⚠️';
let testStatusTip = t('endpoints.testTipUnknown');
if (testStatus === true) {
testStatusIcon = '✅';
} else if (displayStatus === false) {
testStatusTip = t('endpoints.testTipSuccess');
} else if (testStatus === false) {
testStatusIcon = '❌';
testStatusTip = t('endpoints.testTipFailed');
}
// 'unknown' 或 undefined 都显示 ⚠️

item.innerHTML = `
<div class="endpoint-info">
<h3>
${ep.name}
${testStatusIcon}
<span title="${testStatusTip}" style="cursor: help">${testStatusIcon}</span>
${isCurrentEndpoint ? '<span class="current-badge">' + t('endpoints.current') + '</span>' : ''}
${enabled && !isCurrentEndpoint ? '<button class="btn btn-switch" data-action="switch" data-name="' + ep.name + '">' + t('endpoints.switchTo') + '</button>' : ''}
</h3>
Expand Down Expand Up @@ -239,8 +190,6 @@ export async function renderEndpoints(endpoints) {
switchBtn.disabled = true;
switchBtn.innerHTML = '⏳';
await window.go.main.App.SwitchToEndpoint(name);
// 保存当前端点到 localStorage
saveCurrentEndpoint(name);
window.loadConfig(); // Refresh display
} catch (error) {
console.error('Failed to switch endpoint:', error);
Expand Down
Loading