mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-19 11:10:49 +08:00
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { useMemo } from 'react';
|
|
import type { AuthFileItem } from '@/types';
|
|
import { calculateStatusBarData, type UsageDetail } from '@/utils/usage';
|
|
import { normalizeAuthIndexValue } from '@/features/authFiles/constants';
|
|
|
|
export type AuthFileStatusBarData = ReturnType<typeof calculateStatusBarData>;
|
|
|
|
export function useAuthFilesStatusBarCache(files: AuthFileItem[], usageDetails: UsageDetail[]) {
|
|
return useMemo(() => {
|
|
const cache = new Map<string, AuthFileStatusBarData>();
|
|
|
|
files.forEach((file) => {
|
|
const rawAuthIndex = file['auth_index'] ?? file.authIndex;
|
|
const authIndexKey = normalizeAuthIndexValue(rawAuthIndex);
|
|
|
|
if (authIndexKey) {
|
|
const filteredDetails = usageDetails.filter((detail) => {
|
|
const detailAuthIndex = normalizeAuthIndexValue(detail.auth_index);
|
|
return detailAuthIndex !== null && detailAuthIndex === authIndexKey;
|
|
});
|
|
cache.set(authIndexKey, calculateStatusBarData(filteredDetails));
|
|
}
|
|
});
|
|
|
|
return cache;
|
|
}, [files, usageDetails]);
|
|
}
|
|
|