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 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?
|
2018-07-06 04:12:59 -04:00
|
|
|
logger.err err:err, key:key, bucket:bucket, "problem getting file from bucket"
|
2018-07-04 06:18:55 -04:00
|
|
|
if err instanceof Errors.NotFoundError
|
|
|
|
return res.send 404
|
|
|
|
else
|
|
|
|
return res.send 500
|
|
|
|
else
|
2018-07-06 04:12:59 -04:00
|
|
|
logger.log key:key, bucket:bucket, "sending bucket file to response"
|
2018-07-04 06:18:55 -04:00
|
|
|
fileStream.pipe res
|