feat: display auth file name instead of index in request logs

- Load auth files to build authIndex -> fileName mapping
- Display actual auth file name in the Auth Index column
- Fallback to index number if mapping not found
This commit is contained in:
Lany798
2026-02-03 08:52:49 +08:00
parent 149d89a3d8
commit 259bf88f81

View File

@@ -2,7 +2,7 @@ import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useVirtualizer } from '@tanstack/react-virtual'; import { useVirtualizer } from '@tanstack/react-virtual';
import { Card } from '@/components/ui/Card'; import { Card } from '@/components/ui/Card';
import { usageApi } from '@/services/api'; import { usageApi, authFilesApi } from '@/services/api';
import { useDisableModel } from '@/hooks'; import { useDisableModel } from '@/hooks';
import { TimeRangeSelector, formatTimeRangeCaption, type TimeRange } from './TimeRangeSelector'; import { TimeRangeSelector, formatTimeRangeCaption, type TimeRange } from './TimeRangeSelector';
import { DisableModelModal } from './DisableModelModal'; import { DisableModelModal } from './DisableModelModal';
@@ -93,6 +93,9 @@ export function RequestLogs({ data, loading: parentLoading, providerMap, provide
const [logLoading, setLogLoading] = useState(false); const [logLoading, setLogLoading] = useState(false);
const [isFirstLoad, setIsFirstLoad] = useState(true); const [isFirstLoad, setIsFirstLoad] = useState(true);
// 认证文件索引到名称的映射
const [authIndexMap, setAuthIndexMap] = useState<Record<string, string>>({});
// 使用禁用模型 Hook // 使用禁用模型 Hook
const { const {
disableState, disableState,
@@ -125,6 +128,28 @@ export function RequestLogs({ data, loading: parentLoading, providerMap, provide
} }
}, [parentLoading, data]); }, [parentLoading, data]);
// 加载认证文件映射authIndex -> 文件名)
const loadAuthIndexMap = useCallback(async () => {
try {
const response = await authFilesApi.list();
const files = response?.files || [];
const map: Record<string, string> = {};
files.forEach((file) => {
if (file.authIndex !== undefined && file.authIndex !== null) {
map[String(file.authIndex)] = file.name;
}
});
setAuthIndexMap(map);
} catch (err) {
console.warn('Failed to load auth files for index mapping:', err);
}
}, []);
// 初始加载认证文件映射
useEffect(() => {
loadAuthIndexMap();
}, [loadAuthIndexMap]);
// 独立获取日志数据 // 独立获取日志数据
const fetchLogData = useCallback(async () => { const fetchLogData = useCallback(async () => {
setLogLoading(true); setLogLoading(true);
@@ -411,11 +436,13 @@ export function RequestLogs({ data, loading: parentLoading, providerMap, provide
const stats = getStats(entry); const stats = getStats(entry);
const rateValue = parseFloat(stats.successRate); const rateValue = parseFloat(stats.successRate);
const disabled = isModelDisabled(entry.source, entry.model); const disabled = isModelDisabled(entry.source, entry.model);
// 将 authIndex 映射为文件名
const authDisplayName = entry.authIndex ? (authIndexMap[entry.authIndex] || entry.authIndex) : '-';
return ( return (
<> <>
<td title={entry.authIndex || '-'}> <td title={authDisplayName}>
{entry.authIndex || '-'} {authDisplayName}
</td> </td>
<td title={entry.apiKey}> <td title={entry.apiKey}>
{maskSecret(entry.apiKey)} {maskSecret(entry.apiKey)}