diff --git a/abogen/web/routes/books.py b/abogen/web/routes/books.py index 0306ee7..e62effd 100644 --- a/abogen/web/routes/books.py +++ b/abogen/web/routes/books.py @@ -7,7 +7,7 @@ from flask.typing import ResponseReturnValue from abogen.web.routes.utils.settings import ( load_settings, - stored_integration_config, + load_integration_settings, ) from abogen.web.routes.utils.voice import template_options from abogen.web.routes.utils.form import build_pending_job_from_extraction @@ -37,7 +37,7 @@ def _build_calibre_client(payload: Dict[str, Any]) -> CalibreOPDSClient: @books_bp.get("/") def find_books_page() -> ResponseReturnValue: settings = load_settings() - integrations = settings.get("integrations", {}) + integrations = load_integration_settings() return render_template( "find_books.html", integrations=integrations, @@ -54,8 +54,7 @@ def search_books() -> ResponseReturnValue: @books_bp.get("/calibre/feed") def calibre_opds_feed() -> ResponseReturnValue: - settings = load_settings() - integrations = settings.get("integrations", {}) + integrations = load_integration_settings() calibre_settings = integrations.get("calibre_opds", {}) payload = { diff --git a/abogen/web/routes/utils/settings.py b/abogen/web/routes/utils/settings.py index 759ad11..342db9d 100644 --- a/abogen/web/routes/utils/settings.py +++ b/abogen/web/routes/utils/settings.py @@ -343,6 +343,25 @@ def load_integration_settings() -> Dict[str, Dict[str, Any]]: # Do not clear the token here # merged["api_token"] = "" integrations[key] = merged + + # Environment variable fallbacks for Calibre OPDS + calibre = integrations["calibre_opds"] + if not calibre.get("base_url"): + calibre["base_url"] = os.environ.get("CALIBRE_SERVER_HOST", "") + if not calibre.get("username"): + calibre["username"] = os.environ.get("OPDS_USERNAME", "") + if not calibre.get("password"): + calibre["password"] = os.environ.get("OPDS_PASSWORD", "") + + # If we have a password (from storage or env), mark it as present for the UI + if calibre.get("password"): + calibre["has_password"] = True + + # Auto-enable if configured via env but not explicitly disabled in config + stored_calibre = stored_integrations.get("calibre_opds") + if stored_calibre is None and calibre.get("base_url"): + calibre["enabled"] = True + return integrations