2021-07-12 12:47:19 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
module.exports = {
|
2019-12-19 10:36:48 -05:00
|
|
|
getConvertedFolderKey,
|
|
|
|
addCachingToKey,
|
|
|
|
userFileKeyMiddleware,
|
2020-03-14 10:56:29 -04:00
|
|
|
userProjectKeyMiddleware,
|
2020-01-07 10:05:51 -05:00
|
|
|
bucketFileKeyMiddleware,
|
2021-07-13 07:04:46 -04:00
|
|
|
templateFileKeyMiddleware,
|
2019-12-19 10:36:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getConvertedFolderKey(key) {
|
|
|
|
return `${key}-converted-cache/`
|
|
|
|
}
|
|
|
|
|
|
|
|
function addCachingToKey(key, opts) {
|
|
|
|
key = this.getConvertedFolderKey(key)
|
|
|
|
|
|
|
|
if (opts.format && !opts.style) {
|
|
|
|
key = `${key}format-${opts.format}`
|
|
|
|
}
|
|
|
|
if (opts.style && !opts.format) {
|
|
|
|
key = `${key}style-${opts.style}`
|
|
|
|
}
|
|
|
|
if (opts.style && opts.format) {
|
|
|
|
key = `${key}format-${opts.format}-style-${opts.style}`
|
|
|
|
}
|
|
|
|
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
|
|
|
|
function userFileKeyMiddleware(req, res, next) {
|
|
|
|
const { project_id: projectId, file_id: fileId } = req.params
|
|
|
|
req.key = `${projectId}/${fileId}`
|
|
|
|
req.bucket = settings.filestore.stores.user_files
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:56:29 -04:00
|
|
|
function userProjectKeyMiddleware(req, res, next) {
|
|
|
|
const { project_id: projectId } = req.params
|
2024-08-02 07:17:07 -04:00
|
|
|
req.project_id = projectId
|
2020-03-14 10:56:29 -04:00
|
|
|
req.key = `${projectId}/`
|
|
|
|
req.bucket = settings.filestore.stores.user_files
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
|
2020-01-07 10:05:51 -05:00
|
|
|
function bucketFileKeyMiddleware(req, res, next) {
|
|
|
|
req.bucket = req.params.bucket
|
|
|
|
req.key = req.params[0]
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
|
2019-12-19 10:36:48 -05:00
|
|
|
function templateFileKeyMiddleware(req, res, next) {
|
|
|
|
const {
|
|
|
|
template_id: templateId,
|
|
|
|
format,
|
|
|
|
version,
|
2021-07-13 07:04:46 -04:00
|
|
|
sub_type: subType,
|
2019-12-19 10:36:48 -05:00
|
|
|
} = req.params
|
|
|
|
|
|
|
|
req.key = `${templateId}/v/${version}/${format}`
|
|
|
|
|
|
|
|
if (subType) {
|
|
|
|
req.key = `${req.key}/${subType}`
|
|
|
|
}
|
|
|
|
|
|
|
|
req.bucket = settings.filestore.stores.template_files
|
|
|
|
req.version = version
|
|
|
|
|
|
|
|
next()
|
|
|
|
}
|