Update qbit component to show leech progress
This commit is contained in:
parent
a3f0fc9599
commit
321549fa88
@ -1,12 +1,38 @@
|
|||||||
import { useTranslation } from "next-i18next";
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import QueueEntry from "../../components/widgets/queue/queueEntry";
|
||||||
|
|
||||||
import Container from "components/services/widget/container";
|
import Container from "components/services/widget/container";
|
||||||
import Block from "components/services/widget/block";
|
import Block from "components/services/widget/block";
|
||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
|
function formatTimeLeft(inputSeconds) {
|
||||||
|
let seconds = inputSeconds;
|
||||||
|
const years = Math.floor(seconds / (365 * 24 * 60 * 60));
|
||||||
|
seconds %= 365 * 24 * 60 * 60; // Remaining seconds after subtracting years
|
||||||
|
|
||||||
|
const days = Math.floor(seconds / (24 * 60 * 60));
|
||||||
|
seconds %= 24 * 60 * 60; // Remaining seconds after subtracting days
|
||||||
|
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
seconds %= 3600; // Remaining seconds after subtracting hours
|
||||||
|
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainingSeconds = seconds % 60;
|
||||||
|
|
||||||
|
let result = '';
|
||||||
|
if (years > 0) result += `${years}y `;
|
||||||
|
if (days > 0) result += `${days}d `;
|
||||||
|
if (hours > 0) result += `${hours}h `;
|
||||||
|
if (minutes > 0) result += `${minutes}m `;
|
||||||
|
result += `${remainingSeconds}s`;
|
||||||
|
|
||||||
|
return result.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function Component({ service }) {
|
export default function Component({ service }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { widget } = service;
|
const { widget } = service;
|
||||||
|
|
||||||
const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
|
const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents");
|
||||||
@ -29,6 +55,7 @@ export default function Component({ service }) {
|
|||||||
let rateDl = 0;
|
let rateDl = 0;
|
||||||
let rateUl = 0;
|
let rateUl = 0;
|
||||||
let completed = 0;
|
let completed = 0;
|
||||||
|
const leechTorrents = [];
|
||||||
|
|
||||||
for (let i = 0; i < torrentData.length; i += 1) {
|
for (let i = 0; i < torrentData.length; i += 1) {
|
||||||
const torrent = torrentData[i];
|
const torrent = torrentData[i];
|
||||||
@ -37,16 +64,32 @@ export default function Component({ service }) {
|
|||||||
if (torrent.progress === 1) {
|
if (torrent.progress === 1) {
|
||||||
completed += 1;
|
completed += 1;
|
||||||
}
|
}
|
||||||
|
if (torrent.state.includes("DL") || torrent.state === "downloading") {
|
||||||
|
leechTorrents.push(torrent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const leech = torrentData.length - completed;
|
const leech = torrentData.length - completed;
|
||||||
|
const enableLeechProgress = widget?.enableLeechProgress && Array.isArray(leechTorrents) && leechTorrents.length > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<>
|
||||||
<Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
|
<Container service={service}>
|
||||||
<Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
|
<Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
|
||||||
<Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
|
<Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
|
||||||
<Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
|
<Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
|
||||||
</Container>
|
<Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
|
||||||
|
</Container>
|
||||||
|
{enableLeechProgress &&
|
||||||
|
leechTorrents.map((queueEntry) => (
|
||||||
|
<QueueEntry
|
||||||
|
progress={(queueEntry.progress) * 100}
|
||||||
|
timeLeft={formatTimeLeft(queueEntry.eta)}
|
||||||
|
title={queueEntry.name}
|
||||||
|
activity={queueEntry.state}
|
||||||
|
key={`${queueEntry.name}-${queueEntry.amount_left}`}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user