diff --git a/files/[Andreas_M._Antonopoulos]_Mastering_Bitcoin_Progr(b-ok.org).pdf b/files/[Andreas_M._Antonopoulos]_Mastering_Bitcoin_Progr(b-ok.org).pdf new file mode 100644 index 0000000..eee69fc Binary files /dev/null and b/files/[Andreas_M._Antonopoulos]_Mastering_Bitcoin_Progr(b-ok.org).pdf differ diff --git a/package-lock.json b/package-lock.json index dbbfe3e..48d631e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1021,6 +1021,11 @@ "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": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", diff --git a/package.json b/package.json index 32feb19..1ede88e 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "body-parser": "^1.18.3", "bootstrap": "^4.1.3", "browserify": "^16.2.2", + "circular-json": "^0.5.5", "cookie-parser": "^1.4.3", "drag-drop": "^4.2.0", "ejs": "^2.6.1", diff --git a/routes.js b/routes.js index 0007df9..c6e0ab2 100644 --- a/routes.js +++ b/routes.js @@ -11,6 +11,8 @@ const funcs = require('./public/js/funcs') var path = require('path') var fs = require('fs'); +//const JSON = require('circular-json'); + router.get('/', (req, res)=>{ res.render('index.ejs', { data: {}, @@ -71,20 +73,19 @@ router.post('/download-magnetic-uri', (req, res)=>{ var length = files.length // Stream each file to the disk files.forEach(function (file) { - //console.log(file); - - let fullpath = path.resolve(file.path) - + //console.log(file._torrent.path); + var source = file.createReadStream() var destination = fs.createWriteStream(`files/${file.name}`) - source.on('end', function () { - console.log('file:\t\t', file.name) - //console.log(destination); - //res.json({file:file.name, location:fullpath}) - res.json({file:file.name, location:fullpath}) - // close after all files are saved - if (!--length) process.exit() + let fullpath = path.resolve(`files/${file.name}`) + + source.on('end', function () { + console.log('file:\t\t', file.name) + + res.json({file:file.name, location:fullpath}) + // close after all files are saved + if (!--length) process.exit() }).pipe(destination) }) diff --git a/views/magnetic.ejs b/views/magnetic.ejs index 3ef53ae..223c4df 100644 --- a/views/magnetic.ejs +++ b/views/magnetic.ejs @@ -33,18 +33,37 @@ 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.href = `/files/${response.file}` - // a.textContent = 'Download ' + response.file - // document.getElementById("dwld").appendChild(a) - console.log('ok'); - window.open(response.location); - } + + // 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 = `[Download .torrent]`; }, error: function(e) {