mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 12:15:57 +00:00
- Fix regex escape in auth-utils.ts: `\\.` not `\\\\.` (dot matcher) - Refactor quota-fetcher.ts to import from auth-utils.ts (DRY) - Remove unused UnifiedQuotaResult type (YAGNI) - Add maintenance comment to Gemini model groups Addresses code review feedback on PR #395
28 lines
756 B
TypeScript
28 lines
756 B
TypeScript
/**
|
|
* Shared Authentication Utilities
|
|
*
|
|
* Common functions for OAuth token handling across quota fetchers.
|
|
*/
|
|
|
|
/**
|
|
* Sanitize email to match CLIProxyAPI auth file naming convention.
|
|
* Replaces @ and . with underscores for filesystem compatibility.
|
|
*/
|
|
export function sanitizeEmail(email: string): string {
|
|
return email.replace(/@/g, '_').replace(/\./g, '_');
|
|
}
|
|
|
|
/**
|
|
* Check if token is expired based on the expired timestamp.
|
|
* Returns false if timestamp is missing or invalid (fail-open for quota display).
|
|
*/
|
|
export function isTokenExpired(expiredStr?: string): boolean {
|
|
if (!expiredStr) return false;
|
|
try {
|
|
const expiredDate = new Date(expiredStr);
|
|
return expiredDate.getTime() < Date.now();
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|