mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-20 06:12:22 +01:00
test(download): restore download code
This commit is contained in:
@@ -71,35 +71,18 @@ exports.download = function (req, res) {
|
||||
fs.exists(filePath, function (exists) {
|
||||
if (exists) {
|
||||
var stat = fs.statSync(filePath);
|
||||
//
|
||||
//try {
|
||||
// res.set('Content-Type', 'application/octet-stream');
|
||||
// res.set('Content-Disposition', 'attachment; filename=' + encodeURI(req.params.filename));
|
||||
// res.set('Content-Length', stat.size);
|
||||
//
|
||||
// fs.createReadStream(filePath).pipe(res);
|
||||
//} catch (err) {
|
||||
// res.status(422).send({
|
||||
// message: 'DOWNLOAD_FAILED'
|
||||
// });
|
||||
//}
|
||||
|
||||
var options = {
|
||||
root: path.join(__dirname, '../../../../' + backupConfig.dir),
|
||||
dotfiles: 'deny',
|
||||
headers: {
|
||||
'x-timestamp': Date.now(),
|
||||
'x-sent': true,
|
||||
'Content-Disposition': 'attachment; filename=' + encodeURI(req.params.filename)
|
||||
}
|
||||
};
|
||||
try {
|
||||
res.set('Content-Type', 'application/octet-stream');
|
||||
res.set('Content-Disposition', 'attachment; filename=' + encodeURI(req.params.filename));
|
||||
res.set('Content-Length', stat.size);
|
||||
|
||||
res.sendFile(req.params.filename, options, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(err.status).end();
|
||||
}
|
||||
});
|
||||
fs.createReadStream(filePath).pipe(res);
|
||||
} catch (err) {
|
||||
res.status(422).send({
|
||||
message: 'DOWNLOAD_FAILED'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.status(422).send({
|
||||
message: 'FILE_DOES_NOT_EXISTS'
|
||||
|
||||
Reference in New Issue
Block a user