2014-02-14 16:39:05 +00:00
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
|
|
|
|
getConvertedFolderKey: (key)->
|
|
|
|
key = "#{key}-converted-cache/"
|
|
|
|
|
|
|
|
addCachingToKey: (key, opts)->
|
|
|
|
key = @getConvertedFolderKey(key)
|
|
|
|
if opts.format? and !opts.style?
|
|
|
|
key = "#{key}format-#{opts.format}"
|
|
|
|
if opts.style? and !opts.format?
|
|
|
|
key = "#{key}style-#{opts.style}"
|
|
|
|
if opts.style? and opts.format?
|
|
|
|
key = "#{key}format-#{opts.format}-style-#{opts.style}"
|
|
|
|
return key
|
|
|
|
|
|
|
|
|
|
|
|
userFileKey: (req, res, next)->
|
|
|
|
{project_id, file_id} = req.params
|
|
|
|
req.key = "#{project_id}/#{file_id}"
|
2014-03-04 15:01:13 +00:00
|
|
|
req.bucket = settings.filestore.stores.user_files
|
2014-02-14 16:39:05 +00:00
|
|
|
next()
|
|
|
|
|
2015-05-08 14:15:48 +00:00
|
|
|
publicFileKey: (req, res, next)->
|
|
|
|
{project_id, public_file_id} = req.params
|
|
|
|
if not settings.filestore.stores.public_files?
|
|
|
|
res.status(501).send("public files not available")
|
|
|
|
else
|
|
|
|
req.key = "#{project_id}/#{public_file_id}"
|
|
|
|
req.bucket = settings.filestore.stores.public_files
|
|
|
|
next()
|
|
|
|
|
2014-02-14 16:39:05 +00:00
|
|
|
templateFileKey: (req, res, next)->
|
2015-04-09 16:14:47 +00:00
|
|
|
{template_id, format, version, sub_type} = req.params
|
2015-04-13 11:01:49 +00:00
|
|
|
req.key = "#{template_id}/v/#{version}/#{format}"
|
|
|
|
if sub_type?
|
|
|
|
req.key = "#{req.key}/#{sub_type}"
|
2014-03-04 15:01:13 +00:00
|
|
|
req.bucket = settings.filestore.stores.template_files
|
2014-02-14 16:39:05 +00:00
|
|
|
req.version = version
|
|
|
|
opts = req.query
|
|
|
|
next()
|
|
|
|
|
2014-03-04 15:01:13 +00:00
|
|
|
|