26 lines
718 B
Python
26 lines
718 B
Python
from sqlalchemy.orm import Session
|
|
|
|
from app.models import ApplicationSetting
|
|
|
|
|
|
def read_setting(db: Session, key: str) -> str | None:
|
|
item = db.get(ApplicationSetting, key)
|
|
return item.value if item else None
|
|
|
|
|
|
def write_setting(db: Session, key: str, value: str) -> None:
|
|
item = db.get(ApplicationSetting, key)
|
|
if item:
|
|
item.value = value
|
|
else:
|
|
db.add(ApplicationSetting(key=key, value=value))
|
|
|
|
|
|
def radarr_credentials(db: Session) -> tuple[str, str]:
|
|
url = read_setting(db, "radarr_url")
|
|
api_key = read_setting(db, "radarr_api_key")
|
|
if not url or not api_key:
|
|
raise ValueError("La connexion Radarr n'est pas configurée")
|
|
return url.rstrip("/"), api_key
|
|
|