mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 04:17:11 +00:00
fix(cliproxy): address PR review issues for backend selection
- Remove duplicate CLIProxyBackend type from platform-detector.ts (import from types.ts) - Add warning for invalid --backend CLI value (was silently ignored) - Show toast notification when backend change blocked by running proxy - Migrate from deprecated CLIPROXY_FALLBACK_VERSION to getFallbackVersion() - Add comprehensive JSDoc for backend API endpoints
This commit is contained in:
@@ -5,10 +5,13 @@
|
||||
* Supports 6 platforms: darwin/linux/windows x amd64/arm64
|
||||
*/
|
||||
|
||||
import { PlatformInfo, SupportedOS, SupportedArch, ArchiveExtension } from './types';
|
||||
|
||||
// Phase 1 will add CLIProxyBackend type - using string literal temporarily
|
||||
type CLIProxyBackend = 'original' | 'plus';
|
||||
import {
|
||||
PlatformInfo,
|
||||
SupportedOS,
|
||||
SupportedArch,
|
||||
ArchiveExtension,
|
||||
CLIProxyBackend,
|
||||
} from './types';
|
||||
|
||||
/** Backend configuration */
|
||||
export const BACKEND_CONFIG = {
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
} from '../cliproxy/account-manager';
|
||||
import { fetchAllProviderQuotas } from '../cliproxy/quota-fetcher';
|
||||
import { isOnCooldown } from '../cliproxy/quota-manager';
|
||||
import { DEFAULT_BACKEND, CLIPROXY_FALLBACK_VERSION } from '../cliproxy/platform-detector';
|
||||
import { DEFAULT_BACKEND, getFallbackVersion, BACKEND_CONFIG } from '../cliproxy/platform-detector';
|
||||
import { CLIPROXY_PROFILES, CLIProxyProfileName } from '../auth/profile-detector';
|
||||
import { supportsModelConfig, getProviderCatalog, ModelEntry } from '../cliproxy/model-catalog';
|
||||
import { CLIProxyProvider, CLIProxyBackend } from '../cliproxy/types';
|
||||
@@ -83,6 +83,7 @@ function parseBackendArg(args: string[]): {
|
||||
if (backendEqualsIdx !== -1) {
|
||||
const value = args[backendEqualsIdx].split('=')[1] as CLIProxyBackend;
|
||||
if (value !== 'original' && value !== 'plus') {
|
||||
warn(`Invalid backend '${value}'. Valid options: original, plus`);
|
||||
return { backend: undefined, remainingArgs: args };
|
||||
}
|
||||
const remainingArgs = [...args];
|
||||
@@ -93,6 +94,7 @@ function parseBackendArg(args: string[]): {
|
||||
}
|
||||
const value = args[backendIdx + 1];
|
||||
if (value !== 'original' && value !== 'plus') {
|
||||
warn(`Invalid backend '${value}'. Valid options: original, plus`);
|
||||
return { backend: undefined, remainingArgs: args };
|
||||
}
|
||||
const remainingArgs = [...args];
|
||||
@@ -642,9 +644,9 @@ async function showHelp(): Promise<void> {
|
||||
console.log(dim(' Note: CLIProxy now persists by default. Use "stop" to terminate.'));
|
||||
console.log('');
|
||||
console.log(subheader('Notes:'));
|
||||
console.log(` Default fallback version: ${color(CLIPROXY_FALLBACK_VERSION, 'info')}`);
|
||||
console.log(` Default fallback version: ${color(getFallbackVersion(), 'info')}`);
|
||||
console.log(
|
||||
` Releases: ${color('https://github.com/router-for-me/CLIProxyAPIPlus/releases', 'path')}`
|
||||
` Releases: ${color(`https://github.com/${BACKEND_CONFIG[DEFAULT_BACKEND].repo}/releases`, 'path')}`
|
||||
);
|
||||
console.log('');
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ router.put('/', async (req: Request, res: Response) => {
|
||||
|
||||
/**
|
||||
* GET /api/cliproxy-server/backend - Get CLIProxy backend setting
|
||||
* @returns {{ backend: 'original' | 'plus' }} Current backend configuration
|
||||
*/
|
||||
router.get('/backend', async (_req: Request, res: Response) => {
|
||||
try {
|
||||
@@ -81,6 +82,12 @@ router.get('/backend', async (_req: Request, res: Response) => {
|
||||
|
||||
/**
|
||||
* PUT /api/cliproxy-server/backend - Update CLIProxy backend setting
|
||||
* @param {Object} req.body - Request body
|
||||
* @param {'original' | 'plus'} req.body.backend - Backend to switch to
|
||||
* @param {boolean} [req.body.force=false] - Force change even if proxy is running
|
||||
* @returns {{ backend: 'original' | 'plus' }} Updated backend configuration
|
||||
* @throws {400} Invalid backend value
|
||||
* @throws {409} Proxy is running (unless force=true)
|
||||
*/
|
||||
router.put('/backend', async (req: Request, res: Response) => {
|
||||
try {
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
Box,
|
||||
AlertTriangle,
|
||||
} from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { useProxyConfig, useRawConfig } from '../../hooks';
|
||||
import { LocalProxyCard } from './local-proxy-card';
|
||||
import { RemoteProxyCard } from './remote-proxy-card';
|
||||
@@ -110,7 +111,7 @@ export default function ProxySection() {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Failed to save backend';
|
||||
// Check if error is due to proxy running (409 conflict)
|
||||
if (errorMessage.includes('Proxy is running')) {
|
||||
console.warn('[Proxy] Backend change blocked: proxy is running');
|
||||
toast.error('Stop the proxy first to change backend');
|
||||
}
|
||||
console.error('[Proxy] Failed to save backend:', err);
|
||||
setBackend(previousValue);
|
||||
|
||||
Reference in New Issue
Block a user