2022-11-23 11:51:53 -08:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import Block from "components/services/widget/block";
|
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
|
|
|
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { widget } = service;
|
|
|
|
|
|
|
|
const { data: torrentData, error: torrentError } = useWidgetAPI(widget);
|
|
|
|
|
|
|
|
if (torrentError) {
|
|
|
|
return <Container error={torrentError} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!torrentData) {
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="deluge.leech" />
|
|
|
|
<Block label="deluge.download" />
|
|
|
|
<Block label="deluge.seed" />
|
|
|
|
<Block label="deluge.upload" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { torrents } = torrentData;
|
2022-11-23 15:08:06 -08:00
|
|
|
const keys = torrents ? Object.keys(torrents) : [];
|
2022-11-23 12:01:31 -08:00
|
|
|
|
2022-11-23 11:51:53 -08:00
|
|
|
let rateDl = 0;
|
|
|
|
let rateUl = 0;
|
|
|
|
let completed = 0;
|
2022-11-23 12:01:31 -08:00
|
|
|
for (let i = 0; i < keys.length; i += 1) {
|
|
|
|
const torrent = torrents[keys[i]];
|
2022-11-23 11:51:53 -08:00
|
|
|
rateDl += torrent.download_payload_rate;
|
|
|
|
rateUl += torrent.upload_payload_rate;
|
|
|
|
completed += torrent.total_remaining === 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2022-11-23 12:01:31 -08:00
|
|
|
const leech = keys.length - completed || 0;
|
2022-11-23 11:51:53 -08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="deluge.leech" value={t("common.number", { value: leech })} />
|
2023-03-03 00:48:28 -08:00
|
|
|
<Block label="deluge.download" value={t("common.byterate", { value: rateDl })} />
|
2022-11-23 11:51:53 -08:00
|
|
|
<Block label="deluge.seed" value={t("common.number", { value: completed })} />
|
2023-03-03 00:48:28 -08:00
|
|
|
<Block label="deluge.upload" value={t("common.byterate", { value: rateUl })} />
|
2022-11-23 11:51:53 -08:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|