feat: Refactor integration settings loading to use environment variable fallbacks for Calibre OPDS

This commit is contained in:
JB
2025-11-28 20:16:34 -08:00
parent 4bfce0f900
commit a5f2bf7fbe
2 changed files with 22 additions and 4 deletions
+3 -4
View File
@@ -7,7 +7,7 @@ from flask.typing import ResponseReturnValue
from abogen.web.routes.utils.settings import ( from abogen.web.routes.utils.settings import (
load_settings, load_settings,
stored_integration_config, load_integration_settings,
) )
from abogen.web.routes.utils.voice import template_options from abogen.web.routes.utils.voice import template_options
from abogen.web.routes.utils.form import build_pending_job_from_extraction 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("/") @books_bp.get("/")
def find_books_page() -> ResponseReturnValue: def find_books_page() -> ResponseReturnValue:
settings = load_settings() settings = load_settings()
integrations = settings.get("integrations", {}) integrations = load_integration_settings()
return render_template( return render_template(
"find_books.html", "find_books.html",
integrations=integrations, integrations=integrations,
@@ -54,8 +54,7 @@ def search_books() -> ResponseReturnValue:
@books_bp.get("/calibre/feed") @books_bp.get("/calibre/feed")
def calibre_opds_feed() -> ResponseReturnValue: def calibre_opds_feed() -> ResponseReturnValue:
settings = load_settings() integrations = load_integration_settings()
integrations = settings.get("integrations", {})
calibre_settings = integrations.get("calibre_opds", {}) calibre_settings = integrations.get("calibre_opds", {})
payload = { payload = {
+19
View File
@@ -343,6 +343,25 @@ def load_integration_settings() -> Dict[str, Dict[str, Any]]:
# Do not clear the token here # Do not clear the token here
# merged["api_token"] = "" # merged["api_token"] = ""
integrations[key] = merged 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 return integrations