tstor/torrent/assets/js/routes.js
Antonio Navarro Perez ecd524ed3c First functional web interface version.
- Simplify by now all html and javascript.
- Added a simple interface using go templates and plain javascript.
- Improved REST interface for the use case.
- Changed some properties into the config file to make it suitable for
future use cases.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2020-05-18 19:42:23 +02:00

32 lines
No EOL
1.1 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;
document.getElementById("up-down-speed-text-" + torrentStat.hash).innerText =
Humanize.bytes(download, 1024) + "/s down, " + Humanize.bytes(upload, 1024) + "/s up";
});
});
})
.catch(function (error) {
console.log('Error getting status info: ' + error.message);
});
}