From 922caa76da8dd7f4f089458ec6ae5210432fd087 Mon Sep 17 00:00:00 2001 From: Larvey <39219859+LarveyOfficial@users.noreply.github.com> Date: Sat, 11 Jun 2022 18:59:45 -0400 Subject: [PATCH] More Info in Torrents Module Added - ETA - Torrent Size - Paused state color in progress bar --- .../modules/downloads/DownloadsModule.tsx | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/modules/downloads/DownloadsModule.tsx b/src/components/modules/downloads/DownloadsModule.tsx index 3a4a4a65b..476c3c405 100644 --- a/src/components/modules/downloads/DownloadsModule.tsx +++ b/src/components/modules/downloads/DownloadsModule.tsx @@ -53,6 +53,7 @@ export default function DownloadComponent() { // Send one request with each download service inside axios.post('/api/modules/downloads', { config }).then((response) => { setTorrents(response.data); + console.log(response.data); setIsLoading(false); }); }, 5000); @@ -85,8 +86,10 @@ export default function DownloadComponent() { const ths = ( Name + Size Download Upload + ETA Progress ); @@ -96,6 +99,30 @@ export default function DownloadComponent() { .map((torrent) => { const downloadSpeed = torrent.downloadSpeed / 1024 / 1024; const uploadSpeed = torrent.uploadSpeed / 1024 / 1024; + const size = torrent.totalSelected / (1024 * 1024); + // Convert Seconds to readable format. + function calculateETA(givenSeconds: number) { + if (givenSeconds > 86399) { // No + return ">1d" + } + const time = new Date(givenSeconds * 1000).toISOString(); + const hours = parseInt(time.substring(11,13)); + const minutes = parseInt(time.substring(14,16)); + const seconds = parseInt(time.substring(17,19)); + var str = ""; + // If tree go brr + if (hours > 0) { + str = `${hours}h `; + } + if (minutes > 0) { + str = `${str}${minutes}m ` + } + if (seconds > 0) { + str = `${str}${seconds}s`; + } + return str.trim(); + } + return ( @@ -111,17 +138,23 @@ export default function DownloadComponent() { + + {size > 0 ? (size > 999 ? `${(size / 1024).toFixed(1)} GB` : `${size.toFixed(1)} MB`) : '-' } + {downloadSpeed > 0 ? `${downloadSpeed.toFixed(1)} Mb/s` : '-'} {uploadSpeed > 0 ? `${uploadSpeed.toFixed(1)} Mb/s` : '-'} + + {torrent.eta <= 0 ? '∞' : calculateETA(torrent.eta)} + {(torrent.progress * 100).toFixed(1)}%