Allow dirs to downloaded as tarballs

This commit is contained in:
Girish Ramakrishnan
2017-08-20 18:44:26 -07:00
parent 3c31c96ad4
commit 7cb451c157
2 changed files with 22 additions and 14 deletions
+8 -7
View File
@@ -557,17 +557,18 @@ function downloadFile(req, res, next) {
if (typeof req.query.file !== 'string' || !req.query.file) return next(new HttpError(400, 'file query argument must be provided'));
apps.downloadFile(req.params.id, req.query.file, function (error, result, info) {
apps.downloadFile(req.params.id, req.query.file, function (error, stream, info) {
if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, error.message));
if (error) return next(new HttpError(500, error));
// TODO get real content type and size
res.writeHead(200, {
var headers = {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename="' + info.filename + '"',
'Content-Length': info.size
});
'Content-Disposition': 'attachment; filename="' + info.filename + '"'
};
if (info.size) headers['Content-Length'] = info.size;
result.pipe(res);
res.writeHead(200, headers);
stream.pipe(res);
});
}