Fix update functionality and improve documentation

- Fixed update detection in install scripts
- Added Git availability checks to update system
- Improved error handling for update endpoint
- Added detailed Git requirements to README
- Added troubleshooting section for update issues

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-03-10 16:57:47 +00:00
parent 9b45e669e2
commit 2dcd4becef
8 changed files with 535 additions and 105 deletions

View File

@@ -50,13 +50,35 @@ function initSystemStatus() {
const testMode = localStorage.getItem('showUpdateButton') === 'true';
const url = testMode ? '/api/system/check-updates?test=true' : '/api/system/check-updates';
// Set a timeout to detect network issues
const timeoutId = setTimeout(() => {
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check timed out';
showNotification('Update check timed out. Please try again later.', 'warning');
}, 10000); // 10 second timeout
fetch(url, {
headers: authHeaders()
headers: authHeaders(),
// Add a fetch timeout as well
signal: AbortSignal.timeout(15000) // 15 second timeout (available in modern browsers)
})
.then(handleResponse)
.then(response => {
clearTimeout(timeoutId);
// Better error checking
if (!response.ok) {
return response.json().then(data => {
throw new Error(data.message || `Server error: ${response.status}`);
}).catch(e => {
if (e instanceof SyntaxError) {
throw new Error(`Server error: ${response.status}`);
}
throw e;
});
}
return response.json();
})
.then(data => {
if (data.status === 'success') {
if (data.data.updateAvailable) {
if (data.data && data.data.updateAvailable) {
updateStatusElement.innerHTML = '<i class="fas fa-exclamation-circle text-warning"></i> Update available';
updateAvailableDiv.classList.remove('d-none');
updateAvailableDiv.querySelector('span').textContent =
@@ -65,14 +87,24 @@ function initSystemStatus() {
updateStatusElement.innerHTML = '<i class="fas fa-check-circle text-success"></i> Up to date';
}
} else {
// Error status but with a response
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check failed';
showNotification(data.message || 'Failed to check for updates', 'danger');
}
})
.catch(error => {
clearTimeout(timeoutId);
console.error('Error checking for updates:', error);
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check failed';
showNotification('Failed to connect to server', 'danger');
// More specific error message based on the error type
if (error.name === 'AbortError') {
showNotification('Update check timed out. Please try again later.', 'warning');
} else if (error.message.includes('Failed to fetch') || error.message.includes('NetworkError')) {
showNotification('Network error. Please check your connection and try again.', 'danger');
} else {
showNotification(error.message || 'Failed to connect to server', 'danger');
}
});
}
@@ -88,19 +120,58 @@ function initSystemStatus() {
updateButton.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Updating...';
showNotification('Applying update. Please wait...', 'info');
// Set a timeout for the update process
const updateTimeoutId = setTimeout(() => {
updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now';
showNotification('Update process timed out. Please try again or check server logs.', 'warning');
}, 60000); // 60 second timeout for the entire update process
fetch('/api/system/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...authHeaders()
}
},
signal: AbortSignal.timeout(45000) // 45 second timeout
})
.then(handleResponse)
.then(response => {
// Better error checking
if (!response.ok) {
return response.json().then(data => {
throw new Error(data.message || `Server error: ${response.status}`);
}).catch(e => {
if (e instanceof SyntaxError) {
throw new Error(`Server error: ${response.status}`);
}
throw e;
});
}
return response.json();
})
.then(data => {
clearTimeout(updateTimeoutId);
if (data.status === 'success') {
showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success');
// Show a countdown to reload
let secondsLeft = 30;
updateButton.innerHTML = `<i class="fas fa-sync"></i> Reloading in ${secondsLeft}s...`;
const countdownInterval = setInterval(() => {
secondsLeft--;
updateButton.innerHTML = `<i class="fas fa-sync"></i> Reloading in ${secondsLeft}s...`;
if (secondsLeft <= 0) {
clearInterval(countdownInterval);
window.location.reload();
}
}, 1000);
// Set a timer to reload the page after the service has time to restart
setTimeout(() => {
clearInterval(countdownInterval);
window.location.reload();
}, 30000);
} else {
@@ -110,10 +181,19 @@ function initSystemStatus() {
}
})
.catch(error => {
clearTimeout(updateTimeoutId);
console.error('Error applying update:', error);
updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now';
showNotification('Failed to connect to server', 'danger');
// More specific error message based on the error type
if (error.name === 'AbortError') {
showNotification('Update request timed out. The server might still be processing the update.', 'warning');
} else if (error.message.includes('Failed to fetch') || error.message.includes('NetworkError')) {
showNotification('Network error. Please check your connection and try again.', 'danger');
} else {
showNotification(error.message || 'Failed to connect to server', 'danger');
}
});
}