diff --git a/src/widgets/sabnzbd/component.jsx b/src/widgets/sabnzbd/component.jsx index 2077695ba..b38cb90f1 100644 --- a/src/widgets/sabnzbd/component.jsx +++ b/src/widgets/sabnzbd/component.jsx @@ -4,6 +4,16 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +function fromUnits(value) { + const units = ["B", "K", "M", "G", "T", "P"]; + const [number, unit] = value.split(" "); + const index = units.indexOf(unit); + if (index === -1) { + return 0; + } + return parseFloat(number) * 1024 ** index; +} + export default function Component({ service }) { const { t } = useTranslation(); @@ -27,7 +37,7 @@ export default function Component({ service }) { return ( - + diff --git a/src/widgets/transmission/component.jsx b/src/widgets/transmission/component.jsx index f082a0d97..0ec62de04 100644 --- a/src/widgets/transmission/component.jsx +++ b/src/widgets/transmission/component.jsx @@ -27,42 +27,18 @@ export default function Component({ service }) { } const { torrents } = torrentData.arguments; - let rateDl = 0; - let rateUl = 0; - let completed = 0; - - for (let i = 0; i < torrents.length; i += 1) { - const torrent = torrents[i]; - rateDl += torrent.rateDownload; - rateUl += torrent.rateUpload; - if (torrent.percentDone === 1) { - completed += 1; - } - } + const rateDl = torrents.reduce((acc, torrent) => acc + torrent.rateDownload, 0); + const rateUl = torrents.reduce((acc, torrent) => acc + torrent.rateUpload, 0); + const completed = torrents.filter((torrent) => torrent.percentDone === 1); const leech = torrents.length - completed; - let unitsDl = "KB/s"; - let unitsUl = "KB/s"; - rateDl /= 1024; - rateUl /= 1024; - - if (rateDl > 1024) { - rateDl /= 1024; - unitsDl = "MB/s"; - } - - if (rateUl > 1024) { - rateUl /= 1024; - unitsUl = "MB/s"; - } - return ( - + - + ); }