2018-07-04 06:18:55 -04:00
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
logger = require("logger-sharelatex")
|
|
|
|
FileHandler = require("./FileHandler")
|
|
|
|
metrics = require("metrics-sharelatex")
|
|
|
|
Errors = require('./Errors')
|
|
|
|
|
|
|
|
module.exports = BucketController =
|
|
|
|
|
|
|
|
getFile: (req, res)->
|
2018-07-04 07:11:09 -04:00
|
|
|
{bucket} = req.params
|
|
|
|
key = req.params[0]
|
2018-07-04 06:18:55 -04:00
|
|
|
{format, style} = req.query
|
2018-07-04 11:39:41 -04:00
|
|
|
credentials = settings.filestore.s3[bucket]
|
2018-07-04 06:18:55 -04:00
|
|
|
options = {
|
|
|
|
key: key,
|
|
|
|
bucket: bucket,
|
|
|
|
credentials: credentials
|
|
|
|
}
|
2018-07-04 07:02:09 -04:00
|
|
|
metrics.inc "#{bucket}.getFile"
|
2018-07-04 06:18:55 -04:00
|
|
|
logger.log key:key, bucket:bucket, "receiving request to get file from bucket"
|
|
|
|
FileHandler.getFile bucket, key, options, (err, fileStream)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, key:key, bucket:bucket, format:format, style:style, "problem getting file from bucket"
|
|
|
|
if err instanceof Errors.NotFoundError
|
|
|
|
return res.send 404
|
|
|
|
else
|
|
|
|
return res.send 500
|
|
|
|
else
|
|
|
|
logger.log key:key, bucket:bucket, format:format, style:style, "sending bucket file to response"
|
|
|
|
fileStream.pipe res
|