2019-12-16 05:24:37 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
no-return-assign,
|
|
|
|
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
|
|
|
|
*/
|
2019-12-16 05:42:31 -05:00
|
|
|
const settings = require('settings-sharelatex')
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
module.exports = {
|
2019-12-16 05:42:31 -05:00
|
|
|
getConvertedFolderKey(key) {
|
|
|
|
return (key = `${key}-converted-cache/`)
|
|
|
|
},
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
addCachingToKey(key, opts) {
|
|
|
|
key = this.getConvertedFolderKey(key)
|
|
|
|
if (opts.format != null && opts.style == null) {
|
|
|
|
key = `${key}format-${opts.format}`
|
|
|
|
}
|
|
|
|
if (opts.style != null && opts.format == null) {
|
|
|
|
key = `${key}style-${opts.style}`
|
|
|
|
}
|
|
|
|
if (opts.style != null && opts.format != null) {
|
|
|
|
key = `${key}format-${opts.format}-style-${opts.style}`
|
|
|
|
}
|
|
|
|
return key
|
|
|
|
},
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
userFileKey(req, res, next) {
|
|
|
|
const { project_id, file_id } = req.params
|
|
|
|
req.key = `${project_id}/${file_id}`
|
|
|
|
req.bucket = settings.filestore.stores.user_files
|
|
|
|
return next()
|
|
|
|
},
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
publicFileKey(req, res, next) {
|
|
|
|
const { project_id, public_file_id } = req.params
|
|
|
|
if (settings.filestore.stores.public_files == null) {
|
|
|
|
return res.status(501).send('public files not available')
|
|
|
|
} else {
|
|
|
|
req.key = `${project_id}/${public_file_id}`
|
|
|
|
req.bucket = settings.filestore.stores.public_files
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
},
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
templateFileKey(req, res, next) {
|
|
|
|
const { template_id, format, version, sub_type } = req.params
|
|
|
|
req.key = `${template_id}/v/${version}/${format}`
|
|
|
|
if (sub_type != null) {
|
|
|
|
req.key = `${req.key}/${sub_type}`
|
|
|
|
}
|
|
|
|
req.bucket = settings.filestore.stores.template_files
|
|
|
|
req.version = version
|
|
|
|
const opts = req.query
|
|
|
|
return next()
|
|
|
|
},
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
publicProjectKey(req, res, next) {
|
|
|
|
const { project_id } = req.params
|
|
|
|
req.project_id = project_id
|
|
|
|
req.bucket = settings.filestore.stores.user_files
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
}
|