calibre upload errors
This commit is contained in:
+5
-4
@@ -47,6 +47,11 @@ class CalibreClient:
|
|||||||
if resp.url.rstrip("/").endswith("/login"):
|
if resp.url.rstrip("/").endswith("/login"):
|
||||||
raise RuntimeError("Calibre-Web authentication failed — check credentials")
|
raise RuntimeError("Calibre-Web authentication failed — check credentials")
|
||||||
self._authenticated = True
|
self._authenticated = True
|
||||||
|
# The CSRF token is session-scoped in Flask-WTF — reuse the login token for uploads.
|
||||||
|
# Also try to extract a fresh one from the landing page (/).
|
||||||
|
self._upload_csrf = _extract_csrf(resp.text) or csrf
|
||||||
|
log.debug("Upload CSRF token from login: %s",
|
||||||
|
self._upload_csrf[:12] + "…" if self._upload_csrf else "NOT FOUND")
|
||||||
log.info("Authenticated to Calibre-Web at %s", self._cfg.url)
|
log.info("Authenticated to Calibre-Web at %s", self._cfg.url)
|
||||||
|
|
||||||
def upload(self, book_path: Path, zip_source: str) -> str:
|
def upload(self, book_path: Path, zip_source: str) -> str:
|
||||||
@@ -60,10 +65,6 @@ class CalibreClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self._ensure_auth()
|
self._ensure_auth()
|
||||||
if not self._upload_csrf:
|
|
||||||
page = self._session.get(f"{self._cfg.url}/upload", timeout=30)
|
|
||||||
self._upload_csrf = _extract_csrf(page.text)
|
|
||||||
log.debug("Upload CSRF token: %s", self._upload_csrf[:12] + "…" if self._upload_csrf else "NOT FOUND")
|
|
||||||
|
|
||||||
mime = MIME_TYPES.get(book_path.suffix.lower(), "application/octet-stream")
|
mime = MIME_TYPES.get(book_path.suffix.lower(), "application/octet-stream")
|
||||||
with book_path.open("rb") as fh:
|
with book_path.open("rb") as fh:
|
||||||
|
|||||||
Reference in New Issue
Block a user