2025-02-21 10:35:52 +01:00
|
|
|
<!DOCTYPE html>
|
2025-02-18 12:28:47 +01:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2025-02-21 10:35:52 +01:00
|
|
|
<title>FilaMan - Firmware Update</title>
|
2025-02-18 12:28:47 +01:00
|
|
|
<link rel="stylesheet" href="style.css">
|
2025-02-21 11:53:59 +01:00
|
|
|
<script>
|
|
|
|
fetch('/api/version')
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
const versionSpan = document.querySelector('.version');
|
|
|
|
if (versionSpan) {
|
|
|
|
versionSpan.textContent = 'v' + data.version;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => console.error('Error fetching version:', error));
|
|
|
|
</script>
|
2025-02-18 12:28:47 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="navbar">
|
|
|
|
<div style="display: flex; align-items: center; gap: 2rem;">
|
|
|
|
<img src="/logo.png" alt="FilaMan Logo" class="logo">
|
|
|
|
<div class="logo-text">
|
2025-02-21 11:53:59 +01:00
|
|
|
<h1>FilaMan<span class="version"></span></h1>
|
2025-02-18 12:28:47 +01:00
|
|
|
<h4>Filament Management Tool</h4>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<nav style="display: flex; gap: 1rem;">
|
|
|
|
<a href="/">Start</a>
|
|
|
|
<a href="/waage">Scale</a>
|
|
|
|
<a href="/spoolman">Spoolman/Bambu</a>
|
|
|
|
<a href="/about">About</a>
|
|
|
|
<a href="/upgrade">Upgrade</a>
|
|
|
|
</nav>
|
|
|
|
<div class="status-container">
|
|
|
|
<div class="status-item">
|
|
|
|
<span class="status-dot" id="bambuDot"></span>B
|
|
|
|
</div>
|
|
|
|
<div class="status-item">
|
|
|
|
<span class="status-dot" id="spoolmanDot"></span>S
|
|
|
|
</div>
|
|
|
|
<div class="ram-status" id="ramStatus"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-02-21 11:53:59 +01:00
|
|
|
</body>
|
|
|
|
</html>
|
2025-02-18 12:28:47 +01:00
|
|
|
|
|
|
|
<!-- head -->
|
|
|
|
|
|
|
|
<div class="content">
|
2025-02-21 11:57:19 +01:00
|
|
|
<h1>System Update</h1>
|
2025-02-18 12:28:47 +01:00
|
|
|
<div class="warning">
|
2025-02-21 10:35:52 +01:00
|
|
|
<strong>Warning:</strong> Do not power off the device during update.
|
2025-02-18 12:28:47 +01:00
|
|
|
</div>
|
|
|
|
|
2025-02-21 11:57:19 +01:00
|
|
|
<div class="update-options">
|
|
|
|
<div class="update-section">
|
|
|
|
<h2>Firmware Update</h2>
|
|
|
|
<p>Upload a new firmware file (filaman_*.bin)</p>
|
|
|
|
<div class="update-form">
|
|
|
|
<form id="firmwareForm" enctype='multipart/form-data' data-type="firmware">
|
|
|
|
<input type='file' name='update' accept='.bin' required>
|
|
|
|
<input type='submit' value='Start Firmware Update'>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-02-18 12:28:47 +01:00
|
|
|
|
2025-02-21 11:57:19 +01:00
|
|
|
<div class="update-section">
|
|
|
|
<h2>Webpage Update</h2>
|
|
|
|
<p>Upload a new webpage file (webpage_*.bin)</p>
|
|
|
|
<div class="update-form">
|
|
|
|
<form id="webpageForm" enctype='multipart/form-data' data-type="webpage">
|
|
|
|
<input type='file' name='update' accept='.bin' required>
|
|
|
|
<input type='submit' value='Start Webpage Update'>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-02-18 12:28:47 +01:00
|
|
|
</div>
|
2025-02-21 10:35:52 +01:00
|
|
|
|
2025-02-21 11:57:19 +01:00
|
|
|
<div class="progress-container" style="display: none;">
|
|
|
|
<div class="progress-bar">0%</</div>
|
2025-02-18 12:28:47 +01:00
|
|
|
</div>
|
|
|
|
<div class="status"></div>
|
|
|
|
</div>
|
|
|
|
|
2025-02-21 11:57:19 +01:00
|
|
|
<style>
|
|
|
|
.update-options {
|
|
|
|
display: flex;
|
|
|
|
gap: 2rem;
|
|
|
|
margin: 2rem 0;
|
|
|
|
}
|
|
|
|
.update-section {
|
|
|
|
flex: 1;
|
|
|
|
background: #f5f5f5;
|
|
|
|
padding: 1.5rem;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
.update-section h2 {
|
|
|
|
margin-top: 0;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
.update-section p {
|
|
|
|
color: #666;
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2025-02-18 12:28:47 +01:00
|
|
|
<script>
|
2025-02-18 14:18:14 +01:00
|
|
|
// Hide status indicators during update
|
|
|
|
const statusContainer = document.querySelector('.status-container');
|
|
|
|
if (statusContainer) {
|
|
|
|
statusContainer.style.display = 'none';
|
2025-02-21 09:24:54 +01:00
|
|
|
}
|
|
|
|
|
2025-02-21 11:57:19 +01:00
|
|
|
function handleUpdate(e) {
|
2025-02-18 12:28:47 +01:00
|
|
|
e.preventDefault();
|
|
|
|
const file = form.update.files[0];
|
2025-02-21 11:57:19 +01:00
|
|
|
const updateType = form.dataset.type;
|
|
|
|
|
2025-02-18 14:18:14 +01:00
|
|
|
if (!file) {
|
2025-02-21 11:57:19 +01:00
|
|
|
alert('Please select a file.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate file name pattern
|
|
|
|
if (updateType === 'firmware' && !file.name.startsWith('filaman_')) {
|
|
|
|
alert('Please select a valid firmware file (filaman_*.bin)');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (updateType === 'webpage' && !file.name.startsWith('webpage_')) {
|
|
|
|
alert('Please select a valid webpage file (webpage_*.bin)');
|
2025-02-21 09:24:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-02-21 10:35:52 +01:00
|
|
|
log(`Selected file: ${file.name} (${file.size} bytes)`);
|
2025-02-18 12:28:47 +01:00
|
|
|
|
2025-02-21 10:35:52 +01:00
|
|
|
// Aktiviere Fortschrittsanzeige
|
|
|
|
progress.style.display = 'block';
|
|
|
|
form.style.display = 'none';
|
2025-02-18 12:28:47 +01:00
|
|
|
|
2025-02-21 10:35:52 +01:00
|
|
|
// Erstelle FormData für den Upload
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('update', file);
|
2025-02-21 11:57:19 +01:00
|
|
|
|
2025-02-18 12:28:47 +01:00
|
|
|
const progress = document.querySelector('.progress-bar');
|
|
|
|
const progressContainer = document.querySelector('.progress-container');
|
|
|
|
const status = document.querySelector('.status');
|
|
|
|
|
|
|
|
progressContainer.style.display = 'block';
|
|
|
|
status.style.display = 'none';
|
|
|
|
status.className = 'status';
|
2025-02-21 11:57:19 +01:00
|
|
|
|
|
|
|
// Disable both forms during update
|
|
|
|
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = true);
|
2025-02-21 09:24:54 +01:00
|
|
|
|
2025-02-18 12:28:47 +01:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', '/update', true);
|
|
|
|
xhr.upload.onprogress = (e) => {
|
|
|
|
if (e.lengthComputable) {
|
|
|
|
const percentComplete = (e.loaded / e.total) * 100;
|
|
|
|
progress.style.width = percentComplete + '%';
|
|
|
|
progress.textContent = Math.round(percentComplete) + '%';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
try {
|
|
|
|
let response = this.responseText;
|
|
|
|
try {
|
|
|
|
const jsonResponse = JSON.parse(response);
|
|
|
|
response = jsonResponse.message;
|
|
|
|
|
|
|
|
if (jsonResponse.restart) {
|
2025-02-18 14:18:14 +01:00
|
|
|
status.textContent = response + " Redirecting in 20 seconds...";
|
|
|
|
let countdown = 20;
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
countdown--;
|
|
|
|
if (countdown <= 0) {
|
|
|
|
clearInterval(timer);
|
|
|
|
window.location.href = '/';
|
|
|
|
} else {
|
|
|
|
status.textContent = response + ` Redirecting in ${countdown} seconds...`;
|
|
|
|
}
|
|
|
|
}, 1000);
|
2025-02-18 12:28:47 +01:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
if (!isNaN(response)) {
|
|
|
|
const percent = parseInt(response);
|
|
|
|
progress.style.width = percent + '%';
|
|
|
|
progress.textContent = percent + '%';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status.textContent = response;
|
|
|
|
status.classList.add(xhr.status === 200 ? 'success' : 'error');
|
|
|
|
status.style.display = 'block';
|
|
|
|
|
|
|
|
if (xhr.status !== 200) {
|
2025-02-21 11:57:19 +01:00
|
|
|
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = false);
|
2025-02-18 12:28:47 +01:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2025-02-18 14:18:14 +01:00
|
|
|
status.textContent = 'Error: ' + error.message;
|
2025-02-18 12:28:47 +01:00
|
|
|
status.classList.add('error');
|
|
|
|
status.style.display = 'block';
|
2025-02-21 11:57:19 +01:00
|
|
|
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = false);
|
2025-02-21 10:35:52 +01:00
|
|
|
}
|
2025-02-18 12:28:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
xhr.onerror = function() {
|
2025-02-18 14:18:14 +01:00
|
|
|
status.textContent = 'Update failed: Network error';
|
2025-02-18 12:28:47 +01:00
|
|
|
status.classList.add('error');
|
|
|
|
status.style.display = 'block';
|
2025-02-21 11:57:19 +01:00
|
|
|
document.querySelectorAll('form input[type=submit]').forEach(btn => btn.disabled = false);
|
2025-02-18 12:28:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
xhr.send(formData);
|
2025-02-21 11:57:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('firmwareForm').addEventListener('submit', handleUpdate);
|
|
|
|
document.getElementById('webpageForm').addEventListener('submit', handleUpdate);
|
2025-02-18 12:28:47 +01:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|