|
@@ -1,126 +1,74 @@
|
|
|
-/* eslint-disable
|
|
|
|
|
- camelcase,
|
|
|
|
|
- handle-callback-err,
|
|
|
|
|
- max-len,
|
|
|
|
|
- no-return-assign,
|
|
|
|
|
-*/
|
|
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
|
|
-/*
|
|
|
|
|
- * 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
|
|
|
|
|
- */
|
|
|
|
|
const { Project } = require('../../models/Project')
|
|
const { Project } = require('../../models/Project')
|
|
|
const logger = require('logger-sharelatex')
|
|
const logger = require('logger-sharelatex')
|
|
|
-const _ = require('underscore')
|
|
|
|
|
const settings = require('settings-sharelatex')
|
|
const settings = require('settings-sharelatex')
|
|
|
|
|
|
|
|
const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
|
|
const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
|
|
|
|
|
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
- setCompiler(project_id, compiler, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function() {}
|
|
|
|
|
|
|
+ setCompiler(projectId, compiler, callback) {
|
|
|
|
|
+ logger.log({ projectId, compiler }, 'setting the compiler')
|
|
|
|
|
+ if (!compiler) {
|
|
|
|
|
+ return callback()
|
|
|
}
|
|
}
|
|
|
- logger.log({ project_id, compiler }, 'setting the compiler')
|
|
|
|
|
compiler = compiler.toLowerCase()
|
|
compiler = compiler.toLowerCase()
|
|
|
- if (!_.contains(safeCompilers, compiler)) {
|
|
|
|
|
- return callback()
|
|
|
|
|
|
|
+ if (!safeCompilers.includes(compiler)) {
|
|
|
|
|
+ return callback(new Error(`invalid compiler: ${compiler}`))
|
|
|
}
|
|
}
|
|
|
- const conditions = { _id: project_id }
|
|
|
|
|
|
|
+ const conditions = { _id: projectId }
|
|
|
const update = { compiler }
|
|
const update = { compiler }
|
|
|
- return Project.update(conditions, update, {}, function(err) {
|
|
|
|
|
- if (callback != null) {
|
|
|
|
|
- return callback()
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Project.update(conditions, update, {}, callback)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- setImageName(project_id, imageName, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function() {}
|
|
|
|
|
|
|
+ setImageName(projectId, imageName, callback) {
|
|
|
|
|
+ logger.log({ projectId, imageName }, 'setting the imageName')
|
|
|
|
|
+ if (!imageName || !Array.isArray(settings.allowedImageNames)) {
|
|
|
|
|
+ return callback()
|
|
|
}
|
|
}
|
|
|
- logger.log({ project_id, imageName }, 'setting the imageName')
|
|
|
|
|
imageName = imageName.toLowerCase()
|
|
imageName = imageName.toLowerCase()
|
|
|
- if (
|
|
|
|
|
- !_.some(
|
|
|
|
|
- settings.allowedImageNames,
|
|
|
|
|
- allowed => imageName === allowed.imageName
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
- return callback()
|
|
|
|
|
|
|
+ const isAllowed = settings.allowedImageNames.find(
|
|
|
|
|
+ allowed => imageName === allowed.imageName
|
|
|
|
|
+ )
|
|
|
|
|
+ if (!isAllowed) {
|
|
|
|
|
+ return callback(new Error(`invalid imageName: ${imageName}`))
|
|
|
}
|
|
}
|
|
|
- const conditions = { _id: project_id }
|
|
|
|
|
|
|
+ const conditions = { _id: projectId }
|
|
|
const update = { imageName: settings.imageRoot + '/' + imageName }
|
|
const update = { imageName: settings.imageRoot + '/' + imageName }
|
|
|
- return Project.update(conditions, update, {}, function(err) {
|
|
|
|
|
- if (callback != null) {
|
|
|
|
|
- return callback()
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Project.update(conditions, update, {}, callback)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- setSpellCheckLanguage(project_id, languageCode, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function() {}
|
|
|
|
|
- }
|
|
|
|
|
- logger.log({ project_id, languageCode }, 'setting the spell check language')
|
|
|
|
|
- let languageIsSafe = false
|
|
|
|
|
- settings.languages.forEach(function(safeLang) {
|
|
|
|
|
- if (safeLang.code === languageCode) {
|
|
|
|
|
- return (languageIsSafe = true)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- if (languageCode === '') {
|
|
|
|
|
- languageIsSafe = true
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (languageIsSafe) {
|
|
|
|
|
- const conditions = { _id: project_id }
|
|
|
|
|
- const update = { spellCheckLanguage: languageCode }
|
|
|
|
|
- return Project.update(conditions, update, {}, err => callback())
|
|
|
|
|
- } else {
|
|
|
|
|
- logger.err({ project_id, languageCode }, 'tryed to set unsafe language')
|
|
|
|
|
|
|
+ setSpellCheckLanguage(projectId, languageCode, callback) {
|
|
|
|
|
+ logger.log({ projectId, languageCode }, 'setting the spell check language')
|
|
|
|
|
+ if (!Array.isArray(settings.languages)) {
|
|
|
return callback()
|
|
return callback()
|
|
|
}
|
|
}
|
|
|
|
|
+ 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 }
|
|
|
|
|
+ Project.update(conditions, update, {}, callback)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- setBrandVariationId(project_id, brandVariationId, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function() {}
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ setBrandVariationId(projectId, brandVariationId, callback) {
|
|
|
logger.log(
|
|
logger.log(
|
|
|
- { project_id, brandVariationId },
|
|
|
|
|
|
|
+ { projectId, brandVariationId },
|
|
|
'setting the brand variation id'
|
|
'setting the brand variation id'
|
|
|
)
|
|
)
|
|
|
- if (brandVariationId == null || brandVariationId === '') {
|
|
|
|
|
|
|
+ if (!brandVariationId) {
|
|
|
return callback()
|
|
return callback()
|
|
|
}
|
|
}
|
|
|
- const conditions = { _id: project_id }
|
|
|
|
|
|
|
+ const conditions = { _id: projectId }
|
|
|
const update = { brandVariationId }
|
|
const update = { brandVariationId }
|
|
|
- return Project.update(conditions, update, {}, function(err) {
|
|
|
|
|
- if (err != null) {
|
|
|
|
|
- logger.err({ err }, 'error setting brandVariationId')
|
|
|
|
|
- }
|
|
|
|
|
- return callback()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Project.update(conditions, update, {}, callback)
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- unsetBrandVariationId(project_id, callback) {
|
|
|
|
|
- if (callback == null) {
|
|
|
|
|
- callback = function() {}
|
|
|
|
|
- }
|
|
|
|
|
- logger.log({ project_id }, 'unsetting the brand variation id')
|
|
|
|
|
- const conditions = { _id: project_id }
|
|
|
|
|
|
|
+ unsetBrandVariationId(projectId, callback) {
|
|
|
|
|
+ logger.log({ projectId }, 'unsetting the brand variation id')
|
|
|
|
|
+ const conditions = { _id: projectId }
|
|
|
const update = { $unset: { brandVariationId: 1 } }
|
|
const update = { $unset: { brandVariationId: 1 } }
|
|
|
- return Project.update(conditions, update, {}, function(err) {
|
|
|
|
|
- if (err != null) {
|
|
|
|
|
- logger.warn({ err }, 'error unsetting brandVariationId')
|
|
|
|
|
- return callback(err)
|
|
|
|
|
- }
|
|
|
|
|
- return callback()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Project.update(conditions, update, {}, callback)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|