2022-09-26 00:35:54 +03:00
|
|
|
import { useTranslation } from "next-i18next";
|
|
|
|
|
2022-09-26 15:25:10 +03:00
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import Block from "components/services/widget/block";
|
2022-09-27 22:59:14 +03:00
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-09-28 02:32:30 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-09-26 00:35:54 +03:00
|
|
|
export default function Component({ service }) {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { widget } = service;
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue");
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-11-07 09:24:15 -08:00
|
|
|
if (queueError) {
|
|
|
|
return <Container error={queueError} />;
|
2022-09-26 00:35:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!queueData) {
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="sabnzbd.rate" />
|
|
|
|
<Block label="sabnzbd.queue" />
|
|
|
|
<Block label="sabnzbd.timeleft" />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="sabnzbd.rate" value={t("common.bitrate", { value: fromUnits(queueData.queue.speed) * 8 })} />
|
|
|
|
<Block label="sabnzbd.queue" value={t("common.number", { value: queueData.queue.noofslots })} />
|
|
|
|
<Block label="sabnzbd.timeleft" value={queueData.queue.timeleft} />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|