✨ Endpoints qBittorrent (GET/PUT/test) persistant dans conf.json
This commit is contained in:
1 parent
de4a9b212f
commit
cfc0c54181
2 files changed
+86
No files matched your search
+48
@@ -16,6 +16,7 @@ from app import auth
|
||||
from app.conf_store import read_config, write_config
|
||||
from app.database import Base, engine, get_db
|
||||
from app.models import IsoMovie
|
||||
from app.qbittorrent import QbittorrentClient
|
||||
from app.radarr import RadarrClient, movie_file_path
|
||||
from app.schemas import (
|
||||
ApiServiceSettingsRead,
|
||||
@@ -26,6 +27,7 @@ from app.schemas import (
|
||||
HealthRead,
|
||||
IsoMovieRead,
|
||||
QbittorrentSettingsRead,
|
||||
QbittorrentSettingsWrite,
|
||||
RadarrSettingsRead,
|
||||
RadarrSettingsWrite,
|
||||
ScanResult,
|
||||
@@ -172,6 +174,52 @@ async def test_radarr() -> ConnectionResult:
|
||||
return ConnectionResult(success=True, version=version, message=f"Radarr {version} accessible")
|
||||
|
||||
|
||||
def qbittorrent_from_config() -> QbittorrentClient:
|
||||
qb = read_config().qbittorrent
|
||||
if not qb.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)
|
||||
|
||||
|
||||
@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
|
||||
)
|
||||
|
||||
|
||||
@app.put("/api/settings/qbittorrent", response_model=QbittorrentSettingsRead)
|
||||
def put_qbittorrent_settings(payload: QbittorrentSettingsWrite) -> QbittorrentSettingsRead:
|
||||
cfg = read_config()
|
||||
if payload.url is not None:
|
||||
cfg.qbittorrent.url = str(payload.url).rstrip("/")
|
||||
if payload.username:
|
||||
cfg.qbittorrent.username = payload.username
|
||||
if payload.password:
|
||||
cfg.qbittorrent.password = payload.password
|
||||
write_config(cfg)
|
||||
return QbittorrentSettingsRead(
|
||||
url=cfg.qbittorrent.url,
|
||||
username=cfg.qbittorrent.username,
|
||||
password_configured=cfg.qbittorrent.password is not None,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/settings/qbittorrent/test", response_model=ConnectionResult)
|
||||
async def test_qbittorrent() -> ConnectionResult:
|
||||
client = qbittorrent_from_config()
|
||||
try:
|
||||
version = await client.version()
|
||||
except (httpx.HTTPError, ValueError) as error:
|
||||
raise HTTPException(
|
||||
status_code=502, detail=f"Connexion qBittorrent impossible: {error}"
|
||||
) from error
|
||||
return ConnectionResult(
|
||||
success=True, version=version, message=f"qBittorrent {version} accessible"
|
||||
)
|
||||
|
||||
|
||||
@app.get("/api/movies", response_model=list[IsoMovieRead])
|
||||
def list_movies(db: DbSession) -> list[IsoMovie]:
|
||||
return list(db.scalars(select(IsoMovie).order_by(IsoMovie.title)).all())
|
||||
|
||||
Reference in new issue
Block a user