databse wipe

This commit is contained in:
2026-05-10 17:08:28 +02:00
parent d69169807c
commit 881604b4a5
4 changed files with 32 additions and 0 deletions
+9
View File
@@ -204,5 +204,14 @@ def get_stats() -> dict:
} }
def clear_sync_data() -> dict:
"""Delete all processed_zips, uploaded_books, and sync_runs rows. Settings are kept."""
with get_db() as conn:
zips = conn.execute("DELETE FROM processed_zips").rowcount
books = conn.execute("DELETE FROM uploaded_books").rowcount
runs = conn.execute("DELETE FROM sync_runs").rowcount
return {"zips": zips, "books": books, "runs": runs}
def _now() -> str: def _now() -> str:
return datetime.now(timezone.utc).isoformat() return datetime.now(timezone.utc).isoformat()
+9
View File
@@ -174,6 +174,15 @@ async def test_calibre():
return {"ok": ok, "message": message} return {"ok": ok, "message": message}
# --- Data reset ---
@app.post("/settings/reset-sync-data")
async def reset_sync_data():
counts = db.clear_sync_data()
log.info("Sync data cleared: %s", counts)
return RedirectResponse("/settings?reset=1", status_code=303)
# --- JSON status API --- # --- JSON status API ---
@app.get("/api/status") @app.get("/api/status")
+3
View File
@@ -153,6 +153,9 @@ tr:hover td { background: rgba(255,255,255,0.02); }
.btn-secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); } .btn-secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-secondary:hover { background: rgba(99,102,241,0.1); } .btn-secondary:hover { background: rgba(99,102,241,0.1); }
.btn-disabled { background: var(--border); color: var(--muted); cursor: not-allowed; } .btn-disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
.btn-danger { background: #dc2626; color: #fff; border: 1px solid #dc2626; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.danger-zone { border-color: rgba(220,38,38,0.4); }
/* Forms */ /* Forms */
.form-section { .form-section {
+11
View File
@@ -148,6 +148,17 @@
</div> </div>
</form> </form>
<section class="form-section danger-zone">
<h2>Danger zone</h2>
{% if request.query_params.get("reset") %}
<div class="alert alert-success">Sync data cleared — all processed zip and book records have been deleted.</div>
{% endif %}
<p class="muted small">Deletes all records of processed zips, uploaded books, and sync run history. Your settings are kept. Use this to start fresh after test runs.</p>
<form method="post" action="/settings/reset-sync-data" onsubmit="return confirm('Delete all sync data? This cannot be undone.')">
<button type="submit" class="btn btn-danger">Delete all sync data</button>
</form>
</section>
<script> <script>
function toggleAuth(method) { function toggleAuth(method) {
document.getElementById("row-key").style.display = method === "key" ? "" : "none"; document.getElementById("row-key").style.display = method === "key" ? "" : "none";