import useSWR from "swr"; import { useTranslation } from "next-i18next"; import Widget from "../widget"; import Block from "../block"; import { formatProxyUrl } from "utils/api-helpers"; export default function Transmission({ service }) { const { t } = useTranslation(); const config = service.widget; const { data: torrentData, error: torrentError } = useSWR(formatProxyUrl(config)); if (torrentError) { return ; } if (!torrentData) { return ( ); } const { torrents } = torrentData.arguments; let rateDl = 0; let rateUl = 0; let completed = 0; for (let i = 0; i < torrents.length; i += 1) { const torrent = torrents[i]; rateDl += torrent.rateDownload; rateUl += torrent.rateUpload; if (torrent.percentDone === 1) { completed += 1; } } const leech = torrents.length - completed; let unitsDl = "KB/s"; let unitsUl = "KB/s"; rateDl /= 1024; rateUl /= 1024; if (rateDl > 1024) { rateDl /= 1024; unitsDl = "MB/s"; } if (rateUl > 1024) { rateUl /= 1024; unitsUl = "MB/s"; } return ( ); }