mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 00:17:47 +00:00
fix: replace hardcoded provider validation arrays with CLIPROXY_PROFILES import
Closes #382 Replace duplicate hardcoded provider validation arrays across three route files with a single import from CLIPROXY_PROFILES constant. This DRY fix eliminates code duplication and ensures provider validation is consistent across all routes. Files updated: - account-routes.ts - cliproxy-auth-routes.ts - cliproxy-stats-routes.ts Reduces code by 21 lines while improving maintainability.
This commit is contained in:
@@ -17,20 +17,13 @@ import {
|
|||||||
soloAccount,
|
soloAccount,
|
||||||
} from '../../cliproxy/account-manager';
|
} from '../../cliproxy/account-manager';
|
||||||
import type { CLIProxyProvider } from '../../cliproxy/types';
|
import type { CLIProxyProvider } from '../../cliproxy/types';
|
||||||
|
import { CLIPROXY_PROFILES } from '../../auth/profile-detector';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
const registry = new ProfileRegistry();
|
const registry = new ProfileRegistry();
|
||||||
|
|
||||||
/** Valid CLIProxy providers */
|
/** Valid CLIProxy providers - derived from canonical CLIPROXY_PROFILES */
|
||||||
const VALID_PROVIDERS: CLIProxyProvider[] = [
|
const VALID_PROVIDERS: CLIProxyProvider[] = [...CLIPROXY_PROFILES];
|
||||||
'gemini',
|
|
||||||
'codex',
|
|
||||||
'agy',
|
|
||||||
'qwen',
|
|
||||||
'iflow',
|
|
||||||
'kiro',
|
|
||||||
'ghcp',
|
|
||||||
];
|
|
||||||
|
|
||||||
/** Check if provider is valid */
|
/** Check if provider is valid */
|
||||||
function isValidProvider(provider: string): provider is CLIProxyProvider {
|
function isValidProvider(provider: string): provider is CLIProxyProvider {
|
||||||
|
|||||||
@@ -35,19 +35,12 @@ import { loadOrCreateUnifiedConfig } from '../../config/unified-config-loader';
|
|||||||
import { tryKiroImport } from '../../cliproxy/auth/kiro-import';
|
import { tryKiroImport } from '../../cliproxy/auth/kiro-import';
|
||||||
import { getProviderTokenDir } from '../../cliproxy/auth/token-manager';
|
import { getProviderTokenDir } from '../../cliproxy/auth/token-manager';
|
||||||
import type { CLIProxyProvider } from '../../cliproxy/types';
|
import type { CLIProxyProvider } from '../../cliproxy/types';
|
||||||
|
import { CLIPROXY_PROFILES } from '../../auth/profile-detector';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// Valid providers list
|
// Valid providers list - derived from canonical CLIPROXY_PROFILES
|
||||||
const validProviders: CLIProxyProvider[] = [
|
const validProviders: CLIProxyProvider[] = [...CLIPROXY_PROFILES];
|
||||||
'gemini',
|
|
||||||
'codex',
|
|
||||||
'agy',
|
|
||||||
'qwen',
|
|
||||||
'iflow',
|
|
||||||
'kiro',
|
|
||||||
'ghcp',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/cliproxy/auth - Get auth status for built-in CLIProxy profiles
|
* GET /api/cliproxy/auth - Get auth status for built-in CLIProxy profiles
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
} from '../../cliproxy/stats-fetcher';
|
} from '../../cliproxy/stats-fetcher';
|
||||||
import { fetchAccountQuota } from '../../cliproxy/quota-fetcher';
|
import { fetchAccountQuota } from '../../cliproxy/quota-fetcher';
|
||||||
import type { CLIProxyProvider } from '../../cliproxy/types';
|
import type { CLIProxyProvider } from '../../cliproxy/types';
|
||||||
|
import { CLIPROXY_PROFILES } from '../../auth/profile-detector';
|
||||||
import {
|
import {
|
||||||
getCliproxyWritablePath,
|
getCliproxyWritablePath,
|
||||||
getCliproxyConfigPath,
|
getCliproxyConfigPath,
|
||||||
@@ -517,16 +518,8 @@ router.put('/models/:provider', async (req: Request, res: Response): Promise<voi
|
|||||||
router.get('/quota/:provider/:accountId', async (req: Request, res: Response): Promise<void> => {
|
router.get('/quota/:provider/:accountId', async (req: Request, res: Response): Promise<void> => {
|
||||||
const { provider, accountId } = req.params;
|
const { provider, accountId } = req.params;
|
||||||
|
|
||||||
// Validate provider
|
// Validate provider - use canonical CLIPROXY_PROFILES
|
||||||
const validProviders: CLIProxyProvider[] = [
|
const validProviders: CLIProxyProvider[] = [...CLIPROXY_PROFILES];
|
||||||
'agy',
|
|
||||||
'gemini',
|
|
||||||
'codex',
|
|
||||||
'qwen',
|
|
||||||
'iflow',
|
|
||||||
'kiro',
|
|
||||||
'ghcp',
|
|
||||||
];
|
|
||||||
if (!validProviders.includes(provider as CLIProxyProvider)) {
|
if (!validProviders.includes(provider as CLIProxyProvider)) {
|
||||||
res.status(400).json({
|
res.status(400).json({
|
||||||
error: 'Invalid provider',
|
error: 'Invalid provider',
|
||||||
|
|||||||
Reference in New Issue
Block a user