From 295befe42b7bef421b05fe8ca0c7d2e8e4d563d6 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Fri, 14 Nov 2025 18:24:22 +0800 Subject: [PATCH] feat(app.js): enhance file name handling in CLIProxyManager - Added logic to generate candidate names based on the raw file name, type, and provider prefixes. - Implemented checks to return statistics for candidates and their masked versions, improving the accuracy of file management. - Enhanced the overall handling of file names to support better matching and retrieval of associated stats. --- app.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app.js b/app.js index 1da18c1..4828470 100644 --- a/app.js +++ b/app.js @@ -3955,6 +3955,46 @@ class CLIProxyManager { let fileStats = fromName || defaultStats; if (fileStats.success === 0 && fileStats.failure === 0) { const nameWithoutExt = rawFileName.replace(/\.[^/.]+$/, ""); + + if (nameWithoutExt && nameWithoutExt !== rawFileName) { + const candidateNames = new Set([nameWithoutExt]); + const normalizedName = nameWithoutExt.toLowerCase(); + const typePrefix = typeof file?.type === 'string' ? file.type.trim().toLowerCase() : ''; + const providerPrefix = typeof file?.provider === 'string' ? file.provider.trim().toLowerCase() : ''; + const prefixList = []; + + if (typePrefix) { + prefixList.push(`${typePrefix}-`); + } + if (providerPrefix && providerPrefix !== typePrefix) { + prefixList.push(`${providerPrefix}-`); + } + + prefixList.forEach(prefix => { + if (prefix && normalizedName.startsWith(prefix)) { + const trimmed = nameWithoutExt.substring(prefix.length); + if (trimmed) { + candidateNames.add(trimmed); + } + } + }); + + for (const candidate of candidateNames) { + const statsByName = stats[candidate]; + if (statsByName && (statsByName.success > 0 || statsByName.failure > 0)) { + return statsByName; + } + + const maskedCandidate = this.maskApiKey(candidate); + if (maskedCandidate && maskedCandidate !== candidate) { + const statsByMaskedName = stats[maskedCandidate]; + if (statsByMaskedName && (statsByMaskedName.success > 0 || statsByMaskedName.failure > 0)) { + return statsByMaskedName; + } + } + } + } + const possibleSources = []; const match = nameWithoutExt.match(/^([^@]+@[^-]+)-(.+)$/);