mirror of
https://github.com/adelatour11/codebarr.git
synced 2025-12-27 10:10:03 -06:00
Enhance album add process and add countdown reset
Refactor album addition process to improve error handling and add countdown reset functionality.
This commit is contained in:
@@ -219,17 +219,17 @@
|
||||
|
||||
// --- ADD ALBUM TO LIDARR ---
|
||||
document.getElementById('add-album-btn').addEventListener('click', async () => {
|
||||
if (!currentBarcode) return;
|
||||
const addBtn = document.getElementById('add-album-btn');
|
||||
addBtn.disabled = true;
|
||||
updateStatus("Starting album add process...");
|
||||
updateProgress(0);
|
||||
if (!currentBarcode) return;
|
||||
const addBtn = document.getElementById('add-album-btn');
|
||||
addBtn.disabled = true;
|
||||
updateStatus("Starting album add process...");
|
||||
updateProgress(0);
|
||||
|
||||
try {
|
||||
try {
|
||||
const response = await fetch("/submit", {
|
||||
method: "POST",
|
||||
headers: {'Content-Type':'application/x-www-form-urlencoded'},
|
||||
body: `barcode=${currentBarcode}`
|
||||
method: "POST",
|
||||
headers: {'Content-Type':'application/x-www-form-urlencoded'},
|
||||
body: `barcode=${currentBarcode}`
|
||||
});
|
||||
|
||||
const reader = response.body.getReader();
|
||||
@@ -237,35 +237,48 @@
|
||||
let buffer = "";
|
||||
|
||||
await reader.read().then(function process({done, value}) {
|
||||
if (done) return;
|
||||
buffer += decoder.decode(value, {stream:true});
|
||||
const lines = buffer.split("\n\n");
|
||||
buffer = lines.pop();
|
||||
for (const line of lines) {
|
||||
if (done) return;
|
||||
buffer += decoder.decode(value, {stream:true});
|
||||
const lines = buffer.split("\n\n");
|
||||
buffer = lines.pop();
|
||||
for (const line of lines) {
|
||||
if (line.trim()) {
|
||||
try {
|
||||
try {
|
||||
const data = JSON.parse(line);
|
||||
updateStatus(data.status);
|
||||
updateProgress(data.progress);
|
||||
} catch(e) {
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return reader.read().then(process);
|
||||
}
|
||||
}
|
||||
return reader.read().then(process);
|
||||
});
|
||||
|
||||
updateStatus("✅ Album processed");
|
||||
} catch(err) {
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
updateStatus("❌ Error adding album");
|
||||
} finally {
|
||||
resetScanner();
|
||||
} finally {
|
||||
addBtn.disabled = false;
|
||||
startScanner();
|
||||
}
|
||||
startCountdownReset(5); // Start 5-second countdown
|
||||
}
|
||||
});
|
||||
|
||||
function startCountdownReset(seconds) {
|
||||
let remaining = seconds;
|
||||
const countdownInterval = setInterval(() => {
|
||||
updateStatus(`Resetting in ${remaining}...`);
|
||||
remaining--;
|
||||
if (remaining < 0) {
|
||||
clearInterval(countdownInterval);
|
||||
resetScanner();
|
||||
startScanner(); // Restart the scanner after reset
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
||||
// --- STOP APP ---
|
||||
document.getElementById("stop-app-btn").addEventListener("click", () => {
|
||||
if(confirm("Are you sure you want to stop Codebarr?")) {
|
||||
|
||||
Reference in New Issue
Block a user