webtor/views/magnetic.ejs
2018-08-25 23:11:41 +05:30

76 lines
2.5 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 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) {
// if (typeof response.file != undefined) {
// let file = response.file;
// var a = document.createElement('a')
// filename = response.file;
// uri = `file://${response.location}`;
// var link = document.createElement('a');
// if (typeof link.download === 'string') {
// console.log("a");
// link.href = uri;
// link.download = filename;
// //Firefox requires the link to be in the body
// document.getElementById("dwld").appendChild(link);
// //simulate click
// link.click();
// //remove the link when done
// document.getElementById("dwld").removeChild(link);
// console.log("aa")
// } else {
// console.log("b");
// window.open(uri);
// }
// }
document.getElementById('dwld').innerHTML = `<a href="file://${response.location}" target="_blank" download onclick="window.open('file://${response.location}')">[Download .torrent]</a>`;
},
error: function(e) {
console.error(e);
}
});
});
</script>