mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 22:14:22 +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:
1 parent
e31d00f0b9
commit
38ba6a9fea
4 files changed
+6
-48
No files matched your search
@@ -9,7 +9,7 @@
|
|||||||
* Replaces @ and . with underscores for filesystem compatibility.
|
* Replaces @ and . with underscores for filesystem compatibility.
|
||||||
*/
|
*/
|
||||||
export function sanitizeEmail(email: string): string {
|
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_BASE = 'https://cloudcode-pa.googleapis.com';
|
||||||
const GEMINI_CLI_API_VERSION = 'v1internal';
|
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<
|
const GEMINI_CLI_GROUPS: Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
type AccountInfo,
|
type AccountInfo,
|
||||||
type AccountTier,
|
type AccountTier,
|
||||||
} from './account-manager';
|
} from './account-manager';
|
||||||
|
import { sanitizeEmail, isTokenExpired } from './auth-utils';
|
||||||
|
|
||||||
/** Individual model quota info */
|
/** Individual model quota info */
|
||||||
export interface ModelQuota {
|
export interface ModelQuota {
|
||||||
@@ -154,27 +155,6 @@ interface FetchAvailableModelsResponse {
|
|||||||
models?: Record<string, AvailableModel>;
|
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
|
* Refresh access token using refresh_token via Google OAuth
|
||||||
* This allows CCS to get fresh tokens independently of CLIProxyAPI
|
* This allows CCS to get fresh tokens independently of CLIProxyAPI
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
* Supports Antigravity, Codex, and Gemini CLI providers.
|
* Supports Antigravity, Codex, and Gemini CLI providers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { QuotaResult as AntigravityQuotaResult } from './quota-fetcher';
|
|
||||||
|
|
||||||
/** Supported quota providers */
|
/** Supported quota providers */
|
||||||
export type QuotaProvider = 'agy' | 'codex' | 'gemini';
|
export type QuotaProvider = 'agy' | 'codex' | 'gemini';
|
||||||
|
|
||||||
@@ -84,26 +82,3 @@ export interface GeminiCliQuotaResult {
|
|||||||
/** Account ID (email) this quota belongs to */
|
/** Account ID (email) this quota belongs to */
|
||||||
accountId?: string;
|
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