mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-03-12 17:21:19 +08:00
refactor: update version check logic and response handling
This commit is contained in:
@@ -6,13 +6,10 @@ import { VersionCheckModal } from './VersionCheckModal';
|
|||||||
interface VersionData {
|
interface VersionData {
|
||||||
currentVersion: string;
|
currentVersion: string;
|
||||||
latestVersion: string;
|
latestVersion: string;
|
||||||
updateAvailable: boolean;
|
hasUpdate: boolean;
|
||||||
}
|
packageName?: string;
|
||||||
|
updateCommand?: string;
|
||||||
interface VersionCheckResponse {
|
checkedAt?: string;
|
||||||
success: boolean;
|
|
||||||
data?: VersionData;
|
|
||||||
error?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,30 +39,26 @@ export function VersionCheck() {
|
|||||||
const checkVersion = async (silent = false) => {
|
const checkVersion = async (silent = false) => {
|
||||||
if (!silent) setChecking(true);
|
if (!silent) setChecking(true);
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/config/version');
|
const response = await fetch('/api/version-check');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: VersionCheckResponse = await response.json();
|
const data: VersionData = await response.json();
|
||||||
|
|
||||||
// Validate response structure
|
// Validate response structure
|
||||||
if (!data || typeof data !== 'object') {
|
if (!data || typeof data !== 'object') {
|
||||||
throw new Error('Invalid response format');
|
throw new Error('Invalid response format');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.currentVersion) {
|
||||||
throw new Error(data.error || 'Version check failed');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!data.data || typeof data.data !== 'object') {
|
|
||||||
throw new Error('Invalid version data in response');
|
throw new Error('Invalid version data in response');
|
||||||
}
|
}
|
||||||
|
|
||||||
setVersionData(data.data);
|
setVersionData(data);
|
||||||
|
|
||||||
if (data.data.updateAvailable && !silent) {
|
if (data.hasUpdate && !silent) {
|
||||||
toast.info('新版本可用: ' + data.data.latestVersion);
|
toast.info('新版本可用: ' + data.latestVersion);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Version check failed:', error);
|
console.error('Version check failed:', error);
|
||||||
@@ -98,7 +91,7 @@ export function VersionCheck() {
|
|||||||
localStorage.setItem('ccw.autoUpdate', JSON.stringify(enabled));
|
localStorage.setItem('ccw.autoUpdate', JSON.stringify(enabled));
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!versionData?.updateAvailable) {
|
if (!versionData?.hasUpdate) {
|
||||||
return null; // Don't show anything if no update
|
return null; // Don't show anything if no update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user