Fix loglist
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Filename: frontend/js/pages/logs/logList.js
|
||||
// --- [扩展] 静态错误码与样式的映射表 (源自Gemini官方文档) ---
|
||||
import { escapeHTML } from '../../utils/utils.js';
|
||||
|
||||
const STATIC_ERROR_MAP = {
|
||||
'API_KEY_INVALID': { type: '密钥无效', style: 'red' },
|
||||
'INVALID_ARGUMENT': { type: '参数无效', style: 'red' },
|
||||
@@ -23,10 +24,8 @@ const STATUS_CODE_MAP = {
|
||||
500: { type: '内部服务错误', style: 'yellow' },
|
||||
503: { type: '服务不可用', style: 'yellow' }
|
||||
};
|
||||
// --- [新增] 特殊场景判断规则 (高优先级) ---
|
||||
const SPECIAL_CASE_MAP = [
|
||||
{ code: 400, keyword: 'api key not found', type: '无效密钥', style: 'red' },
|
||||
// 之前实现的模型配置错误规则也可以移到这里,更加规范
|
||||
{ code: 404, keyword: 'call listmodels', type: '模型配置错误', style: 'orange' }
|
||||
];
|
||||
|
||||
@@ -41,16 +40,13 @@ const styleToClass = (style) => {
|
||||
}
|
||||
};
|
||||
|
||||
// [修正] 修正了正则表达式的名称,使其语义清晰
|
||||
|
||||
const errorCodeRegex = /(\d+)$/;
|
||||
|
||||
// [修正] 移除了 MODEL_STYLE_MAP 的声明,因为它未在 _formatModelName 中使用
|
||||
// 如果未来需要,可以重新添加
|
||||
// const MODEL_STYLE_MAP = { ... };
|
||||
|
||||
class LogList {
|
||||
constructor(container) {
|
||||
constructor(container, dataStore) {
|
||||
this.container = container;
|
||||
this.dataStore = dataStore;
|
||||
if (!this.container) console.error("LogList: container element (tbody) not found.");
|
||||
}
|
||||
|
||||
@@ -125,15 +121,21 @@ class LogList {
|
||||
}
|
||||
|
||||
_formatModelName(modelName) {
|
||||
// [修正] 移除了对 MODEL_STYLE_MAP 的依赖,简化为统一的样式
|
||||
// 这样可以避免因 MODEL_STYLE_MAP 未定义而产生的潜在错误
|
||||
const styleClass = ''; // 可根据需要添加回样式逻辑
|
||||
const styleClass = '';
|
||||
return `<div class="inline-block rounded bg-zinc-100 dark:bg-zinc-800 px-2 py-0.5"><span class="font-quinquefive text-xs tracking-wider ${styleClass}">${modelName}</span></div>`;
|
||||
}
|
||||
|
||||
createLogRowHtml(log, index) {
|
||||
const groupName = log.GroupDisplayName || (log.GroupID ? `Group #${log.GroupID}` : 'N/A');
|
||||
const apiKeyName = log.APIKeyName || (log.KeyID ? `Key #${log.KeyID}` : 'N/A');
|
||||
const group = this.dataStore.groups.get(log.GroupID);
|
||||
const groupName = group ? group.display_name : (log.GroupID ? `Group #${log.GroupID}` : 'N/A');
|
||||
const key = this.dataStore.keys.get(log.KeyID);
|
||||
let apiKeyDisplay;
|
||||
if (key && key.APIKey && key.APIKey.length >= 8) {
|
||||
const masked = `${key.APIKey.substring(0, 4)}......${key.APIKey.substring(key.APIKey.length - 4)}`;
|
||||
apiKeyDisplay = escapeHTML(masked);
|
||||
} else {
|
||||
apiKeyDisplay = log.KeyID ? `Key #${log.KeyID}` : 'N/A';
|
||||
}
|
||||
const errorInfo = this._interpretError(log);
|
||||
const modelNameFormatted = this._formatModelName(log.ModelName);
|
||||
const errorMessageAttr = log.ErrorMessage ? `data-error-message="${escape(log.ErrorMessage)}"` : '';
|
||||
@@ -142,7 +144,7 @@ class LogList {
|
||||
<tr class="table-row" data-log-id="${log.ID}" ${errorMessageAttr}>
|
||||
<td class="table-cell"><input type="checkbox" class="h-4 w-4 rounded border-zinc-300 text-blue-600 focus:ring-blue-500"></td>
|
||||
<td class="table-cell font-mono text-muted-foreground">${index}</td>
|
||||
<td class="table-cell font-medium font-mono">${apiKeyName}</td>
|
||||
<td class="table-cell font-medium font-mono">${apiKeyDisplay}</td>
|
||||
<td class="table-cell">${groupName}</td>
|
||||
<td class="table-cell">${errorInfo.type}</td>
|
||||
<td class="table-cell">${errorInfo.statusCodeHtml}</td>
|
||||
@@ -158,5 +160,4 @@ class LogList {
|
||||
}
|
||||
}
|
||||
|
||||
// [核心修正] 移除了文件末尾所有多余的代码,只保留最核心的默认导出
|
||||
export default LogList;
|
||||
|
||||
Reference in New Issue
Block a user