✨ Champ port optionnel (Radarr + qBittorrent) et normalisation des adresses locales

This commit is contained in:
Orionis312050 committed 2026-10-11 20:16:06 +00:00
1 parent f0b5f2b21e
commit 76dbd7e425
6 files changed
+127 -35

No files matched your search

+34 -17
View File
@@ -14,7 +14,7 @@ from sqlalchemy import inspect, select, text, update
from sqlalchemy.orm import Session
from app import auth
from app.conf_store import read_config, write_config
from app.conf_store import ApiServiceConfig, build_base_url, read_config, write_config
from app.converter import cancel_conversion, conversion_paths, finalize_validation
from app.database import Base, engine, get_db
from app.models import IsoMovie
@@ -82,18 +82,20 @@ app.add_middleware(
DbSession = Annotated[Session, Depends(get_db)]
def _api_service_read(url: str | None, api_key: str | None) -> ApiServiceSettingsRead:
return ApiServiceSettingsRead(url=url, api_key_configured=api_key is not None)
def _api_service_read(service: ApiServiceConfig) -> ApiServiceSettingsRead:
return ApiServiceSettingsRead(
url=service.url, port=service.port, api_key_configured=service.api_key is not None
)
def _settings_read() -> SettingsRead:
cfg = read_config()
return SettingsRead(
radarr=_api_service_read(cfg.radarr.url, cfg.radarr.api_key),
sonarr=_api_service_read(cfg.sonarr.url, cfg.sonarr.api_key),
prowlarr=_api_service_read(cfg.prowlarr.url, cfg.prowlarr.api_key),
jellyfin=_api_service_read(cfg.jellyfin.url, cfg.jellyfin.api_key),
seerr=_api_service_read(cfg.seerr.url, cfg.seerr.api_key),
radarr=_api_service_read(cfg.radarr),
sonarr=_api_service_read(cfg.sonarr),
prowlarr=_api_service_read(cfg.prowlarr),
jellyfin=_api_service_read(cfg.jellyfin),
seerr=_api_service_read(cfg.seerr),
qbittorrent=QbittorrentSettingsRead(
url=cfg.qbittorrent.url,
username=cfg.qbittorrent.username,
@@ -104,7 +106,7 @@ def _settings_read() -> SettingsRead:
def client_from_config() -> RadarrClient:
cfg = read_config()
url = (cfg.radarr.url or "").rstrip("/")
url = build_base_url(cfg.radarr.url, cfg.radarr.port)
api_key = cfg.radarr.api_key
if not url or not api_key:
raise HTTPException(status_code=409, detail="La connexion Radarr n'est pas configurée")
@@ -124,8 +126,12 @@ def health() -> HealthRead:
@app.get("/api/settings/radarr", response_model=RadarrSettingsRead)
def get_radarr_settings() -> RadarrSettingsRead:
cfg = read_config()
return RadarrSettingsRead(url=cfg.radarr.url, api_key_configured=cfg.radarr.api_key is not None)
radarr = read_config().radarr
return RadarrSettingsRead(
url=radarr.url,
port=radarr.port,
api_key_configured=radarr.api_key is not None,
)
@app.put("/api/settings/radarr", response_model=RadarrSettingsRead)
@@ -133,12 +139,17 @@ def put_radarr_settings(
payload: RadarrSettingsWrite,
) -> RadarrSettingsRead:
cfg = read_config()
url = str(payload.url).rstrip("/")
url = str(payload.url).strip().rstrip("/")
cfg.radarr.url = url
cfg.radarr.port = payload.port
if payload.api_key:
cfg.radarr.api_key = payload.api_key
write_config(cfg)
return RadarrSettingsRead(url=url, api_key_configured=cfg.radarr.api_key is not None)
return RadarrSettingsRead(
url=url,
port=cfg.radarr.port,
api_key_configured=cfg.radarr.api_key is not None,
)
@app.get("/api/settings", response_model=SettingsRead)
@@ -192,16 +203,20 @@ async def test_radarr() -> ConnectionResult:
def qbittorrent_from_config() -> QbittorrentClient:
qb = read_config().qbittorrent
if not qb.url or not qb.username or not qb.password:
url = build_base_url(qb.url, qb.port)
if not url or not qb.username or not qb.password:
raise HTTPException(status_code=409, detail="La connexion qBittorrent n'est pas configurée")
return QbittorrentClient(qb.url, qb.username, qb.password)
return QbittorrentClient(url, qb.username, qb.password)
@app.get("/api/settings/qbittorrent", response_model=QbittorrentSettingsRead)
def get_qbittorrent_settings() -> QbittorrentSettingsRead:
qb = read_config().qbittorrent
return QbittorrentSettingsRead(
url=qb.url, username=qb.username, password_configured=qb.password is not None
url=qb.url,
port=qb.port,
username=qb.username,
password_configured=qb.password is not None,
)
@@ -209,7 +224,8 @@ def get_qbittorrent_settings() -> QbittorrentSettingsRead:
def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSettingsRead:
cfg = read_config()
if payload.url is not None:
cfg.qbittorrent.url = str(payload.url).rstrip("/")
cfg.qbittorrent.url = str(payload.url).strip().rstrip("/")
cfg.qbittorrent.port = payload.port
if payload.username:
cfg.qbittorrent.username = payload.username
if payload.password:
@@ -217,6 +233,7 @@ def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSe
write_config(cfg)
return QbittorrentSettingsRead(
url=cfg.qbittorrent.url,
port=cfg.qbittorrent.port,
username=cfg.qbittorrent.username,
password_configured=cfg.qbittorrent.password is not None,
)