feat: gestion des téléchargements qBittorrent avec import automatique

- Nouvelle table `torrent_downloads` pour suivre les téléchargements gérés
- API : endpoint POST /torrent-downloads/notify (webhook optionnel) et GET /torrent-downloads
- Poller background toutes les 30s qui interroge qBittorrent pour détecter
  les torrents terminés — aucune config "run external program" nécessaire
- Import automatique : déplacement des fichiers vers la série cible,
  renommage selon le pattern existant (détection de la largeur des digits),
  support packs multi-volumes, scan job déclenché après import
- Page /downloads dans le backoffice : filtres, auto-refresh, carte par download
- Toggle auto-import intégré dans la card qBittorrent des settings
- Erreurs de détection download affichées dans le détail des jobs
- Volume /downloads monté dans docker-compose

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-26 14:43:10 +01:00
parent a2de2e1601
commit 4bb142d1dd
21 changed files with 1197 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
"use client";
import { useState, useEffect } from "react";
import { Card, CardHeader, CardTitle, CardDescription, CardContent, Button, FormField, FormInput, Icon } from "@/app/components/ui";
import { Card, CardHeader, CardTitle, CardDescription, CardContent, Button, FormField, FormInput, FormSelect, Icon } from "@/app/components/ui";
import { useTranslation } from "@/lib/i18n/context";
export function QBittorrentCard({ handleUpdateSetting }: { handleUpdateSetting: (key: string, value: unknown) => Promise<void> }) {
@@ -11,6 +11,7 @@ export function QBittorrentCard({ handleUpdateSetting }: { handleUpdateSetting:
const [qbPassword, setQbPassword] = useState("");
const [isTesting, setIsTesting] = useState(false);
const [testResult, setTestResult] = useState<{ success: boolean; message: string } | null>(null);
const [importEnabled, setImportEnabled] = useState(false);
useEffect(() => {
fetch("/api/settings/qbittorrent")
@@ -23,6 +24,10 @@ export function QBittorrentCard({ handleUpdateSetting }: { handleUpdateSetting:
}
})
.catch(() => {});
fetch("/api/settings/torrent_import")
.then((r) => (r.ok ? r.json() : null))
.then((data) => { if (data?.enabled !== undefined) setImportEnabled(data.enabled); })
.catch(() => {});
}, []);
function saveQbittorrent() {
@@ -118,6 +123,32 @@ export function QBittorrentCard({ handleUpdateSetting }: { handleUpdateSetting:
</span>
)}
</div>
<div className="border-t border-border/40 pt-4">
<FormField className="max-w-xs">
<label className="text-sm font-medium text-muted-foreground mb-1 block">
{t("settings.torrentImportEnabled")}
</label>
<FormSelect
value={importEnabled ? "true" : "false"}
onChange={(e) => {
const val = e.target.value === "true";
setImportEnabled(val);
handleUpdateSetting("torrent_import", { enabled: val });
}}
>
<option value="false">{t("common.disabled")}</option>
<option value="true">{t("common.enabled")}</option>
</FormSelect>
</FormField>
{importEnabled && (
<div className="mt-3 rounded-lg border border-success/20 bg-success/5 p-3 flex items-start gap-2">
<Icon name="check" size="sm" className="text-success mt-0.5 shrink-0" />
<p className="text-sm text-muted-foreground">{t("settings.torrentImportPollingInfo")}</p>
</div>
)}
</div>
</div>
</CardContent>
</Card>