grimmory auth

This commit is contained in:
2026-05-14 21:54:46 +02:00
parent e029da895b
commit cd950c29a6
+13 -11
View File
@@ -21,7 +21,7 @@ def _is_in_grimmory(filename: str, url: str, user: str, password: str) -> bool:
stem = Path(filename).stem stem = Path(filename).stem
try: try:
r = requests.get( r = requests.get(
url.rstrip("/") + "/api/v1/books", url.rstrip("/") + "/komga/api/v1/books",
params={"search": stem}, params={"search": stem},
auth=(user, password), auth=(user, password),
timeout=10, timeout=10,
@@ -72,18 +72,20 @@ def place_book(
def test_connection(url: str, user: str, password: str) -> tuple[bool, str]: def test_connection(url: str, user: str, password: str) -> tuple[bool, str]:
base = url.rstrip("/")
try: try:
r = requests.get( # Health check (no auth required)
url.rstrip("/") + "/api/v1/books", r = requests.get(base + "/api/v1/healthcheck", timeout=10)
params={"size": 1}, if r.status_code != 200:
auth=(user, password), return False, f"Grimmory not reachable (HTTP {r.status_code})"
timeout=10, # Verify credentials against Komga-compatible API
) r2 = requests.get(base + "/komga/api/v1/books", params={"size": 1},
if r.status_code == 200: auth=(user, password), timeout=10)
if r2.status_code == 200:
return True, "Connected to Grimmory successfully" return True, "Connected to Grimmory successfully"
if r.status_code == 401: if r2.status_code == 401:
return False, "Authentication failed — check username and password" return False, "Grimmory reachable but credentials rejected — check username and password"
return False, f"HTTP {r.status_code}" return True, f"Grimmory reachable (API returned HTTP {r2.status_code})"
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
return False, "Could not connect — check the URL" return False, "Could not connect — check the URL"
except Exception as e: except Exception as e: