Fix: revert changes to qbittorrent widget endpoints (#6467)

This commit is contained in:
shamoon
2026-03-27 08:05:31 -07:00
committed by GitHub
parent ea9fca02d3
commit 45af25d6ce
3 changed files with 29 additions and 63 deletions
+22 -28
View File
@@ -10,28 +10,13 @@ export default function Component({ service }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { widget } = service; const { widget } = service;
const { data: transferData, error: transferError } = useWidgetAPI(widget, "transfer"); const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
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 apiError = transferError || totalCountError || completedCountError || leechTorrentError; if (torrentError) {
if (apiError) { return <Container service={service} error={torrentError} />;
return <Container service={service} error={apiError} />;
} }
if ( if (!torrentData) {
!transferData ||
totalCountData === undefined ||
completedCountData === undefined ||
(widget?.enableLeechProgress && !leechTorrentData)
) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="qbittorrent.leech" /> <Block label="qbittorrent.leech" />
@@ -42,15 +27,24 @@ export default function Component({ service }) {
); );
} }
const rateDl = Number(transferData?.dl_info_speed ?? 0); let rateDl = 0;
const rateUl = Number(transferData?.up_info_speed ?? 0); let rateUl = 0;
const totalCount = Number(totalCountData?.all ?? totalCountData?.count ?? totalCountData ?? 0); let completed = 0;
const completedCount = Number( const leechTorrents = [];
completedCountData?.completed ?? completedCountData?.count ?? completedCountData?.all ?? completedCountData ?? 0,
);
const leech = Math.max(0, totalCount - completedCount);
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 = [ const statePriority = [
"downloading", "downloading",
"forcedDL", "forcedDL",
@@ -79,7 +73,7 @@ export default function Component({ service }) {
value={t("common.bibyterate", { value: rateDl, decimals: 1 })} value={t("common.bibyterate", { value: rateDl, decimals: 1 })}
highlightValue={rateDl} highlightValue={rateDl}
/> />
<Block label="qbittorrent.seed" value={t("common.number", { value: completedCount })} /> <Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
<Block <Block
label="qbittorrent.upload" label="qbittorrent.upload"
value={t("common.bibyterate", { value: rateUl, decimals: 1 })} value={t("common.bibyterate", { value: rateUl, decimals: 1 })}
+7 -27
View File
@@ -34,33 +34,13 @@ describe("widgets/qbittorrent/component", () => {
expect(screen.getByText("qbittorrent.upload")).toBeInTheDocument(); expect(screen.getByText("qbittorrent.upload")).toBeInTheDocument();
}); });
it("uses lightweight endpoints for counts/rates and filtered torrents for leech progress", () => { it("computes leech/seed counts and upload/download rates, and can render leech progress entries", () => {
useWidgetAPI.mockImplementation((_widget, endpoint, query) => { useWidgetAPI.mockReturnValue({
if (endpoint === "transfer") { data: [
return { data: { dl_info_speed: 15, up_info_speed: 3 }, error: undefined }; { 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 },
if (endpoint === "torrentCount" && !query) { ],
return { data: 2, error: undefined }; 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 };
}); });
const service = { widget: { type: "qbittorrent", enableLeechProgress: true } }; const service = { widget: { type: "qbittorrent", enableLeechProgress: true } };
-8
View File
@@ -4,16 +4,8 @@ const widget = {
proxyHandler: qbittorrentProxyHandler, proxyHandler: qbittorrentProxyHandler,
mappings: { mappings: {
transfer: {
endpoint: "transfer/info",
},
torrentCount: {
endpoint: "torrents/count",
optionalParams: ["filter"],
},
torrents: { torrents: {
endpoint: "torrents/info", endpoint: "torrents/info",
optionalParams: ["filter"],
}, },
}, },
}; };