2019-05-29 05:21:06 -04:00
|
|
|
const { Project } = require('../../models/Project')
|
|
|
|
const settings = require('settings-sharelatex')
|
2019-10-23 08:24:01 -04:00
|
|
|
const { promisifyAll } = require('../../util/promises')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
|
|
|
|
|
2019-10-23 08:24:01 -04:00
|
|
|
const ProjectOptionsHandler = {
|
2019-08-08 08:04:33 -04:00
|
|
|
setCompiler(projectId, compiler, callback) {
|
|
|
|
if (!compiler) {
|
|
|
|
return callback()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
compiler = compiler.toLowerCase()
|
2019-08-08 08:04:33 -04:00
|
|
|
if (!safeCompilers.includes(compiler)) {
|
|
|
|
return callback(new Error(`invalid compiler: ${compiler}`))
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-08 08:04:33 -04:00
|
|
|
const conditions = { _id: projectId }
|
2019-05-29 05:21:06 -04:00
|
|
|
const update = { compiler }
|
2020-10-12 07:40:01 -04:00
|
|
|
Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2019-08-08 08:04:33 -04:00
|
|
|
setImageName(projectId, imageName, callback) {
|
|
|
|
if (!imageName || !Array.isArray(settings.allowedImageNames)) {
|
|
|
|
return callback()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
imageName = imageName.toLowerCase()
|
2019-08-08 08:04:33 -04:00
|
|
|
const isAllowed = settings.allowedImageNames.find(
|
|
|
|
allowed => imageName === allowed.imageName
|
|
|
|
)
|
|
|
|
if (!isAllowed) {
|
|
|
|
return callback(new Error(`invalid imageName: ${imageName}`))
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-08 08:04:33 -04:00
|
|
|
const conditions = { _id: projectId }
|
2019-05-29 05:21:06 -04:00
|
|
|
const update = { imageName: settings.imageRoot + '/' + imageName }
|
2020-10-12 07:40:01 -04:00
|
|
|
Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2019-08-08 08:04:33 -04:00
|
|
|
setSpellCheckLanguage(projectId, languageCode, callback) {
|
|
|
|
if (!Array.isArray(settings.languages)) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return callback()
|
|
|
|
}
|
2019-08-08 08:04:33 -04:00
|
|
|
const language = settings.languages.find(
|
|
|
|
language => language.code === languageCode
|
|
|
|
)
|
|
|
|
if (languageCode && !language) {
|
|
|
|
return callback(new Error(`invalid languageCode: ${languageCode}`))
|
|
|
|
}
|
|
|
|
const conditions = { _id: projectId }
|
|
|
|
const update = { spellCheckLanguage: languageCode }
|
2020-10-12 07:40:01 -04:00
|
|
|
Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2019-08-08 08:04:33 -04:00
|
|
|
setBrandVariationId(projectId, brandVariationId, callback) {
|
|
|
|
if (!brandVariationId) {
|
2019-05-29 05:21:06 -04:00
|
|
|
return callback()
|
|
|
|
}
|
2019-08-08 08:04:33 -04:00
|
|
|
const conditions = { _id: projectId }
|
2019-05-29 05:21:06 -04:00
|
|
|
const update = { brandVariationId }
|
2020-10-12 07:40:01 -04:00
|
|
|
Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
|
|
|
|
2019-08-08 08:04:33 -04:00
|
|
|
unsetBrandVariationId(projectId, callback) {
|
|
|
|
const conditions = { _id: projectId }
|
2019-05-29 05:21:06 -04:00
|
|
|
const update = { $unset: { brandVariationId: 1 } }
|
2020-10-12 07:40:01 -04:00
|
|
|
Project.updateOne(conditions, update, {}, callback)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
2019-10-23 08:24:01 -04:00
|
|
|
|
|
|
|
ProjectOptionsHandler.promises = promisifyAll(ProjectOptionsHandler)
|
|
|
|
module.exports = ProjectOptionsHandler
|