Add update testing functionality

- Add test mode for simulating available updates
- Implement a toggle to enable/disable test mode
- Add test parameter to check-updates endpoint
- Clean up debugging comments
- Create subtle testing UI controls

This enables testing the update functionality without needing
to create a new higher version in the repository.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-05 00:12:17 +00:00
parent 7c7697c2cd
commit 7041d59267
4 changed files with 200 additions and 1 deletions

View File

@ -625,6 +625,21 @@ header {
font-size: 0.875rem;
}
/* Testing Controls */
.testing-controls {
opacity: 0.5;
font-size: 0.8rem;
}
.testing-controls:hover {
opacity: 1;
}
.testing-controls a {
text-decoration: underline;
color: var(--text-color);
}
/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }

View File

@ -133,6 +133,10 @@
<i class="fas fa-circle-notch fa-spin"></i> Checking...
</span>
</div>
<!-- Testing Controls (hidden in production) -->
<div class="mt-2 testing-controls">
<small><a href="#" id="toggle-test-update-button">Toggle Test Update</a></small>
</div>
<div id="update-available" class="mt-3 d-none">
<div class="alert alert-info">
<i class="fas fa-arrow-circle-up"></i>

163
public/js/system-status.js Normal file
View File

@ -0,0 +1,163 @@
/**
* Transmission RSS Manager - System Status Module
* @description Functionality for system status display and updates
*/
// System status and updates functionality
function initSystemStatus() {
// Elements
const versionElement = document.getElementById('system-version');
const uptimeElement = document.getElementById('uptime');
const transmissionStatusElement = document.getElementById('transmission-status');
const updateStatusElement = document.getElementById('update-status');
const updateAvailableDiv = document.getElementById('update-available');
const updateButton = document.getElementById('btn-update-now');
const refreshButton = document.getElementById('btn-refresh-status');
// Load system status
function loadSystemStatus() {
fetch('/api/system/status', {
headers: authHeaders()
})
.then(handleResponse)
.then(data => {
if (data.status === 'success') {
versionElement.textContent = data.data.version;
uptimeElement.textContent = data.data.uptime;
// Update transmission status with icon
if (data.data.transmissionStatus === 'Connected') {
transmissionStatusElement.innerHTML = '<i class="fas fa-check-circle text-success"></i> Connected';
} else {
transmissionStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Disconnected';
}
} else {
showNotification('Failed to load system status', 'danger');
}
})
.catch(error => {
console.error('Error fetching system status:', error);
showNotification('Failed to connect to server', 'danger');
});
}
// Check for updates
function checkForUpdates() {
updateStatusElement.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Checking...';
updateAvailableDiv.classList.add('d-none');
// Add test=true parameter to force update availability for testing
const testMode = localStorage.getItem('showUpdateButton') === 'true';
const url = testMode ? '/api/system/check-updates?test=true' : '/api/system/check-updates';
fetch(url, {
headers: authHeaders()
})
.then(handleResponse)
.then(data => {
if (data.status === 'success') {
if (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 =
`A new version is available: ${data.data.currentVersion}${data.data.remoteVersion}`;
} else {
updateStatusElement.innerHTML = '<i class="fas fa-check-circle text-success"></i> Up to date';
}
} else {
updateStatusElement.innerHTML = '<i class="fas fa-times-circle text-danger"></i> Check failed';
showNotification(data.message || 'Failed to check for updates', 'danger');
}
})
.catch(error => {
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');
});
}
// Apply update
function applyUpdate() {
// Show confirmation dialog
if (!confirm('Are you sure you want to update the application? The service will restart.')) {
return;
}
// Show loading state
updateButton.disabled = true;
updateButton.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i> Updating...';
showNotification('Applying update. Please wait...', 'info');
fetch('/api/system/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...authHeaders()
}
})
.then(handleResponse)
.then(data => {
if (data.status === 'success') {
showNotification('Update applied successfully. The page will reload in 30 seconds.', 'success');
// Set a timer to reload the page after the service has time to restart
setTimeout(() => {
window.location.reload();
}, 30000);
} else {
updateButton.disabled = false;
updateButton.innerHTML = '<i class="fas fa-download"></i> Update Now';
showNotification(data.message || 'Failed to apply update', 'danger');
}
})
.catch(error => {
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');
});
}
// Event listeners
if (refreshButton) {
refreshButton.addEventListener('click', () => {
loadSystemStatus();
checkForUpdates();
});
}
if (updateButton) {
updateButton.addEventListener('click', applyUpdate);
}
// Test mode toggle (for developers)
const testToggle = document.getElementById('toggle-test-update-button');
if (testToggle) {
// Initialize based on current localStorage setting
const isTestMode = localStorage.getItem('showUpdateButton') === 'true';
// Update toggle text
testToggle.innerText = isTestMode ? 'Disable Test Update' : 'Enable Test Update';
// Add click handler
testToggle.addEventListener('click', (e) => {
e.preventDefault();
const currentSetting = localStorage.getItem('showUpdateButton') === 'true';
const newSetting = !currentSetting;
localStorage.setItem('showUpdateButton', newSetting);
testToggle.innerText = newSetting ? 'Disable Test Update' : 'Enable Test Update';
// Re-check for updates with new setting
checkForUpdates();
showNotification(`Test update button ${newSetting ? 'enabled' : 'disabled'}`, 'info');
});
}
// Initialize
loadSystemStatus();
checkForUpdates();
// Set interval to refresh uptime every minute
setInterval(loadSystemStatus, 60000);
}

View File

@ -64,7 +64,24 @@ app.get('/api/system/check-updates', async (req, res) => {
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
const currentVersion = packageJson.version;
// Fetch latest updates without applying them
// Check for test mode flag which forces update availability for testing
const testMode = req.query.test === 'true';
if (testMode) {
// In test mode, always return that an update is available
return res.json({
status: 'success',
data: {
updateAvailable: true,
currentVersion,
remoteVersion: '2.1.0-test',
commitsBehind: 1,
testMode: true
}
});
}
// Normal mode - fetch latest updates without applying them
await execAsync('git fetch');
// Check if we're behind the remote repository