fix: include all active torrent states
This commit is contained in:
@@ -210,7 +210,8 @@ export const SERVICE_REGISTRY: Record<string, ServiceBinding> = {
|
||||
{
|
||||
kind: "active",
|
||||
name: "Active torrents",
|
||||
description: "Torrents currently downloading or uploading.",
|
||||
description:
|
||||
"All active download/upload work, including queued and stalled transfers.",
|
||||
refreshIntervalMs: 15_000,
|
||||
defaultConfig: {},
|
||||
configSchema: { type: "object", properties: {}, required: [] },
|
||||
|
||||
@@ -40,19 +40,30 @@ function formatProgress(progress: number | null): string {
|
||||
return `${Math.round(progress * 100)}% complete`;
|
||||
}
|
||||
|
||||
function formatState(state: string | null, direction?: ActiveTorrent["direction"]): string {
|
||||
function formatState(
|
||||
state: string | null,
|
||||
direction?: ActiveTorrent["direction"],
|
||||
): string {
|
||||
const labels: Record<string, string> = {
|
||||
downloading: "Downloading",
|
||||
forcedDL: "Downloading",
|
||||
stalledDL: "Download stalled",
|
||||
queuedDL: "Queued download",
|
||||
metaDL: "Downloading metadata",
|
||||
forcedMetaDL: "Downloading metadata",
|
||||
checkingDL: "Checking download",
|
||||
allocating: "Allocating",
|
||||
uploading: "Uploading",
|
||||
forcedUP: "Uploading",
|
||||
stalledUP: "Upload stalled",
|
||||
queuedUP: "Queued upload",
|
||||
checkingUP: "Checking upload",
|
||||
checkingResumeData: "Checking resume data",
|
||||
moving: "Moving",
|
||||
};
|
||||
if (state && labels[state]) return labels[state];
|
||||
if (direction) return direction === "downloading" ? "Downloading" : "Uploading";
|
||||
if (direction)
|
||||
return direction === "downloading" ? "Downloading" : "Uploading";
|
||||
return state || "Unknown state";
|
||||
}
|
||||
|
||||
@@ -91,7 +102,8 @@ export function QbittorrentActiveTorrentsWidget({
|
||||
{torrent.name ?? "Unknown torrent"}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{formatSize(torrent.size)} · {formatProgress(torrent.progress)}
|
||||
{formatSize(torrent.size)} ·{" "}
|
||||
{formatProgress(torrent.progress)}
|
||||
</p>
|
||||
</div>
|
||||
<Badge
|
||||
@@ -103,7 +115,8 @@ export function QbittorrentActiveTorrentsWidget({
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-1 text-xs text-muted-foreground">
|
||||
↓ {formatSpeed(torrent.dl_speed)} · ↑ {formatSpeed(torrent.up_speed)}
|
||||
↓ {formatSpeed(torrent.dl_speed)} · ↑{" "}
|
||||
{formatSpeed(torrent.up_speed)}
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
|
||||
@@ -50,7 +50,9 @@ const UPLOAD_STATES = new Set(["uploading", "forcedUP", "stalledUP"]);
|
||||
function stateLabel(state: string): string {
|
||||
return (
|
||||
STATE_LABELS[state] ??
|
||||
state.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/^./, (char) => char.toUpperCase())
|
||||
state
|
||||
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
.replace(/^./, (char) => char.toUpperCase())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,7 +78,8 @@ export function QbittorrentTotalsWidget({
|
||||
payload?.by_direction?.downloading ??
|
||||
fallbackDirectionCount(byState, DOWNLOAD_STATES);
|
||||
const uploading =
|
||||
payload?.by_direction?.uploading ?? fallbackDirectionCount(byState, UPLOAD_STATES);
|
||||
payload?.by_direction?.uploading ??
|
||||
fallbackDirectionCount(byState, UPLOAD_STATES);
|
||||
const stateEntries = Object.entries(byState).sort(
|
||||
([stateA, countA], [stateB, countB]) =>
|
||||
countB - countA || stateLabel(stateA).localeCompare(stateLabel(stateB)),
|
||||
@@ -95,7 +98,9 @@ export function QbittorrentTotalsWidget({
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<div className="rounded-md border p-3">
|
||||
<div className="text-2xl font-semibold">{payload.total ?? 0}</div>
|
||||
<div className="text-xs text-muted-foreground">Total torrents</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
Total torrents
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-md border p-3">
|
||||
<div className="text-2xl font-semibold">{downloading}</div>
|
||||
@@ -126,7 +131,9 @@ export function QbittorrentTotalsWidget({
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-xs text-muted-foreground">No torrent data available.</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
No torrent data available.
|
||||
</div>
|
||||
)}
|
||||
</SectionCard>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user