Fix update status handling with cache busting and better response parsing

- Added detection of 'already have the latest version' scenario
- Implemented proper handling when no update is available with friendly message
- Added cache busting parameters to ensure fresh data from server
- Enhanced test mode toggle to properly check real update status
- Added specific handling for the case where update script runs but no update is needed
- Improved logging to show actual update check response
- Modified reload mechanics to force cache refresh with timestamp parameter
- Added special handling to avoid unnecessary page reloads

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-10 18:30:40 +00:00
parent 467979971a
commit 8589a0833e

View File

@ -16,7 +16,9 @@ function initSystemStatus() {
// Load system status // Load system status
function loadSystemStatus() { function loadSystemStatus() {
fetch('/api/system/status', { // Add cache-busting parameter
const cacheBuster = `?_=${new Date().getTime()}`;
fetch('/api/system/status' + cacheBuster, {
headers: authHeaders() headers: authHeaders()
}) })
.then(handleResponse) .then(handleResponse)
@ -214,7 +216,10 @@ function initSystemStatus() {
// Add test=true parameter to force update availability for testing // Add test=true parameter to force update availability for testing
const testMode = localStorage.getItem('showUpdateButton') === 'true'; const testMode = localStorage.getItem('showUpdateButton') === 'true';
const url = testMode ? '/api/system/check-updates?test=true' : '/api/system/check-updates'; const cacheBuster = `_=${new Date().getTime()}`;
const url = testMode
? `/api/system/check-updates?test=true&${cacheBuster}`
: `/api/system/check-updates?${cacheBuster}`;
// Set a timeout to detect network issues // Set a timeout to detect network issues
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
@ -375,9 +380,34 @@ function initSystemStatus() {
clearTimeout(updateTimeoutId); clearTimeout(updateTimeoutId);
if (data.status === 'success') { if (data.status === 'success') {
// Hide update notification immediately after successful update // Check if there's an update message to determine if an update was actually applied
const updateApplied = data.message && data.message.includes('Update applied successfully');
const noNewUpdate = data.data && data.data.output && data.data.output.includes('already have the latest version');
// Hide update notification
hideUpdateAlert(); hideUpdateAlert();
if (noNewUpdate) {
// If no update was needed, show a different message
showNotification('You already have the latest version. No update was needed.', 'info');
// Re-enable both buttons
if (updateButton) {
updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Check Again';
}
const floatingButton = document.getElementById('floating-update-button');
if (floatingButton) {
floatingButton.disabled = false;
floatingButton.textContent = 'Check Again';
}
// Update page to show current version without reloading
loadSystemStatus();
return;
}
// Show success notification // Show success notification
showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success'); showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success');
@ -415,7 +445,7 @@ function initSystemStatus() {
localStorage.removeItem(REMOTE_VERSION_KEY); localStorage.removeItem(REMOTE_VERSION_KEY);
// Force a clean reload // Force a clean reload
window.location.href = window.location.href.split('#')[0]; window.location.href = window.location.href.split('#')[0] + '?t=' + new Date().getTime();
} }
}, 1000); }, 1000);
@ -428,8 +458,8 @@ function initSystemStatus() {
localStorage.removeItem(CURRENT_VERSION_KEY); localStorage.removeItem(CURRENT_VERSION_KEY);
localStorage.removeItem(REMOTE_VERSION_KEY); localStorage.removeItem(REMOTE_VERSION_KEY);
// Force a clean reload // Force a clean reload with cache-busting parameter
window.location.href = window.location.href.split('#')[0]; window.location.href = window.location.href.split('#')[0] + '?t=' + new Date().getTime();
}, 30000); }, 30000);
} else { } else {
// Enable both buttons on failure // Enable both buttons on failure
@ -512,7 +542,22 @@ function initSystemStatus() {
} else { } else {
// If disabling test mode, check for real updates // If disabling test mode, check for real updates
hideUpdateAlert(); hideUpdateAlert();
checkForUpdates();
// Force a check without the test parameter to get real status
const realCheckUrl = '/api/system/check-updates';
fetch(realCheckUrl, { headers: authHeaders() })
.then(response => response.json())
.then(data => {
console.log('Real update check result:', data);
if (data.status === 'success' && data.data && !data.data.updateAvailable) {
showNotification('No actual updates are available.', 'info');
} else if (data.status === 'success' && data.data && data.data.updateAvailable) {
showUpdateAlert(data.data.currentVersion, data.data.remoteVersion);
showNotification(`A real update is available: ${data.data.currentVersion}${data.data.remoteVersion}`, 'info');
}
})
.catch(error => console.error('Error checking for real updates:', error));
showNotification('Test update button disabled', 'info'); showNotification('Test update button disabled', 'info');
} }
}); });