From 45af25d6ce592ab879fade5a82af9d54d2236c15 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 27 Mar 2026 08:05:31 -0700 Subject: [PATCH] Fix: revert changes to qbittorrent widget endpoints (#6467) --- src/widgets/qbittorrent/component.jsx | 50 ++++++++++------------ src/widgets/qbittorrent/component.test.jsx | 34 +++------------ src/widgets/qbittorrent/widget.js | 8 ---- 3 files changed, 29 insertions(+), 63 deletions(-) diff --git a/src/widgets/qbittorrent/component.jsx b/src/widgets/qbittorrent/component.jsx index 0f0fa3af3..016ed3605 100644 --- a/src/widgets/qbittorrent/component.jsx +++ b/src/widgets/qbittorrent/component.jsx @@ -10,28 +10,13 @@ export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; - const { data: transferData, error: transferError } = useWidgetAPI(widget, "transfer"); - const { data: totalCountData, error: totalCountError } = useWidgetAPI(widget, "torrentCount"); - const { data: completedCountData, error: completedCountError } = useWidgetAPI(widget, "torrentCount", { - filter: "completed", - }); - const { data: leechTorrentData, error: leechTorrentError } = useWidgetAPI( - widget, - widget?.enableLeechProgress ? "torrents" : "", - widget?.enableLeechProgress ? { filter: "downloading" } : undefined, - ); + const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents"); - const apiError = transferError || totalCountError || completedCountError || leechTorrentError; - if (apiError) { - return ; + if (torrentError) { + return ; } - if ( - !transferData || - totalCountData === undefined || - completedCountData === undefined || - (widget?.enableLeechProgress && !leechTorrentData) - ) { + if (!torrentData) { return ( @@ -42,15 +27,24 @@ export default function Component({ service }) { ); } - const rateDl = Number(transferData?.dl_info_speed ?? 0); - const rateUl = Number(transferData?.up_info_speed ?? 0); - const totalCount = Number(totalCountData?.all ?? totalCountData?.count ?? totalCountData ?? 0); - const completedCount = Number( - completedCountData?.completed ?? completedCountData?.count ?? completedCountData?.all ?? completedCountData ?? 0, - ); - const leech = Math.max(0, totalCount - completedCount); + let rateDl = 0; + let rateUl = 0; + let completed = 0; + const leechTorrents = []; - const leechTorrents = Array.isArray(leechTorrentData) ? [...leechTorrentData] : []; + for (let i = 0; i < torrentData.length; i += 1) { + const torrent = torrentData[i]; + rateDl += torrent.dlspeed; + rateUl += torrent.upspeed; + if (torrent.progress === 1) { + completed += 1; + } + if (torrent.state.includes("DL") || torrent.state === "downloading") { + leechTorrents.push(torrent); + } + } + + const leech = torrentData.length - completed; const statePriority = [ "downloading", "forcedDL", @@ -79,7 +73,7 @@ export default function Component({ service }) { value={t("common.bibyterate", { value: rateDl, decimals: 1 })} highlightValue={rateDl} /> - + { expect(screen.getByText("qbittorrent.upload")).toBeInTheDocument(); }); - it("uses lightweight endpoints for counts/rates and filtered torrents for leech progress", () => { - useWidgetAPI.mockImplementation((_widget, endpoint, query) => { - if (endpoint === "transfer") { - return { data: { dl_info_speed: 15, up_info_speed: 3 }, error: undefined }; - } - if (endpoint === "torrentCount" && !query) { - return { data: 2, error: undefined }; - } - if (endpoint === "torrentCount" && query?.filter === "completed") { - return { data: 1, error: undefined }; - } - if (endpoint === "torrents" && query?.filter === "downloading") { - return { - data: [ - { - name: "B", - progress: 0.5, - state: "downloading", - eta: 60, - size: 100, - amount_left: 50, - }, - ], - error: undefined, - }; - } - return { data: undefined, error: undefined }; + it("computes leech/seed counts and upload/download rates, and can render leech progress entries", () => { + useWidgetAPI.mockReturnValue({ + data: [ + { name: "A", dlspeed: 10, upspeed: 1, progress: 1, state: "uploading" }, + { name: "B", dlspeed: 5, upspeed: 2, progress: 0.5, state: "downloading", eta: 60, size: 100, amount_left: 50 }, + ], + error: undefined, }); const service = { widget: { type: "qbittorrent", enableLeechProgress: true } }; diff --git a/src/widgets/qbittorrent/widget.js b/src/widgets/qbittorrent/widget.js index 9ec167faf..182ac9d1b 100644 --- a/src/widgets/qbittorrent/widget.js +++ b/src/widgets/qbittorrent/widget.js @@ -4,16 +4,8 @@ const widget = { proxyHandler: qbittorrentProxyHandler, mappings: { - transfer: { - endpoint: "transfer/info", - }, - torrentCount: { - endpoint: "torrents/count", - optionalParams: ["filter"], - }, torrents: { endpoint: "torrents/info", - optionalParams: ["filter"], }, }, };