downloading files in download-magnetic-uri
This commit is contained in:
parent
65143ac553
commit
47c3bc61f0
Binary file not shown.
5
package-lock.json
generated
5
package-lock.json
generated
@ -1021,6 +1021,11 @@
|
|||||||
"safe-buffer": "^5.0.1"
|
"safe-buffer": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"circular-json": {
|
||||||
|
"version": "0.5.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.5.tgz",
|
||||||
|
"integrity": "sha512-13YaR6kiz0kBNmIVM87Io8Hp7bWOo4r61vkEANy8iH9R9bc6avud/1FT0SBpqR1RpIQADOh/Q+yHZDA1iL6ysA=="
|
||||||
|
},
|
||||||
"class-utils": {
|
"class-utils": {
|
||||||
"version": "0.3.6",
|
"version": "0.3.6",
|
||||||
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"bootstrap": "^4.1.3",
|
"bootstrap": "^4.1.3",
|
||||||
"browserify": "^16.2.2",
|
"browserify": "^16.2.2",
|
||||||
|
"circular-json": "^0.5.5",
|
||||||
"cookie-parser": "^1.4.3",
|
"cookie-parser": "^1.4.3",
|
||||||
"drag-drop": "^4.2.0",
|
"drag-drop": "^4.2.0",
|
||||||
"ejs": "^2.6.1",
|
"ejs": "^2.6.1",
|
||||||
|
|||||||
23
routes.js
23
routes.js
@ -11,6 +11,8 @@ const funcs = require('./public/js/funcs')
|
|||||||
var path = require('path')
|
var path = require('path')
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
|
//const JSON = require('circular-json');
|
||||||
|
|
||||||
router.get('/', (req, res)=>{
|
router.get('/', (req, res)=>{
|
||||||
res.render('index.ejs', {
|
res.render('index.ejs', {
|
||||||
data: {},
|
data: {},
|
||||||
@ -71,20 +73,19 @@ router.post('/download-magnetic-uri', (req, res)=>{
|
|||||||
var length = files.length
|
var length = files.length
|
||||||
// Stream each file to the disk
|
// Stream each file to the disk
|
||||||
files.forEach(function (file) {
|
files.forEach(function (file) {
|
||||||
//console.log(file);
|
//console.log(file._torrent.path);
|
||||||
|
|
||||||
let fullpath = path.resolve(file.path)
|
|
||||||
|
|
||||||
var source = file.createReadStream()
|
var source = file.createReadStream()
|
||||||
var destination = fs.createWriteStream(`files/${file.name}`)
|
var destination = fs.createWriteStream(`files/${file.name}`)
|
||||||
source.on('end', function () {
|
|
||||||
console.log('file:\t\t', file.name)
|
|
||||||
|
|
||||||
//console.log(destination);
|
let fullpath = path.resolve(`files/${file.name}`)
|
||||||
//res.json({file:file.name, location:fullpath})
|
|
||||||
res.json({file:file.name, location:fullpath})
|
source.on('end', function () {
|
||||||
// close after all files are saved
|
console.log('file:\t\t', file.name)
|
||||||
if (!--length) process.exit()
|
|
||||||
|
res.json({file:file.name, location:fullpath})
|
||||||
|
// close after all files are saved
|
||||||
|
if (!--length) process.exit()
|
||||||
}).pipe(destination)
|
}).pipe(destination)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -33,18 +33,37 @@
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
data: {job:job, torrentId:torrentId},
|
data: {job:job, torrentId:torrentId},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
console.log(response);
|
|
||||||
if (typeof response.file != undefined) {
|
// if (typeof response.file != undefined) {
|
||||||
let file = response.file;
|
// let file = response.file;
|
||||||
// var a = document.createElement('a')
|
// var a = document.createElement('a')
|
||||||
// a.download = `files/${response.file}`
|
// filename = response.file;
|
||||||
// //a.href = response.location
|
// uri = `file://${response.location}`;
|
||||||
// a.href = `/files/${response.file}`
|
|
||||||
// a.textContent = 'Download ' + response.file
|
// var link = document.createElement('a');
|
||||||
// document.getElementById("dwld").appendChild(a)
|
|
||||||
console.log('ok');
|
// if (typeof link.download === 'string') {
|
||||||
window.open(response.location);
|
// 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) {
|
error: function(e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user