mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-10 16:38:00 +00:00
return errors and clean up ProjectOptionsHandler
GitOrigin-RevId: 5be79a317419998216e9f207313c114888beb415
This commit is contained in:
parent
39cb437bb6
commit
cd57ff4e7f
1 changed files with 40 additions and 92 deletions
|
@ -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 logger = require('logger-sharelatex')
|
||||
const _ = require('underscore')
|
||||
const settings = require('settings-sharelatex')
|
||||
|
||||
const safeCompilers = ['xelatex', 'pdflatex', 'latex', 'lualatex']
|
||||
|
||||
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()
|
||||
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 }
|
||||
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()
|
||||
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 }
|
||||
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()
|
||||
}
|
||||
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(
|
||||
{ project_id, brandVariationId },
|
||||
{ projectId, brandVariationId },
|
||||
'setting the brand variation id'
|
||||
)
|
||||
if (brandVariationId == null || brandVariationId === '') {
|
||||
if (!brandVariationId) {
|
||||
return callback()
|
||||
}
|
||||
const conditions = { _id: project_id }
|
||||
const conditions = { _id: projectId }
|
||||
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 } }
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue