Skip to content

Commit

Permalink
Enhancement: downloading torrents list for deluge (#4436)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindfreak9100 authored Dec 18, 2024
1 parent 6b2a3da commit 59ed5ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/widgets/services/deluge.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ widget:
type: deluge
url: http://deluge.host.or.ip
password: password # webui password
enableLeechProgress: true # optional, defaults to false
```
12 changes: 6 additions & 6 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ export function cleanServiceGroups(groups) {
mappings,
display,

// deluge, qbittorrent
enableLeechProgress,

// diskstation
volume,

Expand Down Expand Up @@ -479,9 +482,6 @@ export function cleanServiceGroups(groups) {
// proxmox
node,

// qbittorrent
enableLeechProgress,

// speedtest
bitratePrecision,

Expand Down Expand Up @@ -572,6 +572,9 @@ export function cleanServiceGroups(groups) {
if (allowScrolling) widget.allowScrolling = allowScrolling;
if (refreshInterval) widget.refreshInterval = refreshInterval;
}
if (["deluge", "qbittorrent"].includes(type)) {
if (enableLeechProgress !== undefined) widget.enableLeechProgress = JSON.parse(enableLeechProgress);
}
if (["opnsense", "pfsense"].includes(type)) {
if (wan) widget.wan = wan;
}
Expand Down Expand Up @@ -674,9 +677,6 @@ export function cleanServiceGroups(groups) {
if (type === "spoolman") {
if (spoolIds !== undefined) widget.spoolIds = spoolIds;
}
if (type === "qbittorrent") {
if (enableLeechProgress !== undefined) widget.enableLeechProgress = JSON.parse(enableLeechProgress);
}
return widget;
});
return cleanedService;
Expand Down
31 changes: 25 additions & 6 deletions src/widgets/deluge/component.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useTranslation } from "next-i18next";

import QueueEntry from "../../components/widgets/queue/queueEntry";

import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
Expand Down Expand Up @@ -32,21 +34,38 @@ export default function Component({ service }) {
let rateDl = 0;
let rateUl = 0;
let completed = 0;
const leechTorrents = [];

for (let i = 0; i < keys.length; i += 1) {
const torrent = torrents[keys[i]];
rateDl += torrent.download_payload_rate;
rateUl += torrent.upload_payload_rate;
completed += torrent.total_remaining === 0 ? 1 : 0;
if (torrent.state === "Downloading") {
leechTorrents.push(torrent);
}
}

const leech = keys.length - completed || 0;

return (
<Container service={service}>
<Block label="deluge.leech" value={t("common.number", { value: leech })} />
<Block label="deluge.download" value={t("common.byterate", { value: rateDl })} />
<Block label="deluge.seed" value={t("common.number", { value: completed })} />
<Block label="deluge.upload" value={t("common.byterate", { value: rateUl })} />
</Container>
<>
<Container service={service}>
<Block label="deluge.leech" value={t("common.number", { value: leech })} />
<Block label="deluge.download" value={t("common.byterate", { value: rateDl })} />
<Block label="deluge.seed" value={t("common.number", { value: completed })} />
<Block label="deluge.upload" value={t("common.byterate", { value: rateUl })} />
</Container>
{widget?.enableLeechProgress &&
leechTorrents.map((queueEntry) => (
<QueueEntry
progress={queueEntry.progress}
timeLeft={t("common.duration", { value: queueEntry.eta })}
title={queueEntry.name}
activity={queueEntry.state}
key={`${queueEntry.name}-${queueEntry.total_remaining}`}
/>
))}
</>
);
}
1 change: 1 addition & 0 deletions src/widgets/deluge/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const dataParams = [
"download_payload_rate",
"upload_payload_rate",
"total_remaining",
"eta",
],
{},
];
Expand Down

0 comments on commit 59ed5ed

Please sign in to comment.