Add and remove torrents from web interface (#84)
This commit is contained in:
parent
02842b1917
commit
2f18213660
49 changed files with 996 additions and 1170 deletions
assets/js
|
@ -77,7 +77,6 @@ Handlebars.registerHelper("torrent_info", function (peers, seeders, pieceSize) {
|
|||
return div.outerHTML;
|
||||
});
|
||||
|
||||
|
||||
Distribyted.routes = {
|
||||
_template: null,
|
||||
|
||||
|
@ -114,45 +113,6 @@ Distribyted.routes = {
|
|||
Distribyted.message.error('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.pieceSize;
|
||||
|
||||
// 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)
|
||||
|
||||
// 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;
|
||||
// });
|
||||
// });
|
||||
return routes;
|
||||
})
|
||||
.catch(function (error) {
|
||||
|
@ -160,6 +120,26 @@ Distribyted.routes = {
|
|||
});
|
||||
},
|
||||
|
||||
deleteTorrent: function (route, torrentHash) {
|
||||
var url = '/api/routes/' + route + '/torrent/' + torrentHash
|
||||
|
||||
return fetch(url, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
.then(function (response) {
|
||||
if (response.ok) {
|
||||
Distribyted.message.info('Torrent deleted.')
|
||||
} else {
|
||||
response.json().then(json => {
|
||||
Distribyted.message.error('Error deletting torrent. Response: ' + json.error)
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
Distribyted.message.error('Error deletting torrent: ' + error.message)
|
||||
});
|
||||
},
|
||||
|
||||
loadView: function () {
|
||||
this._getTemplate()
|
||||
.then(t =>
|
||||
|
@ -168,4 +148,34 @@ Distribyted.routes = {
|
|||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$("#new-magnet").submit(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
let route = $("#route-string :selected").val()
|
||||
let magnet = $("#magnet-url").val()
|
||||
|
||||
let url = '/api/routes/' + route + '/torrent'
|
||||
let body = JSON.stringify({ magnet: magnet })
|
||||
|
||||
console.log("LOG", url, body)
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
body: body
|
||||
})
|
||||
.then(function (response) {
|
||||
if (response.ok) {
|
||||
Distribyted.message.info('New magnet added.')
|
||||
} else {
|
||||
response.json().then(json => {
|
||||
Distribyted.message.error('Error adding new magnet. Response: ' + json.error)
|
||||
}).catch(function (error) {
|
||||
Distribyted.message.error('Error adding new magnet: ' + response.status)
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
Distribyted.message.error('Error deletting torrent: ' + error.message)
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue