From c6a31397d7d830444554f53450353e25013a044d Mon Sep 17 00:00:00 2001 From: yk Date: Sat, 20 Jan 2024 20:08:33 +0800 Subject: [PATCH] add more custom fields to qbittorrent widget --- docs/widgets/services/qbittorrent.md | 4 +- public/locales/en/common.json | 12 +++- src/widgets/qbittorrent/component.jsx | 86 +++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/docs/widgets/services/qbittorrent.md b/docs/widgets/services/qbittorrent.md index 28b9ee5f..dc364397 100644 --- a/docs/widgets/services/qbittorrent.md +++ b/docs/widgets/services/qbittorrent.md @@ -5,7 +5,9 @@ description: qBittorrent Widget Configuration Uses the same username and password used to login from the web. -Allowed fields: `["leech", "download", "seed", "upload"]`. +Allowed fields: `["leech", "download", "seed", "upload", "total", "error", +"checking", "moving", "activeDl", "activeUl", "active", "paused", "queued", +"stalled"]`. ```yaml widget: diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 2192a7de..3a6d5ecb 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -203,7 +203,17 @@ "download": "Download", "upload": "Upload", "leech": "Leech", - "seed": "Seed" + "seed": "Seed", + "total": "Total", + "error": "Error", + "checking": "Checking", + "moving": "Moving", + "activeUl": "Active Uploads", + "activeDl": "Active Downloads", + "active": "Active", + "paused": "Paused", + "queued": "Queued", + "stalled": "Stalled" }, "qnap": { "cpuUsage": "CPU Usage", diff --git a/src/widgets/qbittorrent/component.jsx b/src/widgets/qbittorrent/component.jsx index 615709ea..cc7a71c1 100644 --- a/src/widgets/qbittorrent/component.jsx +++ b/src/widgets/qbittorrent/component.jsx @@ -15,6 +15,17 @@ export default function Component({ service }) { return ; } + // Default fields + if (widget.fields === null || widget.fields.length === 0) { + widget.fields = ["leech", "download", "seed", "upload"]; + } + + const MAX_ALLOWED_FIELDS = 4; + // Limits max number of displayed fields + if (widget.fields != null && widget.fields.length > MAX_ALLOWED_FIELDS) { + widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS); + } + if (!torrentData) { return ( @@ -22,6 +33,16 @@ export default function Component({ service }) { + + + + + + + + + + ); } @@ -29,6 +50,15 @@ export default function Component({ service }) { let rateDl = 0; let rateUl = 0; let completed = 0; + let error = 0; + let checking = 0; + let moving = 0; + let activeUl = 0; + let activeDl = 0; + let active = 0; + let paused = 0; + let queued = 0; + let stalled = 0; for (let i = 0; i < torrentData.length; i += 1) { const torrent = torrentData[i]; @@ -37,9 +67,55 @@ export default function Component({ service }) { if (torrent.progress === 1) { completed += 1; } + switch (torrent.state) { + case "error": + case "missingFiles": + case "unknown": + error += 1; + break; + + case "checkingResumeData": + case "checkingUP": + case "checkingDL": + checking += 1; + break; + + case "moving": + moving += 1; + break; + + case "uploading": + active += 1; + activeUl += 1; + break; + + case "downloading": + active += 1; + activeDl += 1; + break; + + case "pausedUP": + case "pausedDL": + paused += 1; + break; + + case "stalledUP": + case "stalledDL": + stalled += 1; + break; + + case "queuedUP": + case "queuedDL": + queued += 1; + break; + + default: + break; + } } const leech = torrentData.length - completed; + const total = torrentData.length; return ( @@ -47,6 +123,16 @@ export default function Component({ service }) { + + + + + + + + + + ); }