refactor(stats): enhance key statistics handling by introducing source and auth index categorization

This commit is contained in:
Supra4E8C
2025-11-20 14:08:10 +08:00
parent 8f4320c837
commit c5010adb82
3 changed files with 84 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ export const authFilesModule = {
const stats = keyStats || await this.getKeyStats();
this.cachedAuthFiles = visibleFiles.map(file => ({ ...file }));
this.authFileStatsCache = stats || {};
this.authFileStatsCache = stats || { bySource: {}, byAuthIndex: {} };
this.syncAuthFileControls();
if (this.cachedAuthFiles.length === 0) {
@@ -76,13 +76,21 @@ export const authFilesModule = {
},
resolveAuthFileStats(file, stats = {}) {
const statsBySource = (stats && stats.bySource) || stats || {};
const statsByAuthIndex = (stats && stats.byAuthIndex) || {};
const rawFileName = typeof file?.name === 'string' ? file.name : '';
const defaultStats = { success: 0, failure: 0 };
const authIndexKey = this.normalizeAuthIndexValue(file?.auth_index);
if (authIndexKey && statsByAuthIndex[authIndexKey]) {
return statsByAuthIndex[authIndexKey];
}
if (!rawFileName) {
return defaultStats;
}
const fromName = stats[rawFileName];
const fromName = statsBySource[rawFileName];
if (fromName && (fromName.success > 0 || fromName.failure > 0)) {
return fromName;
}
@@ -115,7 +123,7 @@ export const authFilesModule = {
});
for (const candidate of candidateNames) {
const candidateStats = stats[candidate];
const candidateStats = statsBySource[candidate];
if (candidateStats && (candidateStats.success > 0 || candidateStats.failure > 0)) {
fileStats = candidateStats;
break;
@@ -127,6 +135,17 @@ export const authFilesModule = {
return fileStats || defaultStats;
},
normalizeAuthIndexValue(value) {
if (typeof value === 'number' && Number.isFinite(value)) {
return value.toString();
}
if (typeof value === 'string') {
const trimmed = value.trim();
return trimmed ? trimmed : null;
}
return null;
},
buildAuthFileItemHtml(file) {
const rawFileName = typeof file?.name === 'string' ? file.name : '';
const safeFileName = this.escapeHtml(rawFileName);