download link added in seeding page

This commit is contained in:
Abhishek Sinha 2018-08-25 20:39:19 +05:30
parent 52a750f657
commit 65143ac553
4 changed files with 42 additions and 16 deletions

View File

@ -21,8 +21,26 @@ let getFloData = (tx) => {
})
}
function saveAs(uri, filename) {
var link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
}
module.exports = {
getFloData
getFloData,
saveAs
}

View File

@ -71,7 +71,7 @@ router.post('/download-magnetic-uri', (req, res)=>{
var length = files.length
// Stream each file to the disk
files.forEach(function (file) {
console.log(file);
//console.log(file);
let fullpath = path.resolve(file.path)

View File

@ -18,12 +18,6 @@
<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;
@ -42,11 +36,14 @@
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)
// var a = document.createElement('a')
// a.download = `files/${response.file}`
// //a.href = response.location
// a.href = `/files/${response.file}`
// a.textContent = 'Download ' + response.file
// document.getElementById("dwld").appendChild(a)
console.log('ok');
window.open(response.location);
}
},

View File

@ -5,6 +5,7 @@
<div class="card drop-div" id="_drop"></div>
<div class="card">
<p id="dw-file"></p>
<div id="seed-result"></div>
</div>
@ -30,6 +31,8 @@ let seeding = () => {
client.seed(files, function (torrent) {
console.log(torrent);
console.log('Client is seeding ' + torrent.magnetURI)
let file_string = torrent.torrentFile.toString('hex');
let t = ``;
@ -60,9 +63,17 @@ let seeding = () => {
}
$("#seed-result").html(t);
document.getElementById('dw-file').innerHTML = '<a href="' + torrent.torrentFileBlobURL + '" target="_blank" download="file.torrent">[Download .torrent]</a>';
})
})
}
$(document).on('click', "#dwldspan", function() {
var loc = $(this).val();
console.log(loc);
window.location(loc)
})
</script>