feat: Add Batch Recovery button

This commit is contained in:
wander 2026-01-05 08:06:52 -05:00
parent 4476779adb
commit 3186dfb942

View file

@ -245,8 +245,12 @@
<div class="tab-content">
<!-- Unindexed Files -->
<div class="tab-pane fade show active" id="tab-unindexed">
<p class="text-muted small">Files found on disk but missing from TubeArchivist. Recover
them to restore your library.</p>
<div class="d-flex justify-content-between align-items-center mb-2">
<p class="text-muted small mb-0">Files found on disk but missing from TubeArchivist.
Recover them to restore your library.</p>
<button class="btn btn-sm btn-success" onclick="recoverAll('unindexed')"><i
class="bi bi-collection-play"></i> Recover All</button>
</div>
<div class="table-responsive" style="max-height: 400px;">
<table class="table table-dark table-striped table-hover mb-0">
<thead>
@ -744,6 +748,45 @@
document.getElementById('status-filter').addEventListener('change', () => {
fetchStatus();
});
async function recoverAll(type) {
if (!confirm("Are you sure you want to BATCH RECOVER all items in '" + type + "'?\n\nThis will process them one by one. Please do not close this tab.")) return;
const tbody = document.getElementById('tbody-' + type);
// Select all buttons that trigger recovery
const buttons = Array.from(tbody.querySelectorAll('button[onclick*="startRecovery"]'));
if (buttons.length === 0) {
alert("No items to recover!");
return;
}
let successCount = 0;
for (const btn of buttons) {
if (btn.disabled) continue; // Skip if already processing
// Visual scroll to item
btn.scrollIntoView({ behavior: 'smooth', block: 'center' });
// Parse the path
const onClickText = btn.getAttribute('onclick');
const match = onClickText.match(/startRecovery\('(.+?)'/);
if (match) {
const path = match[1];
try {
await startRecovery(path, btn);
successCount++;
} catch (e) {
console.error("Batch error for " + path, e);
}
// Pace it
await new Promise(r => setTimeout(r, 500));
}
}
alert("Batch Complete! Processed: " + buttons.length);
}
</script>
</body>