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

View File

@@ -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 <Container service={service} error={apiError} />;
if (torrentError) {
return <Container service={service} error={torrentError} />;
}
if (
!transferData ||
totalCountData === undefined ||
completedCountData === undefined ||
(widget?.enableLeechProgress && !leechTorrentData)
) {
if (!torrentData) {
return (
<Container service={service}>
<Block label="qbittorrent.leech" />
@@ -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}
/>
<Block label="qbittorrent.seed" value={t("common.number", { value: completedCount })} />
<Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
<Block
label="qbittorrent.upload"
value={t("common.bibyterate", { value: rateUl, decimals: 1 })}

View File

@@ -34,33 +34,13 @@ describe("widgets/qbittorrent/component", () => {
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 } };

View File

@@ -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"],
},
},
};