You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
homepage/src/widgets/downloadstation/component.jsx

42 lines
1.6 KiB

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}>
<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}>
<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>
);
}