diff --git a/grimmory.py b/grimmory.py index d9fca48..4d5cefe 100644 --- a/grimmory.py +++ b/grimmory.py @@ -21,7 +21,7 @@ def _is_in_grimmory(filename: str, url: str, user: str, password: str) -> bool: stem = Path(filename).stem try: r = requests.get( - url.rstrip("/") + "/api/v1/books", + url.rstrip("/") + "/komga/api/v1/books", params={"search": stem}, auth=(user, password), timeout=10, @@ -72,18 +72,20 @@ def place_book( def test_connection(url: str, user: str, password: str) -> tuple[bool, str]: + base = url.rstrip("/") try: - r = requests.get( - url.rstrip("/") + "/api/v1/books", - params={"size": 1}, - auth=(user, password), - timeout=10, - ) - if r.status_code == 200: + # Health check (no auth required) + r = requests.get(base + "/api/v1/healthcheck", timeout=10) + if r.status_code != 200: + return False, f"Grimmory not reachable (HTTP {r.status_code})" + # Verify credentials against Komga-compatible API + r2 = requests.get(base + "/komga/api/v1/books", params={"size": 1}, + auth=(user, password), timeout=10) + if r2.status_code == 200: return True, "Connected to Grimmory successfully" - if r.status_code == 401: - return False, "Authentication failed — check username and password" - return False, f"HTTP {r.status_code}" + if r2.status_code == 401: + return False, "Grimmory reachable but credentials rejected — check username and password" + return True, f"Grimmory reachable (API returned HTTP {r2.status_code})" except requests.exceptions.ConnectionError: return False, "Could not connect — check the URL" except Exception as e: