mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-07 00:23:05 +00:00
fix(cliproxy): make version cache backend-specific for proper switching
- Add backend parameter to version cache functions (read/write/path)
- Store cache at bin/{backend}/.version-cache.json instead of shared location
- Pass backend through checkForUpdates() and BinaryManager
- Add refetchType: 'all' to force immediate query refetch on backend change
- Add cliproxy-server-config query invalidation for consistency
This commit is contained in:
@@ -85,7 +85,12 @@ export class BinaryManager {
|
|||||||
|
|
||||||
/** Check for updates by comparing installed version with latest release */
|
/** Check for updates by comparing installed version with latest release */
|
||||||
async checkForUpdates(): Promise<UpdateCheckResult> {
|
async checkForUpdates(): Promise<UpdateCheckResult> {
|
||||||
return checkForUpdates(this.config.binPath, this.config.version, this.config.verbose);
|
return checkForUpdates(
|
||||||
|
this.config.binPath,
|
||||||
|
this.config.version,
|
||||||
|
this.config.verbose,
|
||||||
|
this.backend
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get full path to binary executable */
|
/** Get full path to binary executable */
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ import { DEFAULT_BACKEND } from '../platform-detector';
|
|||||||
import type { CLIProxyBackend } from '../types';
|
import type { CLIProxyBackend } from '../types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path to version cache file
|
* Get path to version cache file (backend-specific)
|
||||||
*/
|
*/
|
||||||
export function getVersionCachePath(): string {
|
export function getVersionCachePath(backend: CLIProxyBackend = DEFAULT_BACKEND): string {
|
||||||
return path.join(getCliproxyDir(), '.version-cache.json');
|
return path.join(getBinDir(), backend, '.version-cache.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,10 +30,10 @@ export function getVersionPinPath(backend: CLIProxyBackend = DEFAULT_BACKEND): s
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read version cache if still valid
|
* Read version cache if still valid (backend-specific)
|
||||||
*/
|
*/
|
||||||
export function readVersionCache(): VersionCache | null {
|
export function readVersionCache(backend: CLIProxyBackend = DEFAULT_BACKEND): VersionCache | null {
|
||||||
const cachePath = getVersionCachePath();
|
const cachePath = getVersionCachePath(backend);
|
||||||
if (!fs.existsSync(cachePath)) {
|
if (!fs.existsSync(cachePath)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -55,10 +55,13 @@ export function readVersionCache(): VersionCache | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write version to cache
|
* Write version to cache (backend-specific)
|
||||||
*/
|
*/
|
||||||
export function writeVersionCache(version: string): void {
|
export function writeVersionCache(
|
||||||
const cachePath = getVersionCachePath();
|
version: string,
|
||||||
|
backend: CLIProxyBackend = DEFAULT_BACKEND
|
||||||
|
): void {
|
||||||
|
const cachePath = getVersionCachePath(backend);
|
||||||
const cache: VersionCache = {
|
const cache: VersionCache = {
|
||||||
latestVersion: version,
|
latestVersion: version,
|
||||||
checkedAt: Date.now(),
|
checkedAt: Date.now(),
|
||||||
|
|||||||
@@ -17,7 +17,12 @@ import {
|
|||||||
GITHUB_API_ALL_RELEASES,
|
GITHUB_API_ALL_RELEASES,
|
||||||
VersionListResult,
|
VersionListResult,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { CLIPROXY_MAX_STABLE_VERSION, CLIPROXY_FAULTY_RANGE } from '../platform-detector';
|
import {
|
||||||
|
CLIPROXY_MAX_STABLE_VERSION,
|
||||||
|
CLIPROXY_FAULTY_RANGE,
|
||||||
|
DEFAULT_BACKEND,
|
||||||
|
} from '../platform-detector';
|
||||||
|
import type { CLIProxyBackend } from '../types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare semver versions (true if latest > current)
|
* Compare semver versions (true if latest > current)
|
||||||
@@ -72,16 +77,18 @@ export async function fetchLatestVersion(verbose = false): Promise<string> {
|
|||||||
/**
|
/**
|
||||||
* Check for updates by comparing installed version with latest release
|
* Check for updates by comparing installed version with latest release
|
||||||
* Uses cache to avoid hitting GitHub API on every run
|
* Uses cache to avoid hitting GitHub API on every run
|
||||||
|
* Cache is backend-specific to handle different repos for original vs plus
|
||||||
*/
|
*/
|
||||||
export async function checkForUpdates(
|
export async function checkForUpdates(
|
||||||
binPath: string,
|
binPath: string,
|
||||||
configVersion: string,
|
configVersion: string,
|
||||||
verbose = false
|
verbose = false,
|
||||||
|
backend: CLIProxyBackend = DEFAULT_BACKEND
|
||||||
): Promise<UpdateCheckResult> {
|
): Promise<UpdateCheckResult> {
|
||||||
const currentVersion = readInstalledVersion(binPath, configVersion);
|
const currentVersion = readInstalledVersion(binPath, configVersion);
|
||||||
|
|
||||||
// Try cache first
|
// Try cache first (backend-specific)
|
||||||
const cache = readVersionCache();
|
const cache = readVersionCache(backend);
|
||||||
if (cache) {
|
if (cache) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
console.error(`[cliproxy] Using cached version: ${cache.latestVersion}`);
|
console.error(`[cliproxy] Using cached version: ${cache.latestVersion}`);
|
||||||
@@ -98,7 +105,7 @@ export async function checkForUpdates(
|
|||||||
// Fetch from GitHub API
|
// Fetch from GitHub API
|
||||||
const latestVersion = await fetchLatestVersion(verbose);
|
const latestVersion = await fetchLatestVersion(verbose);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
writeVersionCache(latestVersion);
|
writeVersionCache(latestVersion, backend);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hasUpdate: isNewerVersion(latestVersion, currentVersion),
|
hasUpdate: isNewerVersion(latestVersion, currentVersion),
|
||||||
|
|||||||
@@ -353,8 +353,10 @@ export function useUpdateBackend() {
|
|||||||
api.cliproxyServer.updateBackend(backend, force),
|
api.cliproxyServer.updateBackend(backend, force),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
// Invalidate all queries that depend on backend setting
|
// Invalidate all queries that depend on backend setting
|
||||||
queryClient.invalidateQueries({ queryKey: ['cliproxy-update-check'] });
|
// Use refetchType: 'all' to force immediate refetch even if query is stale
|
||||||
queryClient.invalidateQueries({ queryKey: ['cliproxy-versions'] });
|
queryClient.invalidateQueries({ queryKey: ['cliproxy-update-check'], refetchType: 'all' });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['cliproxy-versions'], refetchType: 'all' });
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['cliproxy-server-config'], refetchType: 'all' });
|
||||||
queryClient.invalidateQueries({ queryKey: ['proxy-status'] });
|
queryClient.invalidateQueries({ queryKey: ['proxy-status'] });
|
||||||
queryClient.invalidateQueries({ queryKey: ['cliproxy-stats'] });
|
queryClient.invalidateQueries({ queryKey: ['cliproxy-stats'] });
|
||||||
toast.success('Backend updated');
|
toast.success('Backend updated');
|
||||||
|
|||||||
Reference in New Issue
Block a user