check for doubles
This commit is contained in:
+19
-6
@@ -174,7 +174,10 @@ def fetch_all_books(cfg: CalibreConfig) -> list[dict]:
|
||||
data = resp.json()
|
||||
# Calibre-Web uses DataTables format: "data"/"recordsTotal", older versions use "rows"/"total_count"
|
||||
rows = data.get("rows") or data.get("data") or []
|
||||
total = data.get("total") or data.get("totalNotFiltered") or 0
|
||||
total = (
|
||||
data.get("recordsTotal") or data.get("total_count") or
|
||||
data.get("total") or data.get("totalNotFiltered") or 0
|
||||
)
|
||||
all_books.extend(rows)
|
||||
log.info("Books fetched: %d / %d", len(all_books), total)
|
||||
if not rows or len(all_books) >= total:
|
||||
@@ -183,13 +186,23 @@ def fetch_all_books(cfg: CalibreConfig) -> list[dict]:
|
||||
return all_books
|
||||
|
||||
|
||||
def delete_book(cfg: CalibreConfig, book_id: int) -> tuple[bool, str]:
|
||||
"""Delete a book from Calibre-Web by ID."""
|
||||
client = CalibreClient(cfg)
|
||||
client._ensure_auth()
|
||||
def delete_book(cfg: CalibreConfig, book_id: int, client: "CalibreClient | None" = None) -> tuple[bool, str]:
|
||||
"""Delete a book from Calibre-Web by ID. Pass a pre-authenticated client to avoid re-auth overhead."""
|
||||
if client is None:
|
||||
client = CalibreClient(cfg)
|
||||
client._ensure_auth()
|
||||
csrf = client._upload_csrf
|
||||
if not csrf:
|
||||
# Try to fetch a CSRF token from the book detail page
|
||||
try:
|
||||
page = client._session.get(f"{cfg.url}/book/{book_id}", timeout=15)
|
||||
csrf = _extract_csrf(page.text)
|
||||
client._upload_csrf = csrf
|
||||
except Exception:
|
||||
pass
|
||||
resp = client._session.post(
|
||||
f"{cfg.url}/delete/{book_id}",
|
||||
data={"csrf_token": client._upload_csrf} if client._upload_csrf else {},
|
||||
data={"csrf_token": csrf} if csrf else {},
|
||||
timeout=30,
|
||||
)
|
||||
if resp.ok:
|
||||
|
||||
Reference in New Issue
Block a user