Add qBittorrent and SABnzbd: a Download clients page with stuck, disconnected, paused and full-disk alerts
Each client is read every five minutes (read-only; qBittorrent's sign-in is the only POST): speed, queue and item states, network connection or paused queue, free space, SABnzbd's failures and warnings. Shared adapter, sync service, download_state table, /api/downloads, metrics and docs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7775e5dd9
commit
7618bf0f0a
32 files changed
+10715
-12
No files matched your search
@@ -0,0 +1,273 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type DownloadClient, type DownloadItem, type DownloadState } from "../api/client";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { formatBytes } from "./settings/StorageSettings";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
const KIND_NAMES: Record<DownloadClient["kind"], string> = { qbittorrent: "qBittorrent", sabnzbd: "SABnzbd" };
|
||||
const SHOWN = 25;
|
||||
|
||||
const STATE_BADGE: Record<DownloadState, string> = {
|
||||
downloading: "bg-blue-lt text-blue",
|
||||
queued: "bg-secondary-lt text-secondary",
|
||||
waiting: "bg-secondary-lt text-secondary",
|
||||
stalled: "bg-yellow-lt text-yellow",
|
||||
paused: "bg-secondary-lt text-secondary",
|
||||
processing: "bg-azure-lt text-azure",
|
||||
error: "bg-red-lt text-red",
|
||||
seeding: "bg-green-lt text-green",
|
||||
completed: "bg-green-lt text-green",
|
||||
failed: "bg-red-lt text-red",
|
||||
other: "bg-secondary-lt text-secondary",
|
||||
};
|
||||
|
||||
const speedText = (n: number | null): string => (n === null ? "—" : `${formatBytes(n)}/s`);
|
||||
|
||||
/** "2 h 5 min", "14 min", "40 s". */
|
||||
function durationText(seconds: number): string {
|
||||
if (seconds >= 86400) return `${Math.floor(seconds / 86400)} d ${Math.floor((seconds % 86400) / 3600)} h`;
|
||||
if (seconds >= 3600) return `${Math.floor(seconds / 3600)} h ${Math.floor((seconds % 3600) / 60)} min`;
|
||||
if (seconds >= 60) return `${Math.round(seconds / 60)} min`;
|
||||
return `${Math.max(1, Math.round(seconds))} s`;
|
||||
}
|
||||
|
||||
function Badge({ c }: { c: DownloadClient }) {
|
||||
if (!c.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
||||
if (!c.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
|
||||
if (!c.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
||||
if (c.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
|
||||
if (c.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
|
||||
return <span className="badge bg-green-lt text-green">In order</span>;
|
||||
}
|
||||
|
||||
function Tile({ label, value, sub, warn }: { label: string; value: string; sub?: string | null; warn?: boolean }) {
|
||||
return (
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">{label}</div>
|
||||
<div className={`h2 mb-0 ${warn ? "text-yellow" : ""}`}>{value}</div>
|
||||
{sub && <div className="text-secondary small">{sub}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ItemsTable({ items, stuck }: { items: DownloadItem[]; stuck: Set<string> }) {
|
||||
return (
|
||||
<>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>State</th>
|
||||
<th>Progress</th>
|
||||
<th>Speed</th>
|
||||
<th>Left</th>
|
||||
<th>Category</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.slice(0, SHOWN).map((i) => {
|
||||
const pct = i.progress === null ? null : Math.round(i.progress * 100);
|
||||
const isStuck = stuck.has(i.id);
|
||||
return (
|
||||
<tr key={i.id}>
|
||||
<td className="text-break">{i.name}</td>
|
||||
<td>
|
||||
{isStuck ? <span className="badge bg-red-lt text-red">stuck</span> : <span className={`badge ${STATE_BADGE[i.state]}`}>{i.state}</span>}
|
||||
{i.rawState.toLowerCase() !== i.state && <div className="small text-secondary">{i.rawState}</div>}
|
||||
{isStuck && i.state === "stalled" && i.activityAt && (
|
||||
<div className="small text-red">
|
||||
nothing moved <TimeAgo value={i.activityAt} />
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td style={{ minWidth: 120 }}>
|
||||
{pct === null ? (
|
||||
<span className="text-secondary">—</span>
|
||||
) : (
|
||||
<>
|
||||
<div className="progress progress-sm">
|
||||
<div className="progress-bar" style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
<div className="small text-secondary">
|
||||
{pct}%{i.size ? ` of ${formatBytes(i.size)}` : ""}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</td>
|
||||
<td className="text-secondary">{i.speed ? speedText(i.speed) : "—"}</td>
|
||||
<td className="text-secondary">
|
||||
{i.left !== null && i.left > 0 ? formatBytes(i.left) : "—"}
|
||||
{i.eta !== null && <div className="small">{durationText(i.eta)}</div>}
|
||||
</td>
|
||||
<td className="text-secondary">{i.category ?? "—"}</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{items.length > SHOWN && <div className="text-secondary small">{items.length - SHOWN} more are listed by the client (the ones needing a look first).</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ c }: { c: DownloadClient }) {
|
||||
const s = c.state;
|
||||
const stuck = new Set(s?.stuck ?? []);
|
||||
const failedRecent = new Set(s?.failedRecent ?? []);
|
||||
const failed = (s?.failed ?? []).filter((f) => failedRecent.has(f.id));
|
||||
const pending = s ? s.total - s.counts.seeding - s.counts.completed - s.counts.failed : 0;
|
||||
const fullest = s?.disks && s.disks.length > 0 ? s.disks.reduce((a, b) => (a.free < b.free ? a : b)) : null;
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{c.name} <span className="text-secondary fw-normal">{KIND_NAMES[c.kind]}{s?.version ? ` ${s.version}` : ""}</span> <Badge c={c} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{c.status ? <>read <TimeAgo value={c.status.at} /></> : "not read yet"}</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{c.status && !c.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {c.status.error ?? "no answer"}.</div>}
|
||||
{c.problems.length > 0 && (
|
||||
<ul className="mb-3">
|
||||
{c.problems.map((x) => (
|
||||
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
|
||||
{x.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{s && (
|
||||
<>
|
||||
<div className="row g-3 mb-3">
|
||||
<Tile label="Downloading" value={speedText(s.speedDown)} sub={s.speedUp !== null ? `uploading ${speedText(s.speedUp)}` : null} />
|
||||
<Tile
|
||||
label={c.kind === "sabnzbd" ? "Queue" : "Not finished"}
|
||||
value={String(pending)}
|
||||
sub={[`${s.counts.downloading} downloading`, `${s.counts.queued + s.counts.waiting} waiting`, s.counts.stalled > 0 ? `${s.counts.stalled} stalled` : null, s.counts.error > 0 ? `${s.counts.error} in error` : null, c.kind === "qbittorrent" ? `${s.counts.seeding} seeding` : null].filter(Boolean).join(", ")}
|
||||
/>
|
||||
{c.kind === "qbittorrent" ? (
|
||||
<Tile label="Stuck" value={String(stuck.size)} sub={stuck.size > 0 ? "in error, or nothing moving for a day" : "nothing stuck"} warn={stuck.size > 0} />
|
||||
) : (
|
||||
<Tile label="Failed in the last day" value={s.failed === null ? "—" : String(failedRecent.size)} sub={s.failed === null ? "could not be read" : null} warn={failedRecent.size > 0} />
|
||||
)}
|
||||
{c.kind === "qbittorrent" ? (
|
||||
<Tile
|
||||
label="Network"
|
||||
value={s.connection === null ? "—" : s.connection}
|
||||
sub={s.connection === "firewalled" ? "no incoming connections — it still works" : s.connection === "disconnected" ? "no peers or DHT" : null}
|
||||
warn={s.connection === "disconnected"}
|
||||
/>
|
||||
) : (
|
||||
<Tile label="Queue is" value={s.paused ? "Paused" : "Running"} sub={s.paused && s.since.pausedSince ? `for ${durationText((Date.now() - Date.parse(s.since.pausedSince)) / 1000)}` : null} warn={s.paused && pending > 0} />
|
||||
)}
|
||||
{fullest && <Tile label="Free space" value={formatBytes(fullest.free)} sub={fullest.total ? `of ${formatBytes(fullest.total)} (${fullest.label.toLowerCase()})` : fullest.label.toLowerCase()} warn={fullest.total ? fullest.free / fullest.total < 0.1 : fullest.free < 20 * 1024 ** 3} />}
|
||||
</div>
|
||||
{s.disks && s.disks.some((d) => d.total) && (
|
||||
<div className="mb-3">
|
||||
<h4>Disks</h4>
|
||||
{s.disks
|
||||
.filter((d) => d.total)
|
||||
.map((d) => {
|
||||
const free = d.total ? d.free / d.total : 1;
|
||||
return (
|
||||
<div key={d.label} className="mb-1" style={{ maxWidth: 520 }}>
|
||||
<div className="progress progress-sm">
|
||||
<div className={`progress-bar ${free < 0.05 ? "bg-red" : free < 0.1 ? "bg-yellow" : "bg-green"}`} style={{ width: `${Math.min(100, (1 - free) * 100)}%` }} />
|
||||
</div>
|
||||
<div className="small text-secondary">
|
||||
{d.label}: {formatBytes(d.free)} free of {formatBytes(d.total!)} ({Math.floor(free * 100)}%)
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{s.items.length > 0 && (
|
||||
<>
|
||||
<h4>{c.kind === "sabnzbd" ? "Queue" : "Not finished"}</h4>
|
||||
<ItemsTable items={s.items} stuck={stuck} />
|
||||
{s.counts.seeding + s.counts.completed > 0 && <div className="text-secondary small">{s.counts.seeding + s.counts.completed} more are finished and idle (seeding or stopped), and not listed.</div>}
|
||||
</>
|
||||
)}
|
||||
{s.items.length === 0 && <div className="text-secondary">{s.total === 0 ? "Nothing in the queue." : `${s.total} item${s.total === 1 ? "" : "s"}, all finished and idle.`}</div>}
|
||||
{failed.length > 0 && (
|
||||
<>
|
||||
<h4 className="mt-3">Failed in the last day</h4>
|
||||
<ul className="mb-0">
|
||||
{failed.map((f) => (
|
||||
<li key={f.id} className="text-break">
|
||||
{f.name} <span className="text-secondary small"><TimeAgo value={f.activityAt} /></span>
|
||||
{f.message && <div className="small text-red">{f.message}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
{s.warnings && s.warnings.count > 0 && (
|
||||
<div className="mt-3">
|
||||
<h4>
|
||||
{KIND_NAMES[c.kind]}’s own warnings <span className="text-secondary fw-normal small">({s.warnings.count} in its list — cleared in its own Warnings page)</span>
|
||||
</h4>
|
||||
<ul className="mb-0 small text-secondary">
|
||||
{s.warnings.recent.map((w, i) => (
|
||||
<li key={i} className="text-break">
|
||||
{w}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** qBittorrent and SABnzbd: how fast they are going, what is in their queues and in what state, what is stuck or failed, and the room they have. */
|
||||
export default function Downloads() {
|
||||
const [data, setData] = useState<DownloadClient[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.downloads
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.clients);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Download clients</h2>
|
||||
<p className="text-secondary">
|
||||
qBittorrent and SABnzbd, read every few minutes (see <Link to="/integrations">Integrations</Link>) — nothing is added, paused or removed. <strong>Downloads that are stuck</strong>, <strong>no connection</strong>, <strong>a queue left paused or getting nothing</strong> and{" "}
|
||||
<strong>a disk nearly full</strong> are alerts — see <Link to="/alerts">Alerts</Link>. What Sonarr, Radarr and the others think of their downloads is on <Link to="/media">Media managers</Link>.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
{data && data.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<EmptyState title="No download client connected" hint="Add qBittorrent (its Web UI address, and the user name and password of the Web UI) or SABnzbd (its address and API key) under Integrations." />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((c) => <Card key={c.id} c={c} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user