cwa import
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Books — CalibreSync{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h1>Books <span class="muted">({{ total }})</span></h1>
|
||||
</div>
|
||||
|
||||
{% if books %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Status</th>
|
||||
<th>Source zip</th>
|
||||
<th>Uploaded</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for b in books %}
|
||||
<tr>
|
||||
<td>{{ b.filename }}</td>
|
||||
<td><span class="badge badge-{{ b.status }}">{{ b.status }}</span></td>
|
||||
<td class="mono small muted">{{ b.zip_source or "—" }}</td>
|
||||
<td>{{ b.uploaded_at[:19].replace("T"," ") if b.uploaded_at else "—" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if pages > 1 %}
|
||||
<div class="pagination">
|
||||
{% if page > 1 %}
|
||||
<a href="/books?page={{ page - 1 }}">« Prev</a>
|
||||
{% endif %}
|
||||
<span>Page {{ page }} of {{ pages }}</span>
|
||||
{% if page < pages %}
|
||||
<a href="/books?page={{ page + 1 }}">Next »</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p class="muted">No books recorded yet.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -1,124 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Duplicates — CalibreSync{% endblock %}
|
||||
|
||||
{% 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) (same title + author).
|
||||
The oldest copy (lowest ID) is kept when deleting all.
|
||||
{% else %}
|
||||
no duplicates found.
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
{% for group in groups %}
|
||||
<div class="form-section" style="margin-bottom:1rem">
|
||||
<h3 style="margin-top:0">{{ group[0].title }}</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Title</th>
|
||||
<th>Authors</th>
|
||||
<th>Format</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for book in group %}
|
||||
<tr id="row-{{ book.id }}">
|
||||
<td class="mono muted">{{ book.id }}</td>
|
||||
<td>{{ book.title }}</td>
|
||||
<td>{{ book.authors }}</td>
|
||||
<td>{{ book.format or "—" }}</td>
|
||||
<td>
|
||||
<button class="btn btn-danger" style="padding:0.2rem 0.7rem;font-size:0.85rem"
|
||||
onclick="deleteBook({{ book.id }}, this)">Delete</button>
|
||||
<span id="status-{{ book.id }}" class="muted small" style="margin-left:0.5rem"></span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
async function deleteBook(id, btn) {
|
||||
if (!confirm('Delete book ID ' + id + ' from Calibre-Web?')) return;
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Deleting…';
|
||||
const status = document.getElementById('status-' + id);
|
||||
try {
|
||||
const r = await fetch('/api/delete_book/' + id, {method: 'POST'});
|
||||
const data = await r.json();
|
||||
if (data.ok) {
|
||||
document.getElementById('row-' + id).style.opacity = '0.35';
|
||||
btn.textContent = 'Deleted';
|
||||
status.textContent = '✓';
|
||||
} else {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Delete';
|
||||
status.textContent = 'Failed: ' + data.message;
|
||||
status.style.color = 'var(--error, #f87171)';
|
||||
}
|
||||
} catch (e) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Delete';
|
||||
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 %}
|
||||
+4
-14
@@ -59,16 +59,8 @@
|
||||
<div class="stat-label">Zip archives processed</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">{{ stats.uploaded }}</div>
|
||||
<div class="stat-label">Books uploaded</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">{{ stats.skipped }}</div>
|
||||
<div class="stat-label">Duplicates skipped</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-value">{{ stats.total_books }}</div>
|
||||
<div class="stat-label">Total book records</div>
|
||||
<div class="stat-value">{{ stats.total_imported }}</div>
|
||||
<div class="stat-label">Books imported</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -81,8 +73,7 @@
|
||||
<th>Finished</th>
|
||||
<th>Status</th>
|
||||
<th>New zips</th>
|
||||
<th>Uploaded</th>
|
||||
<th>Skipped</th>
|
||||
<th>Imported</th>
|
||||
<th>Errors</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -93,8 +84,7 @@
|
||||
<td>{{ r.finished_at[:19].replace("T"," ") if r.finished_at else "—" }}</td>
|
||||
<td><span class="badge badge-{{ r.status }}">{{ r.status }}</span></td>
|
||||
<td>{{ r.zips_new }}</td>
|
||||
<td>{{ r.books_uploaded }}</td>
|
||||
<td>{{ r.books_skipped }}</td>
|
||||
<td>{{ r.books_imported }}</td>
|
||||
<td>{{ r.books_errored }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
+11
-30
@@ -84,39 +84,20 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="form-section">
|
||||
<h2>Calibre-Web</h2>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="calibre_url">URL</label>
|
||||
<input id="calibre_url" name="calibre_url" type="url" placeholder="http://localhost:8083"
|
||||
value="{{ s.get('calibre_url','') }}">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="calibre_user">Username</label>
|
||||
<input id="calibre_user" name="calibre_user" type="text" value="{{ s.get('calibre_user','') }}">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="calibre_pass">Password</label>
|
||||
<input id="calibre_pass" name="calibre_pass" type="password"
|
||||
value="{{ s.get('calibre_pass','') }}">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<button type="button" class="btn btn-secondary" onclick="testConn('calibre', this)">Test Calibre-Web connection</button>
|
||||
<p id="test-calibre-result" class="test-result"></p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="form-section">
|
||||
<h2>Local</h2>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="local_work_dir">Work directory</label>
|
||||
<input id="local_work_dir" name="local_work_dir" type="text" placeholder="/tmp/calibresync"
|
||||
value="{{ s.get('local_work_dir','/tmp/calibresync') }}">
|
||||
<label for="import_dir">CWA import folder</label>
|
||||
<input id="import_dir" name="import_dir" type="text" placeholder="/mnt/cwa-import"
|
||||
value="{{ s.get('import_dir','') }}">
|
||||
<p class="muted small">Folder watched by Calibre-Web-Automated. Extracted epub/pdf files are moved here flat.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="work_dir">Temp work directory</label>
|
||||
<input id="work_dir" name="work_dir" type="text" placeholder="/tmp/calibresync"
|
||||
value="{{ s.get('work_dir','/tmp/calibresync') }}">
|
||||
<p class="muted small">Temporary storage for downloaded zips and extracted files. Cleaned up after each run.</p>
|
||||
</div>
|
||||
</section>
|
||||
@@ -182,7 +163,7 @@ async function testConn(type, btn) {
|
||||
result.className = "test-result test-fail";
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = type === "ssh" ? "Test SSH connection" : "Test Calibre-Web connection";
|
||||
btn.textContent = "Test SSH connection";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user