overleaf/services/filestore/app/coffee/BucketController.coffee

31 lines
985 B
CoffeeScript
Raw Normal View History

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]
{format, style} = req.query
2018-07-04 11:39:41 -04:00
credentials = settings.filestore.s3[bucket]
options = {
key: key,
bucket: bucket,
credentials: credentials
}
metrics.inc "#{bucket}.getFile"
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