mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 20:17:03 +00:00
fix(review): harden quota retry and tooltip edge cases
This commit is contained in:
1 parent
b6fb443f57
commit
7ac6d0a4d4
11 files changed
+206
-21
No files matched your search
@@ -21,9 +21,18 @@ export function getTokenExpiryTimestamp(expiredValue?: string | number | null):
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalizeNumericTimestamp = (value: number): number | null => {
|
||||
if (!Number.isFinite(value) || value <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Support Unix seconds from older token stores while preserving millisecond timestamps.
|
||||
return value < 1_000_000_000_000 ? value * 1000 : value;
|
||||
};
|
||||
|
||||
try {
|
||||
if (typeof expiredValue === 'number') {
|
||||
return Number.isFinite(expiredValue) ? expiredValue : null;
|
||||
return normalizeNumericTimestamp(expiredValue);
|
||||
}
|
||||
|
||||
const trimmed = expiredValue.trim();
|
||||
@@ -33,7 +42,7 @@ export function getTokenExpiryTimestamp(expiredValue?: string | number | null):
|
||||
|
||||
if (/^\d+$/.test(trimmed)) {
|
||||
const numericTimestamp = Number(trimmed);
|
||||
return Number.isFinite(numericTimestamp) ? numericTimestamp : null;
|
||||
return normalizeNumericTimestamp(numericTimestamp);
|
||||
}
|
||||
|
||||
const expiredDate = new Date(trimmed);
|
||||
|
||||
@@ -745,10 +745,9 @@ export async function fetchGeminiCliQuota(
|
||||
const expiresAt = getTokenExpiryTimestamp(authData.expiresAt);
|
||||
const shouldRefresh =
|
||||
authData.isExpired || expiresAt === null || expiresAt - Date.now() < REFRESH_LEAD_TIME_MS;
|
||||
let attemptedRefresh = false;
|
||||
let refreshedBeforeQuotaFetch = false;
|
||||
|
||||
if (shouldRefresh) {
|
||||
attemptedRefresh = true;
|
||||
if (verbose)
|
||||
console.error(
|
||||
authData.isExpired
|
||||
@@ -758,6 +757,7 @@ export async function fetchGeminiCliQuota(
|
||||
const refreshResult = await refreshGeminiToken(accountId);
|
||||
|
||||
if (refreshResult.success) {
|
||||
refreshedBeforeQuotaFetch = true;
|
||||
if (verbose) console.error('[i] Token refreshed successfully');
|
||||
// Re-read auth data after successful refresh
|
||||
const refreshedAuthData = readGeminiCliAuthData(accountId);
|
||||
@@ -784,7 +784,7 @@ export async function fetchGeminiCliQuota(
|
||||
const result = await fetchWithAuthData(authData, accountId, verbose);
|
||||
|
||||
// Retry once with an account-scoped refresh when the quota endpoint rejects auth.
|
||||
if (result.needsReauth && !attemptedRefresh) {
|
||||
if (result.needsReauth && !refreshedBeforeQuotaFetch) {
|
||||
if (verbose) console.error('[i] Got 401, attempting refresh and retry...');
|
||||
const refreshResult = await refreshGeminiToken(accountId);
|
||||
if (refreshResult.success) {
|
||||
|
||||
Reference in new issue
Block a user