mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
- Updated markAccountUnavailable function to accept resetsAtMs for precise cooldown management.
- Added email backfill functionality for Codex OAuth connections to improve account information accuracy.
This commit is contained in:
@@ -703,6 +703,39 @@ export async function getUsageStats(period = "all") {
|
||||
if (dateKey > (stats.byEndpoint[epKey].lastUsed || "")) stats.byEndpoint[epKey].lastUsed = dateKey;
|
||||
}
|
||||
}
|
||||
|
||||
// Overlay lastUsed with precise ISO timestamps from live history (dailySummary only has YYYY-MM-DD)
|
||||
const overlayCutoff = maxDays ? Date.now() - maxDays * 86400000 : 0;
|
||||
for (const entry of history) {
|
||||
const ts = entry.timestamp;
|
||||
if (!ts || new Date(ts).getTime() < overlayCutoff) continue;
|
||||
|
||||
const modelKey = entry.provider ? `${entry.model} (${entry.provider})` : entry.model;
|
||||
if (stats.byModel[modelKey] && new Date(ts) > new Date(stats.byModel[modelKey].lastUsed)) {
|
||||
stats.byModel[modelKey].lastUsed = ts;
|
||||
}
|
||||
|
||||
if (entry.connectionId) {
|
||||
const accountName = connectionMap[entry.connectionId] || `Account ${entry.connectionId.slice(0, 8)}...`;
|
||||
const accountKey = `${entry.model} (${entry.provider} - ${accountName})`;
|
||||
if (stats.byAccount[accountKey] && new Date(ts) > new Date(stats.byAccount[accountKey].lastUsed)) {
|
||||
stats.byAccount[accountKey].lastUsed = ts;
|
||||
}
|
||||
}
|
||||
|
||||
const apiKeyKey = (entry.apiKey && typeof entry.apiKey === "string")
|
||||
? `${entry.apiKey}|${entry.model}|${entry.provider || "unknown"}`
|
||||
: "local-no-key";
|
||||
if (stats.byApiKey[apiKeyKey] && new Date(ts) > new Date(stats.byApiKey[apiKeyKey].lastUsed)) {
|
||||
stats.byApiKey[apiKeyKey].lastUsed = ts;
|
||||
}
|
||||
|
||||
const endpoint = entry.endpoint || "Unknown";
|
||||
const endpointKey = `${endpoint}|${entry.model}|${entry.provider || "unknown"}`;
|
||||
if (stats.byEndpoint[endpointKey] && new Date(ts) > new Date(stats.byEndpoint[endpointKey].lastUsed)) {
|
||||
stats.byEndpoint[endpointKey].lastUsed = ts;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 24h: use live history (original logic)
|
||||
const cutoff = Date.now() - PERIOD_MS["24h"];
|
||||
|
||||
Reference in New Issue
Block a user