mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 10:17:05 +00:00
fix(cliproxy): propagate backend parameter to version check functions
Root cause: fetchLatestCliproxyVersion() and checkCliproxyUpdate() ignored the caller's backend selection, always re-computing from config. This caused --update to report wrong version when config wasn't synced. Changes: - Add optional backend param to fetchLatestCliproxyVersion() - Add optional backend param to checkCliproxyUpdate() - Pass effectiveBackend in binary-service.ts calls - Pass backend in cliproxy-stats-routes.ts web endpoints Fixes inconsistent version reporting when switching between CLIProxyAPI (original) and CLIProxyAPIPlus backends.
This commit is contained in:
@@ -198,9 +198,9 @@ export async function installCliproxyVersion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Fetch the latest CLIProxyAPI version from GitHub API */
|
/** Fetch the latest CLIProxyAPI version from GitHub API */
|
||||||
export async function fetchLatestCliproxyVersion(): Promise<string> {
|
export async function fetchLatestCliproxyVersion(backend?: CLIProxyBackend): Promise<string> {
|
||||||
const backend = getConfiguredBackend();
|
const effectiveBackend = backend ?? getConfiguredBackend();
|
||||||
const result = await new BinaryManager({}, backend).checkForUpdates();
|
const result = await new BinaryManager({}, effectiveBackend).checkForUpdates();
|
||||||
return result.latestVersion;
|
return result.latestVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,9 +221,11 @@ export interface CliproxyUpdateCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Check for CLIProxyAPI binary updates */
|
/** Check for CLIProxyAPI binary updates */
|
||||||
export async function checkCliproxyUpdate(): Promise<CliproxyUpdateCheckResult> {
|
export async function checkCliproxyUpdate(
|
||||||
const backend = getConfiguredBackend();
|
backend?: CLIProxyBackend
|
||||||
const result = await new BinaryManager({}, backend).checkForUpdates();
|
): Promise<CliproxyUpdateCheckResult> {
|
||||||
|
const effectiveBackend = backend ?? getConfiguredBackend();
|
||||||
|
const result = await new BinaryManager({}, effectiveBackend).checkForUpdates();
|
||||||
|
|
||||||
// Import isNewerVersion for stability check
|
// Import isNewerVersion for stability check
|
||||||
const { isNewerVersion } = await import('./binary/version-checker');
|
const { isNewerVersion } = await import('./binary/version-checker');
|
||||||
@@ -232,11 +234,11 @@ export async function checkCliproxyUpdate(): Promise<CliproxyUpdateCheckResult>
|
|||||||
? undefined
|
? undefined
|
||||||
: `v${result.currentVersion} has known stability issues. Max stable: v${CLIPROXY_MAX_STABLE_VERSION}`;
|
: `v${result.currentVersion} has known stability issues. Max stable: v${CLIPROXY_MAX_STABLE_VERSION}`;
|
||||||
|
|
||||||
const backendLabel = backend === 'plus' ? 'CLIProxy Plus' : 'CLIProxy';
|
const backendLabel = effectiveBackend === 'plus' ? 'CLIProxy Plus' : 'CLIProxy';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...result,
|
...result,
|
||||||
backend,
|
backend: effectiveBackend,
|
||||||
backendLabel,
|
backendLabel,
|
||||||
isStable,
|
isStable,
|
||||||
maxStableVersion: CLIPROXY_MAX_STABLE_VERSION,
|
maxStableVersion: CLIPROXY_MAX_STABLE_VERSION,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export async function checkLatestVersion(backend?: CLIProxyBackend): Promise<Lat
|
|||||||
try {
|
try {
|
||||||
// Use checkCliproxyUpdate which is backend-aware (uses correct GitHub repo)
|
// Use checkCliproxyUpdate which is backend-aware (uses correct GitHub repo)
|
||||||
const { checkCliproxyUpdate } = await import('../binary-manager');
|
const { checkCliproxyUpdate } = await import('../binary-manager');
|
||||||
const updateResult = await checkCliproxyUpdate();
|
const updateResult = await checkCliproxyUpdate(effectiveBackend);
|
||||||
const latestVersion = updateResult.latestVersion;
|
const latestVersion = updateResult.latestVersion;
|
||||||
const currentVersion = getInstalledCliproxyVersion(effectiveBackend);
|
const currentVersion = getInstalledCliproxyVersion(effectiveBackend);
|
||||||
const updateAvailable = latestVersion !== currentVersion;
|
const updateAvailable = latestVersion !== currentVersion;
|
||||||
@@ -151,7 +151,7 @@ export async function installLatest(
|
|||||||
backend ?? loadOrCreateUnifiedConfig().cliproxy?.backend ?? DEFAULT_BACKEND;
|
backend ?? loadOrCreateUnifiedConfig().cliproxy?.backend ?? DEFAULT_BACKEND;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const latestVersion = await fetchLatestCliproxyVersion();
|
const latestVersion = await fetchLatestCliproxyVersion(effectiveBackend);
|
||||||
const currentVersion = getInstalledCliproxyVersion(effectiveBackend);
|
const currentVersion = getInstalledCliproxyVersion(effectiveBackend);
|
||||||
const wasPinned = isVersionPinned(effectiveBackend);
|
const wasPinned = isVersionPinned(effectiveBackend);
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ router.post('/proxy-stop', async (_req: Request, res: Response): Promise<void> =
|
|||||||
*/
|
*/
|
||||||
router.get('/update-check', async (_req: Request, res: Response): Promise<void> => {
|
router.get('/update-check', async (_req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const result = await checkCliproxyUpdate();
|
const backend = getConfiguredBackend();
|
||||||
|
const result = await checkCliproxyUpdate(backend);
|
||||||
res.json(result);
|
res.json(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: (error as Error).message });
|
res.status(500).json({ error: (error as Error).message });
|
||||||
@@ -625,7 +626,8 @@ router.post('/install', async (req: Request, res: Response): Promise<void> => {
|
|||||||
await new Promise((r) => setTimeout(r, 500));
|
await new Promise((r) => setTimeout(r, 500));
|
||||||
|
|
||||||
// Install the version
|
// Install the version
|
||||||
await installCliproxyVersion(version, true);
|
const backend = getConfiguredBackend();
|
||||||
|
await installCliproxyVersion(version, true, backend);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user