tstor/torrent/assets/js/routes.js
Antonio Navarro Perez 401a79379f Add piece size to web interface.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2020-06-09 12:06:12 +02:00

39 lines
No EOL
1.6 KiB
JavaScript

var fileChunks = new FileChunks();
fetchData();
setInterval(function () {
fetchData();
}, 2000)
function fetchData() {
fetch('/api/routes')
.then(function (response) {
if (response.ok) {
return response.json();
} else {
console.log('Error getting data from server. Response: ' + response.status);
}
}).then(function (routes) {
routes.forEach(route => {
route.torrentStats.forEach(torrentStat => {
fileChunks.update(torrentStat.pieceChunks, torrentStat.totalPieces, torrentStat.hash);
var download = torrentStat.downloadedBytes / torrentStat.timePassed;
var upload = torrentStat.uploadedBytes / torrentStat.timePassed;
var seeders = torrentStat.seeders;
var peers = torrentStat.peers;
var pieceSize = torrentStat.pieceSice;
document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText =
Humanize.ibytes(download, 1024) + "/s down, " + Humanize.ibytes(upload, 1024) + "/s up";
document.getElementById("peers-seeders-" + torrentStat.hash).innerText =
peers + " peers, " + seeders + " seeders."
document.getElementById("piece-size-" + torrentStat.hash).innerText = "Piece size: " + Humanize.bytes(pieceSize, 1024)
});
});
})
.catch(function (error) {
console.log('Error getting status info: ' + error.message);
});
}