mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
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
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* Replaces @ and . with underscores for filesystem compatibility.
|
||||
*/
|
||||
export function sanitizeEmail(email: string): string {
|
||||
return email.replace(/@/g, '_').replace(/\\./g, '_');
|
||||
return email.replace(/@/g, '_').replace(/\./g, '_');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,10 @@ import type { GeminiCliQuotaResult, GeminiCliBucket } from './quota-types';
|
||||
const GEMINI_CLI_API_BASE = 'https://cloudcode-pa.googleapis.com';
|
||||
const GEMINI_CLI_API_VERSION = 'v1internal';
|
||||
|
||||
/** Model groups for quota consolidation */
|
||||
/**
|
||||
* Model groups for quota consolidation.
|
||||
* Update when Google releases new Gemini models to include them in quota display.
|
||||
*/
|
||||
const GEMINI_CLI_GROUPS: Record<
|
||||
string,
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
type AccountInfo,
|
||||
type AccountTier,
|
||||
} from './account-manager';
|
||||
import { sanitizeEmail, isTokenExpired } from './auth-utils';
|
||||
|
||||
/** Individual model quota info */
|
||||
export interface ModelQuota {
|
||||
@@ -154,27 +155,6 @@ interface FetchAvailableModelsResponse {
|
||||
models?: Record<string, AvailableModel>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize email to match CLIProxyAPI auth file naming convention
|
||||
* Replaces @ and . with underscores (matches Go sanitizeAntigravityFileName)
|
||||
*/
|
||||
function sanitizeEmail(email: string): string {
|
||||
return email.replace(/@/g, '_').replace(/\./g, '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if token is expired based on the expired timestamp
|
||||
*/
|
||||
function isTokenExpired(expiredStr?: string): boolean {
|
||||
if (!expiredStr) return false;
|
||||
try {
|
||||
const expiredDate = new Date(expiredStr);
|
||||
return expiredDate.getTime() < Date.now();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh access token using refresh_token via Google OAuth
|
||||
* This allows CCS to get fresh tokens independently of CLIProxyAPI
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
* Supports Antigravity, Codex, and Gemini CLI providers.
|
||||
*/
|
||||
|
||||
import type { QuotaResult as AntigravityQuotaResult } from './quota-fetcher';
|
||||
|
||||
/** Supported quota providers */
|
||||
export type QuotaProvider = 'agy' | 'codex' | 'gemini';
|
||||
|
||||
@@ -84,26 +82,3 @@ export interface GeminiCliQuotaResult {
|
||||
/** Account ID (email) this quota belongs to */
|
||||
accountId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unified quota result wrapper for CLI/Dashboard
|
||||
* Contains provider-specific data in nested fields
|
||||
*/
|
||||
export interface UnifiedQuotaResult {
|
||||
/** Provider this result belongs to */
|
||||
provider: QuotaProvider;
|
||||
/** Whether fetch succeeded */
|
||||
success: boolean;
|
||||
/** Timestamp of fetch */
|
||||
lastUpdated: number;
|
||||
/** Error message if fetch failed */
|
||||
error?: string;
|
||||
/** Account ID (email) this quota belongs to */
|
||||
accountId?: string;
|
||||
/** Antigravity-specific quota data */
|
||||
antigravity?: AntigravityQuotaResult;
|
||||
/** Codex-specific quota data */
|
||||
codex?: CodexQuotaResult;
|
||||
/** Gemini CLI-specific quota data */
|
||||
geminiCli?: GeminiCliQuotaResult;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user