42 lines
1.6 KiB
React
Raw Normal View History

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: listData, error: listError } = useWidgetAPI(widget, "list");
if (listError) {
return <Container error={listError} />;
}
const tasks = listData?.data?.tasks;
if (!tasks) {
return (
<Container service={service}>
2022-12-22 10:54:03 -08:00
<Block label="downloadstation.leech" />
<Block label="downloadstation.download" />
<Block label="downloadstation.seed" />
<Block label="downloadstation.upload" />
</Container>
);
}
const rateDl = tasks.reduce((acc, task) => acc + (task?.additional?.transfer?.speed_download ?? 0), 0);
const rateUl = tasks.reduce((acc, task) => acc + (task?.additional?.transfer?.speed_upload ?? 0), 0);
const completed = tasks.filter((task) => task?.additional?.transfer?.size_downloaded === task?.size)?.length || 0;
const leech = tasks.length - completed || 0;
return (
<Container service={service}>
2022-12-22 10:54:03 -08:00
<Block label="downloadstation.leech" value={t("common.number", { value: leech })} />
<Block label="downloadstation.download" value={t("common.bitrate", { value: rateDl })} />
<Block label="downloadstation.seed" value={t("common.number", { value: completed })} />
<Block label="downloadstation.upload" value={t("common.bitrate", { value: rateUl })} />
</Container>
);
}