Merge pull request #3495 from overleaf/ae-prettier-2

Upgrade Prettier to v2

GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
Alf Eaton
2021-04-15 02:05:22 +00:00
committed by Copybot
parent 930d7ba028
commit 1ebc8a79cb
582 changed files with 20382 additions and 20374 deletions
@@ -27,7 +27,7 @@ const clsiCookiesEnabled =
(Settings.clsiCookie != null ? Settings.clsiCookie.key : undefined) != null &&
Settings.clsiCookie.key.length !== 0
module.exports = function(backendGroup) {
module.exports = function (backendGroup) {
return {
buildKey(project_id) {
if (backendGroup != null) {
@@ -39,7 +39,7 @@ module.exports = function(backendGroup) {
_getServerId(project_id, callback) {
if (callback == null) {
callback = function(err, serverId) {}
callback = function (err, serverId) {}
}
return rclient.get(this.buildKey(project_id), (err, serverId) => {
if (err != null) {
@@ -55,7 +55,7 @@ module.exports = function(backendGroup) {
_populateServerIdViaRequest(project_id, callback) {
if (callback == null) {
callback = function(err, serverId) {}
callback = function (err, serverId) {}
}
const url = `${Settings.apis.clsi.url}/project/${project_id}/status`
return request.post(url, (err, res, body) => {
@@ -65,7 +65,7 @@ module.exports = function(backendGroup) {
})
return callback(err)
}
return this.setServerId(project_id, res, function(err, serverId) {
return this.setServerId(project_id, res, function (err, serverId) {
if (err != null) {
logger.warn(
{ err, project_id },
@@ -88,7 +88,7 @@ module.exports = function(backendGroup) {
setServerId(project_id, response, callback) {
if (callback == null) {
callback = function(err, serverId) {}
callback = function (err, serverId) {}
}
if (!clsiCookiesEnabled) {
return callback()
@@ -112,7 +112,7 @@ module.exports = function(backendGroup) {
_setServerIdInRedis(rclient, project_id, serverId, callback) {
if (callback == null) {
callback = function(err) {}
callback = function (err) {}
}
rclient.setex(
this.buildKey(project_id),
@@ -124,7 +124,7 @@ module.exports = function(backendGroup) {
clearServerId(project_id, callback) {
if (callback == null) {
callback = function(err) {}
callback = function (err) {}
}
if (!clsiCookiesEnabled) {
return callback()
@@ -134,7 +134,7 @@ module.exports = function(backendGroup) {
getCookieJar(project_id, callback) {
if (callback == null) {
callback = function(err, jar) {}
callback = function (err, jar) {}
}
if (!clsiCookiesEnabled) {
return callback(null, request.jar())
@@ -26,7 +26,7 @@ module.exports = ClsiFormatChecker = {
}
}
return async.series(jobs, function(err, problems) {
return async.series(jobs, function (err, problems) {
if (err != null) {
return callback(err)
}
@@ -44,7 +44,7 @@ module.exports = ClsiFormatChecker = {
_checkForConflictingPaths(resources, callback) {
const paths = resources.map(resource => resource.path)
const conflicts = _.filter(paths, function(path) {
const conflicts = _.filter(paths, function (path) {
const matchingPaths = _.filter(
paths,
checkPath => checkPath.indexOf(path + '/') !== -1
@@ -63,7 +63,7 @@ module.exports = ClsiFormatChecker = {
let totalSize = 0
let sizedResources = resources.map(function(resource) {
let sizedResources = resources.map(function (resource) {
const result = { path: resource.path }
if (resource.content != null) {
result.size = resource.content.replace(/\n/g, '').length
@@ -79,9 +79,7 @@ module.exports = ClsiFormatChecker = {
if (!tooLarge) {
return callback()
} else {
sizedResources = _.sortBy(sizedResources, 'size')
.reverse()
.slice(0, 10)
sizedResources = _.sortBy(sizedResources, 'size').reverse().slice(0, 10)
return callback(null, { resources: sizedResources, totalSize })
}
}
@@ -34,50 +34,48 @@ const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
// unsetting it if it removes any documents from the doc updater.
const buildState = s =>
crypto
.createHash('sha1')
.update(s, 'utf8')
.digest('hex')
crypto.createHash('sha1').update(s, 'utf8').digest('hex')
module.exports = ClsiStateManager = {
computeHash(project, options, callback) {
if (callback == null) {
callback = function(err, hash) {}
callback = function (err, hash) {}
}
return ProjectEntityHandler.getAllEntitiesFromProject(project, function(
err,
docs,
files
) {
const fileList = Array.from(files || []).map(
f => `${f.file._id}:${f.file.rev}:${f.file.created}:${f.path}`
)
const docList = Array.from(docs || []).map(d => `${d.doc._id}:${d.path}`)
const sortedEntityList = [
...Array.from(docList),
...Array.from(fileList)
].sort()
// ignore the isAutoCompile options as it doesn't affect the
// output, but include all other options e.g. draft
const optionsList = (() => {
const result = []
const object = options || {}
for (let key in object) {
const value = object[key]
if (!['isAutoCompile'].includes(key)) {
result.push(`option ${key}:${value}`)
return ProjectEntityHandler.getAllEntitiesFromProject(
project,
function (err, docs, files) {
const fileList = Array.from(files || []).map(
f => `${f.file._id}:${f.file.rev}:${f.file.created}:${f.path}`
)
const docList = Array.from(docs || []).map(
d => `${d.doc._id}:${d.path}`
)
const sortedEntityList = [
...Array.from(docList),
...Array.from(fileList)
].sort()
// ignore the isAutoCompile options as it doesn't affect the
// output, but include all other options e.g. draft
const optionsList = (() => {
const result = []
const object = options || {}
for (let key in object) {
const value = object[key]
if (!['isAutoCompile'].includes(key)) {
result.push(`option ${key}:${value}`)
}
}
}
return result
})()
const sortedOptionsList = optionsList.sort()
const hash = buildState(
[
...Array.from(sortedEntityList),
...Array.from(sortedOptionsList)
].join('\n')
)
return callback(null, hash)
})
return result
})()
const sortedOptionsList = optionsList.sort()
const hash = buildState(
[
...Array.from(sortedEntityList),
...Array.from(sortedOptionsList)
].join('\n')
)
return callback(null, hash)
}
)
}
}
@@ -104,11 +104,11 @@ module.exports = CompileController = {
stopCompile(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
const project_id = req.params.Project_id
const user_id = AuthenticationController.getLoggedInUserId(req)
return CompileManager.stopCompile(project_id, user_id, function(error) {
return CompileManager.stopCompile(project_id, user_id, function (error) {
if (error != null) {
return next(error)
}
@@ -119,7 +119,7 @@ module.exports = CompileController = {
// Used for submissions through the public API
compileSubmission(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
res.setTimeout(COMPILE_TIMEOUT_MS)
const { submission_id } = req.params
@@ -150,7 +150,7 @@ module.exports = CompileController = {
submission_id,
req.body,
options,
function(error, status, outputFiles, clsiServerId, validationProblems) {
function (error, status, outputFiles, clsiServerId, validationProblems) {
if (error != null) {
return next(error)
}
@@ -189,13 +189,13 @@ module.exports = CompileController = {
downloadPdf(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
Metrics.inc('pdf-downloads')
const project_id = req.params.Project_id
const isPdfjsPartialDownload =
req.query != null ? req.query.pdfng : undefined
const rateLimit = function(callback) {
const rateLimit = function (callback) {
if (isPdfjsPartialDownload) {
return callback(null, true)
} else {
@@ -209,51 +209,52 @@ module.exports = CompileController = {
}
}
return ProjectGetter.getProject(project_id, { name: 1 }, function(
err,
project
) {
res.contentType('application/pdf')
const filename = `${CompileController._getSafeProjectName(project)}.pdf`
return ProjectGetter.getProject(
project_id,
{ name: 1 },
function (err, project) {
res.contentType('application/pdf')
const filename = `${CompileController._getSafeProjectName(project)}.pdf`
if (req.query.popupDownload) {
res.setContentDisposition('attachment', { filename })
} else {
res.setContentDisposition('', { filename })
}
return rateLimit(function(err, canContinue) {
if (err != null) {
logger.err({ err }, 'error checking rate limit for pdf download')
return res.sendStatus(500)
} else if (!canContinue) {
logger.log(
{ project_id, ip: req.ip },
'rate limit hit downloading pdf'
)
return res.sendStatus(500)
if (req.query.popupDownload) {
res.setContentDisposition('attachment', { filename })
} else {
return CompileController._downloadAsUser(req, function(
error,
user_id
) {
const url = CompileController._getFileUrl(
project_id,
user_id,
req.params.build_id,
'output.pdf'
)
return CompileController.proxyToClsi(
project_id,
url,
req,
res,
next
)
})
res.setContentDisposition('', { filename })
}
})
})
return rateLimit(function (err, canContinue) {
if (err != null) {
logger.err({ err }, 'error checking rate limit for pdf download')
return res.sendStatus(500)
} else if (!canContinue) {
logger.log(
{ project_id, ip: req.ip },
'rate limit hit downloading pdf'
)
return res.sendStatus(500)
} else {
return CompileController._downloadAsUser(
req,
function (error, user_id) {
const url = CompileController._getFileUrl(
project_id,
user_id,
req.params.build_id,
'output.pdf'
)
return CompileController.proxyToClsi(
project_id,
url,
req,
res,
next
)
}
)
}
})
}
)
},
_getSafeProjectName(project) {
@@ -264,18 +265,21 @@ module.exports = CompileController = {
deleteAuxFiles(req, res, next) {
const project_id = req.params.Project_id
const { clsiserverid } = req.query
return CompileController._compileAsUser(req, function(error, user_id) {
return CompileController._compileAsUser(req, function (error, user_id) {
if (error != null) {
return next(error)
}
CompileManager.deleteAuxFiles(project_id, user_id, clsiserverid, function(
error
) {
if (error != null) {
return next(error)
CompileManager.deleteAuxFiles(
project_id,
user_id,
clsiserverid,
function (error) {
if (error != null) {
return next(error)
}
return res.sendStatus(200)
}
return res.sendStatus(200)
})
)
})
},
@@ -283,7 +287,7 @@ module.exports = CompileController = {
compileAndDownloadPdf(req, res, next) {
const { project_id } = req.params
// pass user_id as null, since templates are an "anonymous" compile
return CompileManager.compile(project_id, null, {}, function(err) {
return CompileManager.compile(project_id, null, {}, function (err) {
if (err != null) {
logger.err(
{ err, project_id },
@@ -298,10 +302,10 @@ module.exports = CompileController = {
getFileFromClsi(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
const project_id = req.params.Project_id
return CompileController._downloadAsUser(req, function(error, user_id) {
return CompileController._downloadAsUser(req, function (error, user_id) {
if (error != null) {
return next(error)
}
@@ -317,7 +321,7 @@ module.exports = CompileController = {
getFileFromClsiWithoutUser(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
const { submission_id } = req.params
const url = CompileController._getFileUrl(
@@ -367,7 +371,7 @@ module.exports = CompileController = {
proxySyncPdf(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
const project_id = req.params.Project_id
const { page, h, v } = req.query
@@ -381,7 +385,7 @@ module.exports = CompileController = {
return next(new Error('invalid v parameter'))
}
// whether this request is going to a per-user container
return CompileController._compileAsUser(req, function(error, user_id) {
return CompileController._compileAsUser(req, function (error, user_id) {
if (error != null) {
return next(error)
}
@@ -403,7 +407,7 @@ module.exports = CompileController = {
proxySyncCode(req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
const project_id = req.params.Project_id
const { file, line, column } = req.query
@@ -425,7 +429,7 @@ module.exports = CompileController = {
if (!(column != null ? column.match(/^\d+$/) : undefined)) {
return next(new Error('invalid column parameter'))
}
return CompileController._compileAsUser(req, function(error, user_id) {
return CompileController._compileAsUser(req, function (error, user_id) {
if (error != null) {
return next(error)
}
@@ -447,7 +451,7 @@ module.exports = CompileController = {
proxyToClsi(project_id, url, req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
if (req.query != null ? req.query.compileGroup : undefined) {
return CompileController.proxyToClsiWithLimits(
@@ -459,28 +463,28 @@ module.exports = CompileController = {
next
)
} else {
return CompileManager.getProjectCompileLimits(project_id, function(
error,
limits
) {
if (error != null) {
return next(error)
return CompileManager.getProjectCompileLimits(
project_id,
function (error, limits) {
if (error != null) {
return next(error)
}
return CompileController.proxyToClsiWithLimits(
project_id,
url,
limits,
req,
res,
next
)
}
return CompileController.proxyToClsiWithLimits(
project_id,
url,
limits,
req,
res,
next
)
})
)
}
},
proxyToClsiWithLimits(project_id, url, limits, req, res, next) {
if (next == null) {
next = function(error) {}
next = function (error) {}
}
_getPersistenceOptions(req, project_id, (err, persistenceOptions) => {
let qs
@@ -541,7 +545,7 @@ module.exports = CompileController = {
const project_id = req.params.Project_id
const file = req.query.file || false
const { clsiserverid } = req.query
return CompileController._compileAsUser(req, function(error, user_id) {
return CompileController._compileAsUser(req, function (error, user_id) {
if (error != null) {
return next(error)
}
@@ -550,7 +554,7 @@ module.exports = CompileController = {
user_id,
file,
clsiserverid,
function(error, body) {
function (error, body) {
if (error != null) {
return next(error)
}
@@ -30,10 +30,10 @@ module.exports = CompileManager = {
options = {}
}
if (_callback == null) {
_callback = function(error) {}
_callback = function (error) {}
}
const timer = new Metrics.Timer('editor.compile')
const callback = function(...args) {
const callback = function (...args) {
timer.done()
return _callback(...Array.from(args || []))
}
@@ -41,7 +41,7 @@ module.exports = CompileManager = {
return CompileManager._checkIfRecentlyCompiled(
project_id,
user_id,
function(error, recentlyCompiled) {
function (error, recentlyCompiled) {
if (error != null) {
return callback(error)
}
@@ -52,20 +52,20 @@ module.exports = CompileManager = {
return CompileManager._checkIfAutoCompileLimitHasBeenHit(
options.isAutoCompile,
'everyone',
function(err, canCompile) {
function (err, canCompile) {
if (!canCompile) {
return callback(null, 'autocompile-backoff', [])
}
return ProjectRootDocManager.ensureRootDocumentIsSet(
project_id,
function(error) {
function (error) {
if (error != null) {
return callback(error)
}
return CompileManager.getProjectCompileLimits(
project_id,
function(error, limits) {
function (error, limits) {
if (error != null) {
return callback(error)
}
@@ -77,7 +77,7 @@ module.exports = CompileManager = {
return CompileManager._checkCompileGroupAutoCompileLimit(
options.isAutoCompile,
limits.compileGroup,
function(err, canCompile) {
function (err, canCompile) {
if (!canCompile) {
return callback(null, 'autocompile-backoff', [])
}
@@ -89,7 +89,7 @@ module.exports = CompileManager = {
project_id,
compileAsUser,
options,
function(
function (
error,
status,
outputFiles,
@@ -123,100 +123,105 @@ module.exports = CompileManager = {
stopCompile(project_id, user_id, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
return CompileManager.getProjectCompileLimits(project_id, function(
error,
limits
) {
if (error != null) {
return callback(error)
return CompileManager.getProjectCompileLimits(
project_id,
function (error, limits) {
if (error != null) {
return callback(error)
}
return ClsiManager.stopCompile(project_id, user_id, limits, callback)
}
return ClsiManager.stopCompile(project_id, user_id, limits, callback)
})
)
},
deleteAuxFiles(project_id, user_id, clsiserverid, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
return CompileManager.getProjectCompileLimits(project_id, function(
error,
limits
) {
if (error != null) {
return callback(error)
return CompileManager.getProjectCompileLimits(
project_id,
function (error, limits) {
if (error != null) {
return callback(error)
}
ClsiManager.deleteAuxFiles(
project_id,
user_id,
limits,
clsiserverid,
callback
)
}
ClsiManager.deleteAuxFiles(
project_id,
user_id,
limits,
clsiserverid,
callback
)
})
)
},
getProjectCompileLimits(project_id, callback) {
if (callback == null) {
callback = function(error, limits) {}
callback = function (error, limits) {}
}
return ProjectGetter.getProject(project_id, { owner_ref: 1 }, function(
error,
project
) {
if (error != null) {
return callback(error)
}
return UserGetter.getUser(
project.owner_ref,
{ alphaProgram: 1, betaProgram: 1, features: 1 },
function(err, owner) {
if (error != null) {
return callback(error)
}
let ownerFeatures = (owner && owner.features) || {}
// put alpha users into their own compile group
if (owner && owner.alphaProgram) {
ownerFeatures.compileGroup = 'alpha'
}
return callback(null, {
timeout:
ownerFeatures.compileTimeout ||
Settings.defaultFeatures.compileTimeout,
compileGroup:
ownerFeatures.compileGroup ||
Settings.defaultFeatures.compileGroup
})
return ProjectGetter.getProject(
project_id,
{ owner_ref: 1 },
function (error, project) {
if (error != null) {
return callback(error)
}
)
})
return UserGetter.getUser(
project.owner_ref,
{ alphaProgram: 1, betaProgram: 1, features: 1 },
function (err, owner) {
if (error != null) {
return callback(error)
}
let ownerFeatures = (owner && owner.features) || {}
// put alpha users into their own compile group
if (owner && owner.alphaProgram) {
ownerFeatures.compileGroup = 'alpha'
}
return callback(null, {
timeout:
ownerFeatures.compileTimeout ||
Settings.defaultFeatures.compileTimeout,
compileGroup:
ownerFeatures.compileGroup ||
Settings.defaultFeatures.compileGroup
})
}
)
}
)
},
COMPILE_DELAY: 1, // seconds
_checkIfRecentlyCompiled(project_id, user_id, callback) {
if (callback == null) {
callback = function(error, recentlyCompiled) {}
callback = function (error, recentlyCompiled) {}
}
const key = `compile:${project_id}:${user_id}`
return rclient.set(key, true, 'EX', this.COMPILE_DELAY, 'NX', function(
error,
ok
) {
if (error != null) {
return callback(error)
return rclient.set(
key,
true,
'EX',
this.COMPILE_DELAY,
'NX',
function (error, ok) {
if (error != null) {
return callback(error)
}
if (ok === 'OK') {
return callback(null, false)
} else {
return callback(null, true)
}
}
if (ok === 'OK') {
return callback(null, false)
} else {
return callback(null, true)
}
})
)
},
_checkCompileGroupAutoCompileLimit(isAutoCompile, compileGroup, callback) {
if (callback == null) {
callback = function(err, canCompile) {}
callback = function (err, canCompile) {}
}
if (!isAutoCompile) {
return callback(null, true)
@@ -236,7 +241,7 @@ module.exports = CompileManager = {
_checkIfAutoCompileLimitHasBeenHit(isAutoCompile, compileGroup, callback) {
if (callback == null) {
callback = function(err, canCompile) {}
callback = function (err, canCompile) {}
}
if (!isAutoCompile) {
return callback(null, true)
@@ -248,7 +253,7 @@ module.exports = CompileManager = {
subjectName: compileGroup,
throttle: Settings.rateLimit.autoCompile[compileGroup] || 25
}
return rateLimiter.addCount(opts, function(err, canCompile) {
return rateLimiter.addCount(opts, function (err, canCompile) {
if (err != null) {
canCompile = false
}
@@ -261,23 +266,23 @@ module.exports = CompileManager = {
wordCount(project_id, user_id, file, clsiserverid, callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
return CompileManager.getProjectCompileLimits(project_id, function(
error,
limits
) {
if (error != null) {
return callback(error)
return CompileManager.getProjectCompileLimits(
project_id,
function (error, limits) {
if (error != null) {
return callback(error)
}
ClsiManager.wordCount(
project_id,
user_id,
file,
limits,
clsiserverid,
callback
)
}
ClsiManager.wordCount(
project_id,
user_id,
file,
limits,
clsiserverid,
callback
)
})
)
}
}