✨ Statut par service dans la Configuration: configure / teste / echec + endpoints de test pour tous les services
This commit is contained in:
1 parent
23132c6219
commit
3a75527135
9 files changed
+409
-59
No files matched your search
@@ -8,6 +8,7 @@ La configuration des services (Radarr, Sonarr, Prowlarr, Jellyfin, Overseerr/See
|
||||
|
||||
- Le backend lit ce fichier.
|
||||
- L'interface modifie ce fichier via l'API (écriture atomique côté backend).
|
||||
- Chaque service expose un statut dans la page Configuration: `Non configuré` (URL ou clé API manquante), `Configuré · non testé`, `Testé` (dernier test de connexion réussi, version affichée) ou `Test échoué`. Le résultat du dernier test est conservé dans `conf.json` (bloc `test`) et invalidé dès que l'URL ou les identifiants changent.
|
||||
|
||||
Radarr (rappel API):
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -9,10 +10,20 @@ from pydantic import BaseModel, Field
|
||||
from app.config import settings
|
||||
|
||||
|
||||
class TestState(BaseModel):
|
||||
"""Resultat du dernier test de connexion (None = jamais teste)."""
|
||||
|
||||
at: str | None = None
|
||||
ok: bool | None = None
|
||||
version: str | None = None
|
||||
error: str | None = None
|
||||
|
||||
|
||||
class ApiServiceConfig(BaseModel):
|
||||
url: str | None = None
|
||||
port: int | None = None
|
||||
api_key: str | None = None
|
||||
test: TestState = Field(default_factory=TestState)
|
||||
|
||||
|
||||
class QbittorrentConfig(BaseModel):
|
||||
@@ -20,6 +31,7 @@ class QbittorrentConfig(BaseModel):
|
||||
port: int | None = None
|
||||
username: str | None = None
|
||||
password: str | None = None
|
||||
test: TestState = Field(default_factory=TestState)
|
||||
|
||||
|
||||
def build_base_url(url: str | None, port: int | None = None) -> str | None:
|
||||
@@ -54,6 +66,48 @@ def config_path() -> Path:
|
||||
return settings.config_dir / "conf.json"
|
||||
|
||||
|
||||
SERVICE_NAMES = ("radarr", "sonarr", "prowlarr", "jellyfin", "seerr", "qbittorrent")
|
||||
|
||||
|
||||
def service_configured(service: ApiServiceConfig | QbittorrentConfig) -> bool:
|
||||
"""Un service est completement configure quand son URL (et sa cle API,
|
||||
quand il en faut une) est renseignee."""
|
||||
if isinstance(service, QbittorrentConfig):
|
||||
return bool(service.url)
|
||||
return bool(service.url and service.api_key)
|
||||
|
||||
|
||||
def service_status(service: ApiServiceConfig | QbittorrentConfig) -> str:
|
||||
"""Statut expose a l'UI: unconfigured | configured | tested | error."""
|
||||
if not service_configured(service):
|
||||
return "unconfigured"
|
||||
if service.test.ok is None:
|
||||
return "configured"
|
||||
return "tested" if service.test.ok else "error"
|
||||
|
||||
|
||||
def record_test(
|
||||
service_name: str, ok: bool, version: str | None = None, error: str | None = None
|
||||
) -> None:
|
||||
"""Persiste dans conf.json le resultat du dernier test de connexion."""
|
||||
if service_name not in SERVICE_NAMES:
|
||||
raise ValueError(f"Service inconnu: {service_name}")
|
||||
cfg = read_config()
|
||||
service = getattr(cfg, service_name)
|
||||
service.test = TestState(
|
||||
at=datetime.now(UTC).isoformat(),
|
||||
ok=ok,
|
||||
version=version if ok else None,
|
||||
error=None if ok else error,
|
||||
)
|
||||
write_config(cfg)
|
||||
|
||||
|
||||
def reset_test(service: ApiServiceConfig | QbittorrentConfig) -> None:
|
||||
"""Reinitialise le statut de test quand la configuration change."""
|
||||
service.test = TestState()
|
||||
|
||||
|
||||
def read_config() -> AppConfig:
|
||||
path = config_path()
|
||||
if not path.exists():
|
||||
|
||||
+142
-38
@@ -14,7 +14,17 @@ from sqlalchemy import inspect, select, text, update
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import auth
|
||||
from app.conf_store import ApiServiceConfig, build_base_url, read_config, write_config
|
||||
from app.conf_store import (
|
||||
ApiServiceConfig,
|
||||
QbittorrentConfig,
|
||||
build_base_url,
|
||||
read_config,
|
||||
record_test,
|
||||
reset_test,
|
||||
service_configured,
|
||||
service_status,
|
||||
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
|
||||
@@ -85,7 +95,26 @@ DbSession = Annotated[Session, Depends(get_db)]
|
||||
|
||||
def _api_service_read(service: ApiServiceConfig) -> ApiServiceSettingsRead:
|
||||
return ApiServiceSettingsRead(
|
||||
url=service.url, port=service.port, api_key_configured=service.api_key is not None
|
||||
url=service.url,
|
||||
port=service.port,
|
||||
api_key_configured=service.api_key is not None,
|
||||
status=service_status(service),
|
||||
tested_version=service.test.version,
|
||||
tested_at=service.test.at,
|
||||
test_error=service.test.error,
|
||||
)
|
||||
|
||||
|
||||
def _qbittorrent_read(qb: QbittorrentConfig) -> QbittorrentSettingsRead:
|
||||
return QbittorrentSettingsRead(
|
||||
url=qb.url,
|
||||
port=qb.port,
|
||||
username=qb.username,
|
||||
password_configured=qb.password is not None,
|
||||
status=service_status(qb),
|
||||
tested_version=qb.test.version,
|
||||
tested_at=qb.test.at,
|
||||
test_error=qb.test.error,
|
||||
)
|
||||
|
||||
|
||||
@@ -97,11 +126,7 @@ def _settings_read() -> SettingsRead:
|
||||
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,
|
||||
password_configured=cfg.qbittorrent.password is not None,
|
||||
),
|
||||
qbittorrent=_qbittorrent_read(cfg.qbittorrent),
|
||||
)
|
||||
|
||||
|
||||
@@ -127,12 +152,7 @@ def health() -> HealthRead:
|
||||
|
||||
@app.get("/api/settings/radarr", response_model=RadarrSettingsRead)
|
||||
def get_radarr_settings() -> RadarrSettingsRead:
|
||||
radarr = read_config().radarr
|
||||
return RadarrSettingsRead(
|
||||
url=radarr.url,
|
||||
port=radarr.port,
|
||||
api_key_configured=radarr.api_key is not None,
|
||||
)
|
||||
return _api_service_read(read_config().radarr)
|
||||
|
||||
|
||||
@app.put("/api/settings/radarr", response_model=RadarrSettingsRead)
|
||||
@@ -141,16 +161,19 @@ def put_radarr_settings(
|
||||
) -> RadarrSettingsRead:
|
||||
cfg = read_config()
|
||||
url = str(payload.url).strip().rstrip("/")
|
||||
# Toute modification de la connexion invalide le dernier test.
|
||||
if (
|
||||
url != (cfg.radarr.url or "")
|
||||
or payload.port != cfg.radarr.port
|
||||
or (payload.api_key and payload.api_key != cfg.radarr.api_key)
|
||||
):
|
||||
reset_test(cfg.radarr)
|
||||
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,
|
||||
port=cfg.radarr.port,
|
||||
api_key_configured=cfg.radarr.api_key is not None,
|
||||
)
|
||||
return _api_service_read(cfg.radarr)
|
||||
|
||||
|
||||
@app.get("/api/settings", response_model=SettingsRead)
|
||||
@@ -165,6 +188,13 @@ def put_settings(payload: SettingsWrite) -> SettingsRead:
|
||||
def apply_service(target, patch):
|
||||
if patch is None:
|
||||
return
|
||||
changed = False
|
||||
if patch.url is not None and str(patch.url).rstrip("/") != (target.url or ""):
|
||||
changed = True
|
||||
if patch.api_key and patch.api_key != target.api_key:
|
||||
changed = True
|
||||
if changed:
|
||||
reset_test(target)
|
||||
if patch.url is not None:
|
||||
target.url = str(patch.url).rstrip("/")
|
||||
if patch.api_key:
|
||||
@@ -178,6 +208,11 @@ def put_settings(payload: SettingsWrite) -> SettingsRead:
|
||||
|
||||
if payload.qbittorrent is not None:
|
||||
qb = payload.qbittorrent
|
||||
qb_changed = bool(qb.url) and str(qb.url).rstrip("/") != (cfg.qbittorrent.url or "")
|
||||
qb_changed = qb_changed or bool(qb.username and qb.username != cfg.qbittorrent.username)
|
||||
qb_changed = qb_changed or bool(qb.password)
|
||||
if qb_changed:
|
||||
reset_test(cfg.qbittorrent)
|
||||
if qb.url is not None:
|
||||
cfg.qbittorrent.url = str(qb.url).rstrip("/")
|
||||
if qb.username:
|
||||
@@ -195,13 +230,83 @@ async def test_radarr() -> ConnectionResult:
|
||||
try:
|
||||
status = await client.system_status()
|
||||
except (httpx.HTTPError, ValueError) as error:
|
||||
record_test("radarr", ok=False, error=str(error))
|
||||
raise HTTPException(
|
||||
status_code=502, detail=f"Connexion Radarr impossible: {error}"
|
||||
) from error
|
||||
version = str(status.get("version", "inconnue"))
|
||||
record_test("radarr", ok=True, version=version)
|
||||
return ConnectionResult(success=True, version=version, message=f"Radarr {version} accessible")
|
||||
|
||||
|
||||
# --- Tests de connexion des autres services API (Sonarr, Prowlarr, Jellyfin,
|
||||
# Overseerr). Chacun expose un endpoint systeme et une version. ---
|
||||
API_SERVICE_TESTS: dict[str, tuple[str, str, str]] = {
|
||||
# service: (endpoint, nom de l'en-tete d'authentification, cle de version)
|
||||
"sonarr": ("api/v3/system/status", "X-Api-Key", "version"),
|
||||
"prowlarr": ("api/v1/system/status", "X-Api-Key", "version"),
|
||||
"jellyfin": ("System/Info", "X-Emby-Token", "Version"),
|
||||
"seerr": ("api/v1/status", "X-Api-Key", "version"),
|
||||
}
|
||||
|
||||
SERVICE_LABELS = {
|
||||
"sonarr": "Sonarr",
|
||||
"prowlarr": "Prowlarr",
|
||||
"jellyfin": "Jellyfin",
|
||||
"seerr": "Overseerr",
|
||||
}
|
||||
|
||||
|
||||
async def _test_api_service(name: str) -> ConnectionResult:
|
||||
service = getattr(read_config(), name)
|
||||
label = SERVICE_LABELS[name]
|
||||
url = build_base_url(service.url, service.port)
|
||||
if not service_configured(service):
|
||||
raise HTTPException(
|
||||
status_code=409, detail=f"La connexion {label} n'est pas configurée"
|
||||
)
|
||||
endpoint, auth_header, version_key = API_SERVICE_TESTS[name]
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=30) as client:
|
||||
response = await client.get(
|
||||
f"{url}/{endpoint}", headers={auth_header: service.api_key}
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except (httpx.HTTPError, ValueError) as error:
|
||||
record_test(name, ok=False, error=str(error))
|
||||
raise HTTPException(
|
||||
status_code=502, detail=f"Connexion {label} impossible: {error}"
|
||||
) from error
|
||||
if not isinstance(data, dict):
|
||||
error = "Réponse inattendue du service"
|
||||
record_test(name, ok=False, error=error)
|
||||
raise HTTPException(status_code=502, detail=f"Connexion {label} impossible: {error}")
|
||||
version = str(data.get(version_key, "inconnue"))
|
||||
record_test(name, ok=True, version=version)
|
||||
return ConnectionResult(success=True, version=version, message=f"{label} {version} accessible")
|
||||
|
||||
|
||||
@app.post("/api/settings/sonarr/test", response_model=ConnectionResult)
|
||||
async def test_sonarr() -> ConnectionResult:
|
||||
return await _test_api_service("sonarr")
|
||||
|
||||
|
||||
@app.post("/api/settings/prowlarr/test", response_model=ConnectionResult)
|
||||
async def test_prowlarr() -> ConnectionResult:
|
||||
return await _test_api_service("prowlarr")
|
||||
|
||||
|
||||
@app.post("/api/settings/jellyfin/test", response_model=ConnectionResult)
|
||||
async def test_jellyfin() -> ConnectionResult:
|
||||
return await _test_api_service("jellyfin")
|
||||
|
||||
|
||||
@app.post("/api/settings/seerr/test", response_model=ConnectionResult)
|
||||
async def test_seerr() -> ConnectionResult:
|
||||
return await _test_api_service("seerr")
|
||||
|
||||
|
||||
def qbittorrent_from_config() -> QbittorrentClient:
|
||||
qb = read_config().qbittorrent
|
||||
url = build_base_url(qb.url, qb.port)
|
||||
@@ -212,39 +317,36 @@ def qbittorrent_from_config() -> QbittorrentClient:
|
||||
|
||||
@app.get("/api/settings/qbittorrent", response_model=QbittorrentSettingsRead)
|
||||
def get_qbittorrent_settings() -> QbittorrentSettingsRead:
|
||||
qb = read_config().qbittorrent
|
||||
return QbittorrentSettingsRead(
|
||||
url=qb.url,
|
||||
port=qb.port,
|
||||
username=qb.username,
|
||||
password_configured=qb.password is not None,
|
||||
)
|
||||
return _qbittorrent_read(read_config().qbittorrent)
|
||||
|
||||
|
||||
@app.put("/api/settings/qbittorrent", response_model=QbittorrentSettingsRead)
|
||||
def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSettingsRead:
|
||||
cfg = read_config()
|
||||
qb = cfg.qbittorrent
|
||||
qb_changed = payload.url is not None and str(payload.url).strip().rstrip("/") != (
|
||||
qb.url or ""
|
||||
)
|
||||
qb_changed = qb_changed or bool(payload.username and payload.username != qb.username)
|
||||
qb_changed = qb_changed or bool(payload.password)
|
||||
if qb_changed:
|
||||
reset_test(qb)
|
||||
if payload.url is not None:
|
||||
cfg.qbittorrent.url = str(payload.url).strip().rstrip("/")
|
||||
cfg.qbittorrent.port = payload.port
|
||||
qb.url = str(payload.url).strip().rstrip("/")
|
||||
qb.port = payload.port
|
||||
if payload.username:
|
||||
cfg.qbittorrent.username = payload.username
|
||||
qb.username = payload.username
|
||||
if payload.password:
|
||||
cfg.qbittorrent.password = payload.password
|
||||
qb.password = payload.password
|
||||
elif payload.password:
|
||||
# Mot de passe seul: on conserve l'utilisateur existant.
|
||||
cfg.qbittorrent.password = payload.password
|
||||
qb.password = payload.password
|
||||
else:
|
||||
# Champs vides: mode bypass d'authentification qBittorrent, sans identifiants.
|
||||
cfg.qbittorrent.username = None
|
||||
cfg.qbittorrent.password = None
|
||||
qb.username = None
|
||||
qb.password = None
|
||||
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,
|
||||
)
|
||||
return _qbittorrent_read(qb)
|
||||
|
||||
|
||||
@app.post("/api/settings/qbittorrent/test", response_model=ConnectionResult)
|
||||
@@ -253,9 +355,11 @@ async def test_qbittorrent() -> ConnectionResult:
|
||||
try:
|
||||
version = await client.version()
|
||||
except (httpx.HTTPError, ValueError) as error:
|
||||
record_test("qbittorrent", ok=False, error=str(error))
|
||||
raise HTTPException(
|
||||
status_code=502, detail=f"Connexion qBittorrent impossible: {error}"
|
||||
) from error
|
||||
record_test("qbittorrent", ok=True, version=version)
|
||||
return ConnectionResult(
|
||||
success=True, version=version, message=f"qBittorrent {version} accessible"
|
||||
)
|
||||
|
||||
@@ -7,6 +7,10 @@ class RadarrSettingsRead(BaseModel):
|
||||
url: str | None
|
||||
port: int | None = None
|
||||
api_key_configured: bool
|
||||
status: str
|
||||
tested_version: str | None = None
|
||||
tested_at: str | None = None
|
||||
test_error: str | None = None
|
||||
|
||||
|
||||
class RadarrSettingsWrite(BaseModel):
|
||||
@@ -19,6 +23,10 @@ class ApiServiceSettingsRead(BaseModel):
|
||||
url: str | None
|
||||
port: int | None = None
|
||||
api_key_configured: bool
|
||||
status: str
|
||||
tested_version: str | None = None
|
||||
tested_at: str | None = None
|
||||
test_error: str | None = None
|
||||
|
||||
|
||||
class ApiServiceSettingsWrite(BaseModel):
|
||||
@@ -32,6 +40,10 @@ class QbittorrentSettingsRead(BaseModel):
|
||||
port: int | None = None
|
||||
username: str | None
|
||||
password_configured: bool
|
||||
status: str
|
||||
tested_version: str | None = None
|
||||
tested_at: str | None = None
|
||||
test_error: str | None = None
|
||||
|
||||
|
||||
class QbittorrentSettingsWrite(BaseModel):
|
||||
|
||||
@@ -38,6 +38,109 @@ def test_radarr_connection() -> None:
|
||||
assert response.json()["version"] == "5.27.0"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_service_status_lifecycle() -> None:
|
||||
"""Statut par service: configured -> tested apres un test reussi, puis
|
||||
retour a configured quand la configuration change.
|
||||
|
||||
Utilise une URL distincte des autres tests: conf.json etant partage entre
|
||||
les tests, il faut garantir un reset du statut herite.
|
||||
"""
|
||||
respx.get("http://radarr-lifecycle:7878/api/v3/system/status").mock(
|
||||
return_value=Response(200, json={"version": "5.27.0"})
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
response = client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-lifecycle:7878", "api_key": "test-key"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Configure mais pas encore teste.
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "configured"
|
||||
assert settings["qbittorrent"]["status"] in {"configured", "unconfigured"}
|
||||
|
||||
client.post("/api/settings/radarr/test")
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "tested"
|
||||
assert settings["radarr"]["tested_version"] == "5.27.0"
|
||||
assert settings["radarr"]["tested_at"] is not None
|
||||
|
||||
# Le resultat du test est persiste dans conf.json.
|
||||
raw = json.loads(config_path().read_text(encoding="utf-8"))
|
||||
assert raw["radarr"]["test"]["ok"] is True
|
||||
assert raw["radarr"]["test"]["version"] == "5.27.0"
|
||||
|
||||
# Modifier l'URL invalide le statut de test.
|
||||
client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-alt:7878", "api_key": None},
|
||||
)
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "configured"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_failed_test_marks_service_as_error() -> None:
|
||||
respx.get("http://radarr-fail:7878/api/v3/system/status").mock(
|
||||
return_value=Response(500, text="boom")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/radarr",
|
||||
json={"url": "http://radarr-fail:7878", "api_key": "test-key"},
|
||||
)
|
||||
response = client.post("/api/settings/radarr/test")
|
||||
assert response.status_code == 502
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["radarr"]["status"] == "error"
|
||||
assert settings["radarr"]["test_error"] is not None
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_sonarr_connection() -> None:
|
||||
"""Les services optionnels ont aussi un endpoint de test."""
|
||||
route = respx.get("http://sonarr:8989/api/v3/system/status").mock(
|
||||
return_value=Response(200, json={"version": "4.0.12"})
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings",
|
||||
json={"sonarr": {"url": "http://sonarr:8989", "api_key": "sonarr-key"}},
|
||||
)
|
||||
response = client.post("/api/settings/sonarr/test")
|
||||
settings = client.get("/api/settings").json()
|
||||
assert response.status_code == 200
|
||||
assert response.json()["version"] == "4.0.12"
|
||||
assert settings["sonarr"]["status"] == "tested"
|
||||
assert route.called
|
||||
assert "sonarr-key" in route.calls.last.request.headers["x-api-key"]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_qbittorrent_status_lifecycle() -> None:
|
||||
respx.get("http://qbit-lifecycle:8080/api/v2/app/version").mock(
|
||||
return_value=Response(200, text="v5.0.2")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "http://qbit-lifecycle:8080", "port": 8080},
|
||||
)
|
||||
assert client.post("/api/settings/qbittorrent/test").status_code == 200
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["qbittorrent"]["status"] == "tested"
|
||||
assert settings["qbittorrent"]["tested_version"] == "v5.0.2"
|
||||
|
||||
# Un nouvel enregistrement (URL differente) reinitialise le statut de test.
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "http://qbit-alt:8080", "port": 8080},
|
||||
)
|
||||
settings = client.get("/api/settings").json()
|
||||
assert settings["qbittorrent"]["status"] == "configured"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_scan_only_imports_iso_files() -> None:
|
||||
respx.get("http://radarr:7878/api/v3/movie?includeMovieFile=true").mock(
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import type {ServiceStatus} from "../types";
|
||||
|
||||
type Props = ServiceStatus;
|
||||
|
||||
export default function ServiceStatusBadge({status, tested_version: version, test_error: error}: Props) {
|
||||
if (status === "tested") {
|
||||
return (
|
||||
<span className="status linked" title={error ?? undefined}>
|
||||
Testé{version ? ` · ${version}` : ""}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (status === "error") {
|
||||
return (
|
||||
<span className="status error" title={error ?? undefined}>
|
||||
Test échoué
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (status === "configured") {
|
||||
return <span className="status warn">Configuré · non testé</span>;
|
||||
}
|
||||
return <span className="status">Non configuré</span>;
|
||||
}
|
||||
+59
-19
@@ -3,6 +3,7 @@ import type React from "react";
|
||||
|
||||
import {api, jsonHeaders} from "../lib/api";
|
||||
import type {SettingsRead} from "../types";
|
||||
import ServiceStatusBadge from "../components/ServiceStatusBadge";
|
||||
|
||||
export default function Settings() {
|
||||
const [radarrUrl, setRadarrUrl] = useState("");
|
||||
@@ -32,6 +33,7 @@ export default function Settings() {
|
||||
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [settings, setSettings] = useState<SettingsRead | null>(null);
|
||||
|
||||
const serviceHelp = useMemo(() => "L’URL doit être accessible depuis le conteneur MKVTool.", []);
|
||||
|
||||
@@ -56,14 +58,27 @@ export default function Settings() {
|
||||
setQbitPasswordConfigured(settings.qbittorrent.password_configured);
|
||||
}, []);
|
||||
|
||||
const refreshSettings = useCallback(async () => {
|
||||
hydrateSettings(await api<SettingsRead>("/api/settings"));
|
||||
const refreshSettings = useCallback(async (): Promise<SettingsRead> => {
|
||||
const fresh = await api<SettingsRead>("/api/settings");
|
||||
hydrateSettings(fresh);
|
||||
setSettings(fresh);
|
||||
return fresh;
|
||||
}, [hydrateSettings]);
|
||||
|
||||
useEffect(() => {
|
||||
refreshSettings().catch((error: Error) => setMessage(error.message));
|
||||
}, [refreshSettings]);
|
||||
|
||||
async function testService(name: "radarr" | "sonarr" | "prowlarr" | "jellyfin" | "seerr" | "qbittorrent"): Promise<void> {
|
||||
try {
|
||||
const result = await api<{ message: string }>(`/api/settings/${name}/test`, {method: "POST"});
|
||||
setMessage(result.message);
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
}
|
||||
await refreshSettings().catch(() => undefined);
|
||||
}
|
||||
|
||||
async function saveRadarr(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
@@ -81,8 +96,7 @@ export default function Settings() {
|
||||
});
|
||||
setRadarrApiKey("");
|
||||
await refreshSettings();
|
||||
const result = await api<{ message: string }>("/api/settings/radarr/test", {method: "POST"});
|
||||
setMessage(result.message);
|
||||
await testService("radarr");
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
@@ -117,8 +131,12 @@ export default function Settings() {
|
||||
if (name === "jellyfin") setJellyfinApiKey("");
|
||||
if (name === "seerr") setSeerrApiKey("");
|
||||
|
||||
await refreshSettings();
|
||||
setMessage("Configuration enregistrée");
|
||||
const fresh = await refreshSettings();
|
||||
if (fresh[name].status === "unconfigured") {
|
||||
setMessage("Configuration enregistrée");
|
||||
} else {
|
||||
await testService(name);
|
||||
}
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
@@ -144,8 +162,12 @@ export default function Settings() {
|
||||
});
|
||||
|
||||
setQbitPassword("");
|
||||
await refreshSettings();
|
||||
setMessage("Configuration enregistrée");
|
||||
const fresh = await refreshSettings();
|
||||
if (fresh.qbittorrent.status === "unconfigured") {
|
||||
setMessage("Configuration enregistrée");
|
||||
} else {
|
||||
await testService("qbittorrent");
|
||||
}
|
||||
} catch (error) {
|
||||
setMessage((error as Error).message);
|
||||
} finally {
|
||||
@@ -168,7 +190,10 @@ export default function Settings() {
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Radarr</h3>
|
||||
<div className="service-head">
|
||||
<h3>Radarr</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.radarr}/>}
|
||||
</div>
|
||||
<p className="muted">Obligatoire pour le scan et la détection des films.</p>
|
||||
</div>
|
||||
<form onSubmit={saveRadarr} className="form-2">
|
||||
@@ -198,7 +223,10 @@ export default function Settings() {
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Sonarr</h3>
|
||||
<div className="service-head">
|
||||
<h3>Sonarr</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.sonarr}/>}
|
||||
</div>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("sonarr", e)} className="form-2">
|
||||
@@ -220,13 +248,16 @@ export default function Settings() {
|
||||
onChange={(event) => setSonarrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Prowlarr</h3>
|
||||
<div className="service-head">
|
||||
<h3>Prowlarr</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.prowlarr}/>}
|
||||
</div>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("prowlarr", e)} className="form-2">
|
||||
@@ -248,13 +279,16 @@ export default function Settings() {
|
||||
onChange={(event) => setProwlarrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Jellyfin</h3>
|
||||
<div className="service-head">
|
||||
<h3>Jellyfin</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.jellyfin}/>}
|
||||
</div>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("jellyfin", e)} className="form-2">
|
||||
@@ -276,13 +310,16 @@ export default function Settings() {
|
||||
onChange={(event) => setJellyfinApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>Overseerr</h3>
|
||||
<div className="service-head">
|
||||
<h3>Overseerr</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.seerr}/>}
|
||||
</div>
|
||||
<p className="muted">Optionnel (hors périmètre MVP), mais stocké dans conf.json.</p>
|
||||
</div>
|
||||
<form onSubmit={(e) => saveApiService("seerr", e)} className="form-2">
|
||||
@@ -304,13 +341,16 @@ export default function Settings() {
|
||||
onChange={(event) => setSeerrApiKey(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="card grid-2">
|
||||
<div>
|
||||
<h3>qBittorrent</h3>
|
||||
<div className="service-head">
|
||||
<h3>qBittorrent</h3>
|
||||
{settings && <ServiceStatusBadge {...settings.qbittorrent}/>}
|
||||
</div>
|
||||
<p className="muted">Optionnel: nécessaire pour supprimer torrent + données après import validé.</p>
|
||||
</div>
|
||||
<form onSubmit={saveQbittorrent} className="form-3">
|
||||
@@ -341,7 +381,7 @@ export default function Settings() {
|
||||
onChange={(event) => setQbitPassword(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button disabled={busy}>Enregistrer</button>
|
||||
<button disabled={busy}>Enregistrer et tester</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ h1 {
|
||||
background: var(--surface);
|
||||
}
|
||||
.settings { display: grid; grid-template-columns: 1fr 2fr; gap: 2.5rem; }
|
||||
.service-head { display: flex; align-items: center; gap: 0.75rem; }
|
||||
.panel-head h2 { font-size: 1.15rem; font-weight: 650; margin-bottom: 0.4rem; }
|
||||
.settings p, article p { color: var(--text-muted); }
|
||||
form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 0.75rem; }
|
||||
@@ -201,6 +202,10 @@ code { color: var(--text-muted); font-size: 0.8rem; overflow-wrap: anywhere; }
|
||||
color: #4ade80;
|
||||
border-color: rgba(74, 222, 128, 0.4);
|
||||
}
|
||||
.status.warn {
|
||||
color: #fbbf24;
|
||||
border-color: rgba(251, 191, 36, 0.4);
|
||||
}
|
||||
|
||||
.row-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
|
||||
button.small { padding: 0.45rem 0.9rem; font-size: 0.85rem; border-radius: 8px; }
|
||||
|
||||
+9
-2
@@ -10,8 +10,15 @@ export type Movie = {
|
||||
processed_at?: string | null;
|
||||
};
|
||||
|
||||
export type ApiServiceSettingsRead = { url: string | null; api_key_configured: boolean };
|
||||
export type QbittorrentSettingsRead = {
|
||||
export type ServiceStatus = {
|
||||
status: "unconfigured" | "configured" | "tested" | "error";
|
||||
tested_version?: string | null;
|
||||
tested_at?: string | null;
|
||||
test_error?: string | null;
|
||||
};
|
||||
|
||||
export type ApiServiceSettingsRead = ServiceStatus & { url: string | null; api_key_configured: boolean };
|
||||
export type QbittorrentSettingsRead = ServiceStatus & {
|
||||
url: string | null;
|
||||
username: string | null;
|
||||
password_configured: boolean;
|
||||
|
||||
Reference in new issue
Block a user