check for doubles

This commit is contained in:
2026-05-10 23:02:59 +02:00
parent 2034bd5f2b
commit 09afe40f04
3 changed files with 97 additions and 8 deletions
+45 -2
View File
@@ -4,16 +4,23 @@
{% block content %}
<div class="page-header">
<h1>Duplicate books in Calibre-Web</h1>
{% if groups %}
<div class="header-actions">
<button class="btn btn-danger" onclick="deleteAll(this)">Delete all duplicates (keep oldest)</button>
</div>
{% endif %}
</div>
<div id="dedup-progress" style="display:none" class="alert alert-success"></div>
{% if error %}
<div class="alert alert-warning">Could not fetch books from Calibre-Web: {{ error }}</div>
{% else %}
<p class="muted small" style="margin-bottom:1.5rem">
Scanned <strong>{{ total_books }}</strong> book(s) —
{% if groups %}
found <strong>{{ groups|length }}</strong> duplicate group(s).
Books are grouped by normalised title. Keep the one you want and delete the rest.
found <strong>{{ groups|length }}</strong> duplicate group(s) (same title + author).
The oldest copy (lowest ID) is kept when deleting all.
{% else %}
no duplicates found.
{% endif %}
@@ -77,5 +84,41 @@ async function deleteBook(id, btn) {
status.textContent = 'Error: ' + e;
}
}
async function deleteAll(btn) {
if (!confirm('Delete all duplicates from Calibre-Web, keeping the oldest copy of each title+author? This cannot be undone.')) return;
btn.disabled = true;
btn.textContent = 'Starting…';
const progress = document.getElementById('dedup-progress');
progress.style.display = '';
progress.textContent = 'Fetching book list from Calibre-Web…';
await fetch('/api/delete_duplicates', {method: 'POST'});
const poll = setInterval(async () => {
const r = await fetch('/api/delete_duplicates/status');
const s = await r.json();
if (s.error) {
clearInterval(poll);
progress.textContent = 'Error: ' + s.error;
progress.className = 'alert alert-warning';
btn.disabled = false;
btn.textContent = 'Delete all duplicates (keep oldest)';
return;
}
if (s.total > 0) {
progress.textContent = `Deleting… ${s.deleted} / ${s.total} deleted, ${s.failed} failed`;
} else {
progress.textContent = 'Scanning for duplicates…';
}
if (s.done) {
clearInterval(poll);
progress.textContent = `Done — ${s.deleted} book(s) deleted, ${s.failed} failed. Reload to refresh the list.`;
btn.textContent = 'Reload';
btn.disabled = false;
btn.onclick = () => location.reload();
}
}, 2000);
}
</script>
{% endblock %}