Change color depending of torrent seeders and piece size.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-06-15 11:14:28 +02:00
parent b8392c4c50
commit b59def4718
2 changed files with 25 additions and 2 deletions

View file

@ -5,6 +5,8 @@ setInterval(function () {
fetchData(); fetchData();
}, 2000) }, 2000)
const MB = 1048576;
function fetchData() { function fetchData() {
fetch('/api/routes') fetch('/api/routes')
.then(function (response) { .then(function (response) {
@ -22,7 +24,7 @@ function fetchData() {
var upload = torrentStat.uploadedBytes / torrentStat.timePassed; var upload = torrentStat.uploadedBytes / torrentStat.timePassed;
var seeders = torrentStat.seeders; var seeders = torrentStat.seeders;
var peers = torrentStat.peers; var peers = torrentStat.peers;
var pieceSize = torrentStat.pieceSice; var pieceSize = torrentStat.pieceSize;
document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText = document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText =
Humanize.ibytes(download, 1024) + "/s down, " + Humanize.ibytes(upload, 1024) + "/s up"; Humanize.ibytes(download, 1024) + "/s down, " + Humanize.ibytes(upload, 1024) + "/s up";
@ -30,6 +32,27 @@ function fetchData() {
peers + " peers, " + seeders + " seeders." peers + " peers, " + seeders + " seeders."
document.getElementById("piece-size-" + torrentStat.hash).innerText = "Piece size: " + Humanize.bytes(pieceSize, 1024) 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;
}); });
}); });
}) })

View file

@ -35,7 +35,7 @@ type TorrentStats struct {
TimePassed float64 `json:"timePassed"` TimePassed float64 `json:"timePassed"`
PieceChunks []*PieceChunk `json:"pieceChunks"` PieceChunks []*PieceChunk `json:"pieceChunks"`
TotalPieces int `json:"totalPieces"` TotalPieces int `json:"totalPieces"`
PieceSize int64 `json:"pieceSice"` PieceSize int64 `json:"pieceSize"`
} }
type GlobalTorrentStats struct { type GlobalTorrentStats struct {