From b59def4718266b4fa05f453046354c2ec092aefa Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Mon, 15 Jun 2020 11:14:28 +0200 Subject: [PATCH] Change color depending of torrent seeders and piece size. Signed-off-by: Antonio Navarro Perez --- assets/js/routes.js | 25 ++++++++++++++++++++++++- stats/torrent.go | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/assets/js/routes.js b/assets/js/routes.js index af3b3aa..741808b 100644 --- a/assets/js/routes.js +++ b/assets/js/routes.js @@ -5,6 +5,8 @@ setInterval(function () { fetchData(); }, 2000) +const MB = 1048576; + function fetchData() { fetch('/api/routes') .then(function (response) { @@ -22,7 +24,7 @@ function fetchData() { var upload = torrentStat.uploadedBytes / torrentStat.timePassed; var seeders = torrentStat.seeders; var peers = torrentStat.peers; - var pieceSize = torrentStat.pieceSice; + var pieceSize = torrentStat.pieceSize; document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText = Humanize.ibytes(download, 1024) + "/s down, " + Humanize.ibytes(upload, 1024) + "/s up"; @@ -30,6 +32,27 @@ function fetchData() { peers + " peers, " + seeders + " seeders." document.getElementById("piece-size-" + torrentStat.hash).innerText = "Piece size: " + Humanize.bytes(pieceSize, 1024) + var className = ""; + + if (seeders < 2) { + className = "text-danger"; + } else if (seeders >= 2 && seeders < 4) { + className = "text-warning"; + } else { + className = "text-success"; + } + + document.getElementById("peers-seeders-" + torrentStat.hash).className = className; + + if (pieceSize <= MB) { + className = "text-success"; + } else if (pieceSize > MB && pieceSize < (MB * 4)) { + className = "text-warning"; + } else { + className = "text-danger"; + } + + document.getElementById("piece-size-" + torrentStat.hash).className = className; }); }); }) diff --git a/stats/torrent.go b/stats/torrent.go index 17ec8de..65285b7 100644 --- a/stats/torrent.go +++ b/stats/torrent.go @@ -35,7 +35,7 @@ type TorrentStats struct { TimePassed float64 `json:"timePassed"` PieceChunks []*PieceChunk `json:"pieceChunks"` TotalPieces int `json:"totalPieces"` - PieceSize int64 `json:"pieceSice"` + PieceSize int64 `json:"pieceSize"` } type GlobalTorrentStats struct {