Files
ccs/src/cliproxy/auth-utils.ts
T
kaitranntt 38ba6a9fea fix(cliproxy): resolve regex escape bug and complete DRY refactor
- 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
2026-01-29 14:55:07 -05:00

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;
}
}