mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-10-25 10:27:06 +08:00
refactor(types): extract source info types
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
import { authFilesApi } from '@/services/api/authFiles';
|
||||
import type { GeminiKeyConfig, ProviderKeyConfig, OpenAIProviderConfig } from '@/types';
|
||||
import type { AuthFileItem } from '@/types/authFile';
|
||||
import type { CredentialInfo } from '@/types/sourceInfo';
|
||||
import type { UsagePayload } from './hooks/useUsageData';
|
||||
import styles from '@/pages/UsagePage.module.scss';
|
||||
|
||||
@@ -24,11 +25,6 @@ export interface CredentialStatsCardProps {
|
||||
openaiProviders: OpenAIProviderConfig[];
|
||||
}
|
||||
|
||||
interface CredentialInfo {
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface CredentialRow {
|
||||
key: string;
|
||||
displayName: string;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Select } from '@/components/ui/Select';
|
||||
import { authFilesApi } from '@/services/api/authFiles';
|
||||
import type { GeminiKeyConfig, ProviderKeyConfig, OpenAIProviderConfig } from '@/types';
|
||||
import type { AuthFileItem } from '@/types/authFile';
|
||||
import type { CredentialInfo, SourceInfo } from '@/types/sourceInfo';
|
||||
import {
|
||||
buildCandidateUsageSourceIds,
|
||||
collectUsageDetails,
|
||||
@@ -60,16 +61,6 @@ const encodeCsv = (value: string | number): string => {
|
||||
return `"${safeText.replace(/"/g, '""')}"`;
|
||||
};
|
||||
|
||||
type CredentialInfo = {
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
type SourceInfo = {
|
||||
displayName: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export function RequestEventsDetailsCard({
|
||||
usage,
|
||||
loading,
|
||||
|
||||
+5
-14
@@ -23,6 +23,7 @@ import { authFilesApi } from '@/services/api/authFiles';
|
||||
import { logsApi } from '@/services/api/logs';
|
||||
import { usageApi } from '@/services/api/usage';
|
||||
import type { AuthFileItem } from '@/types';
|
||||
import type { CredentialInfo, SourceInfo } from '@/types/sourceInfo';
|
||||
import { copyToClipboard } from '@/utils/clipboard';
|
||||
import { downloadBlob } from '@/utils/download';
|
||||
import { MANAGEMENT_API_PREFIX } from '@/utils/constants';
|
||||
@@ -157,16 +158,6 @@ type TraceCandidate = {
|
||||
timeDeltaMs: number | null;
|
||||
};
|
||||
|
||||
type TraceCredentialInfo = {
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
type TraceSourceInfo = {
|
||||
displayName: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
const TRACE_USAGE_CACHE_MS = 60 * 1000;
|
||||
const TRACE_MATCH_STRONG_WINDOW_MS = 3 * 1000;
|
||||
const TRACE_MATCH_WINDOW_MS = 10 * 1000;
|
||||
@@ -505,7 +496,7 @@ export function LogsPage() {
|
||||
const [requestLogDownloading, setRequestLogDownloading] = useState(false);
|
||||
const [traceLogLine, setTraceLogLine] = useState<ParsedLogLine | null>(null);
|
||||
const [traceUsageDetails, setTraceUsageDetails] = useState<UsageDetailWithEndpoint[]>([]);
|
||||
const [traceAuthFileMap, setTraceAuthFileMap] = useState<Map<string, TraceCredentialInfo>>(new Map());
|
||||
const [traceAuthFileMap, setTraceAuthFileMap] = useState<Map<string, CredentialInfo>>(new Map());
|
||||
const [traceLoading, setTraceLoading] = useState(false);
|
||||
const [traceError, setTraceError] = useState('');
|
||||
|
||||
@@ -529,7 +520,7 @@ export function LogsPage() {
|
||||
|
||||
const disableControls = connectionStatus !== 'connected';
|
||||
const traceSourceInfoMap = useMemo(() => {
|
||||
const map = new Map<string, TraceSourceInfo>();
|
||||
const map = new Map<string, SourceInfo>();
|
||||
|
||||
const registerSource = (sourceId: string, displayName: string, type: string) => {
|
||||
if (!sourceId || !displayName || map.has(sourceId)) return;
|
||||
@@ -786,7 +777,7 @@ export function LogsPage() {
|
||||
? authFilesResponse
|
||||
: (authFilesResponse as { files?: AuthFileItem[] })?.files;
|
||||
if (Array.isArray(files)) {
|
||||
const map = new Map<string, TraceCredentialInfo>();
|
||||
const map = new Map<string, CredentialInfo>();
|
||||
files.forEach((file) => {
|
||||
const key = normalizeAuthIndex(file['auth_index'] ?? file.authIndex);
|
||||
if (!key) return;
|
||||
@@ -932,7 +923,7 @@ export function LogsPage() {
|
||||
return scored.slice(0, 8);
|
||||
}, [traceLogLine, traceUsageDetails]);
|
||||
const resolveTraceSourceInfo = useCallback(
|
||||
(sourceRaw: string, authIndex: unknown): TraceSourceInfo => {
|
||||
(sourceRaw: string, authIndex: unknown): SourceInfo => {
|
||||
const source = sourceRaw.trim();
|
||||
const matchedSource = traceSourceInfoMap.get(source);
|
||||
if (matchedSource) {
|
||||
|
||||
@@ -13,3 +13,4 @@ export * from './oauth';
|
||||
export * from './usage';
|
||||
export * from './log';
|
||||
export * from './quota';
|
||||
export * from './sourceInfo';
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export type SourceInfo = {
|
||||
displayName: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type CredentialInfo = {
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
Reference in New Issue
Block a user