webtor/views/magnetic.ejs
2018-08-25 16:40:28 +05:30

60 lines
1.6 KiB
Plaintext

<%include partials/header.ejs %>
<div class="container">
<label for="mag_text">Provide a magnetic URL below:</label>
<textarea class="form-control" id="mag_text" rows="3"></textarea>
<p><button id="dwn-seed" class="btn btn-primary">View</button></p>
<p id="dwld"></p>
<div class="pd-10">
<div id="mag-res"></div>
</div>
</div>
<%include partials/footer.ejs %>
<script>
$(document).on('click', '#dwn-seed', function() {
// var client = new WebTorrent()
// client.on('error', function (err) {
// console.error('ERROR: ' + err.message)
// })
var torrentId = document.getElementById('mag_text').value;
if (torrentId.trim() == '') {
alert("Please specify a magnetic url.");
return;
}
var job = 'download-magnetic-uri';
$.ajax({
url: '/download-magnetic-uri',
type: 'post',
data: {job:job, torrentId:torrentId},
success: function(response) {
console.log(response);
if (typeof response.file != undefined) {
let file = response.file;
var a = document.createElement('a')
a.download = `files/${response.file}`
a.href = response.location
a.textContent = 'Download ' + response.file
document.getElementById("dwld").appendChild(a)
}
},
error: function(e) {
console.error(e);
}
});
});
</script>