2019-12-16 05:24:37 -05:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2019-12-16 05:24:35 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
let BucketController;
|
|
|
|
const settings = require("settings-sharelatex");
|
|
|
|
const logger = require("logger-sharelatex");
|
|
|
|
const FileHandler = require("./FileHandler");
|
|
|
|
const metrics = require("metrics-sharelatex");
|
|
|
|
const Errors = require('./Errors');
|
2018-07-04 06:18:55 -04:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
module.exports = (BucketController = {
|
2018-07-04 06:18:55 -04:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
getFile(req, res){
|
|
|
|
const {bucket} = req.params;
|
|
|
|
const key = req.params[0];
|
|
|
|
const credentials = settings.filestore.s3BucketCreds != null ? settings.filestore.s3BucketCreds[bucket] : undefined;
|
|
|
|
const options = {
|
|
|
|
key,
|
|
|
|
bucket,
|
|
|
|
credentials
|
|
|
|
};
|
|
|
|
metrics.inc(`${bucket}.getFile`);
|
|
|
|
logger.log({key, bucket}, "receiving request to get file from bucket");
|
|
|
|
return FileHandler.getFile(bucket, key, options, function(err, fileStream){
|
|
|
|
if (err != null) {
|
|
|
|
logger.err({err, key, bucket}, "problem getting file from bucket");
|
|
|
|
if (err instanceof Errors.NotFoundError) {
|
|
|
|
return res.send(404);
|
|
|
|
} else {
|
|
|
|
return res.send(500);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger.log({key, bucket}, "sending bucket file to response");
|
|
|
|
return fileStream.pipe(res);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|