Created
October 20, 2016 20:34
-
-
Save xantiagoma/3296ce347882a794cecb4454d289ac37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get("/", auth.authenticate(), middle.getroles, middle.roles(["user"]), function (req, res){ | |
if(req.query.path){ | |
res.sendFile("/mnt/vol0/storage"+req.query.path, {}, function (err) { //I know this is dangerous | |
if (err) { | |
console.log(err); | |
res.status(500).json(err); | |
} | |
else { | |
console.log('Sent:', req.query.path); | |
} | |
}) | |
}else{ | |
res.sendStatus(404); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
download: function(file){ | |
console.log("Downloading...", file.file); | |
this.$http.get("/api/ftp", { | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `JWT ${this.$router.app.token}` | |
}, | |
params: { | |
path: file.full | |
} | |
}) | |
.then((data) => { | |
console.log(data); | |
window.debug = data; | |
let bfile = new Blob([data.data], {type: data.headers["Content-Type"]}); | |
window.saveAs(bfile, file.file); | |
}) | |
.catch((err)=>{console.error(err);}); | |
} | |
//Vue-resource https://github.com/vuejs/vue-resource/blob/master/docs/http.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
window.saveAs: https://github.com/eligrey/FileSaver.js/ from CDN