Fix: torrentCount endpoint for qbittorrent doesnt work

This commit is contained in:
shamoon 2026-03-07 07:42:28 -08:00
parent 440e09a979
commit 1479823320
No known key found for this signature in database
3 changed files with 16 additions and 31 deletions

View File

@ -11,27 +11,19 @@ export default function Component({ service }) {
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", {
const { data: leechTorrentData, error: leechTorrentError } = useWidgetAPI(widget, "torrents", {
filter: "downloading",
});
const { data: seedTorrentData, error: seedTorrentError } = useWidgetAPI(widget, "torrents", {
filter: "completed",
});
const { data: leechTorrentData, error: leechTorrentError } = useWidgetAPI(
widget,
widget?.enableLeechProgress ? "torrents" : "",
widget?.enableLeechProgress ? { filter: "downloading" } : undefined,
);
const apiError = transferError || totalCountError || completedCountError || leechTorrentError;
const apiError = transferError || leechTorrentError || seedTorrentError;
if (apiError) {
return <Container service={service} error={apiError} />;
}
if (
!transferData ||
totalCountData === undefined ||
completedCountData === undefined ||
(widget?.enableLeechProgress && !leechTorrentData)
) {
if (!transferData || !leechTorrentData || !seedTorrentData) {
return (
<Container service={service}>
<Block label="qbittorrent.leech" />
@ -44,13 +36,10 @@ 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);
const leech = Array.isArray(leechTorrentData) ? leechTorrentData.length : 0;
const seed = Array.isArray(seedTorrentData) ? seedTorrentData.length : 0;
const leechTorrents = Array.isArray(leechTorrentData) ? [...leechTorrentData] : [];
const leechTorrents = widget?.enableLeechProgress && Array.isArray(leechTorrentData) ? [...leechTorrentData] : [];
const statePriority = [
"downloading",
"forcedDL",
@ -75,7 +64,7 @@ export default function Component({ service }) {
<Container service={service}>
<Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
<Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
<Block label="qbittorrent.seed" value={t("common.number", { value: completedCount })} />
<Block label="qbittorrent.seed" value={t("common.number", { value: seed })} />
<Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
</Container>
{widget?.enableLeechProgress &&

View File

@ -39,12 +39,6 @@ describe("widgets/qbittorrent/component", () => {
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: [
@ -60,6 +54,12 @@ describe("widgets/qbittorrent/component", () => {
error: undefined,
};
}
if (endpoint === "torrents" && query?.filter === "completed") {
return {
data: [{ name: "A", progress: 1, state: "uploading" }],
error: undefined,
};
}
return { data: undefined, error: undefined };
});

View File

@ -7,10 +7,6 @@ const widget = {
transfer: {
endpoint: "transfer/info",
},
torrentCount: {
endpoint: "torrents/count",
optionalParams: ["filter"],
},
torrents: {
endpoint: "torrents/info",
optionalParams: ["filter"],