mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Decaf cleanup: simplify null checks
This commit is contained in:
parent
80ea49c69c
commit
fc73bbe1a5
1 changed files with 23 additions and 76 deletions
|
@ -2,13 +2,6 @@
|
||||||
camelcase,
|
camelcase,
|
||||||
handle-callback-err,
|
handle-callback-err,
|
||||||
*/
|
*/
|
||||||
// TODO: This file was created by bulk-decaffeinate.
|
|
||||||
// Fix any style issues and re-enable lint.
|
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
let HttpController
|
let HttpController
|
||||||
const DocumentManager = require('./DocumentManager')
|
const DocumentManager = require('./DocumentManager')
|
||||||
const HistoryManager = require('./HistoryManager')
|
const HistoryManager = require('./HistoryManager')
|
||||||
|
@ -25,15 +18,12 @@ const TWO_MEGABYTES = 2 * 1024 * 1024
|
||||||
module.exports = HttpController = {
|
module.exports = HttpController = {
|
||||||
getDoc(req, res, next) {
|
getDoc(req, res, next) {
|
||||||
let fromVersion
|
let fromVersion
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { doc_id } = req.params
|
const { doc_id } = req.params
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
logger.log({ project_id, doc_id }, 'getting doc via http')
|
logger.log({ project_id, doc_id }, 'getting doc via http')
|
||||||
const timer = new Metrics.Timer('http.getDoc')
|
const timer = new Metrics.Timer('http.getDoc')
|
||||||
|
|
||||||
if ((req.query != null ? req.query.fromVersion : undefined) != null) {
|
if (req.query.fromVersion != null) {
|
||||||
fromVersion = parseInt(req.query.fromVersion, 10)
|
fromVersion = parseInt(req.query.fromVersion, 10)
|
||||||
} else {
|
} else {
|
||||||
fromVersion = -1
|
fromVersion = -1
|
||||||
|
@ -45,7 +35,7 @@ module.exports = HttpController = {
|
||||||
fromVersion,
|
fromVersion,
|
||||||
function (error, lines, version, ops, ranges, pathname) {
|
function (error, lines, version, ops, ranges, pathname) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id, doc_id }, 'got doc via http')
|
logger.log({ project_id, doc_id }, 'got doc via http')
|
||||||
|
@ -73,11 +63,8 @@ module.exports = HttpController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getProjectDocsAndFlushIfOld(req, res, next) {
|
getProjectDocsAndFlushIfOld(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const projectStateHash = req.query != null ? req.query.state : undefined
|
const projectStateHash = req.query.state
|
||||||
// exclude is string of existing docs "id:version,id:version,..."
|
// exclude is string of existing docs "id:version,id:version,..."
|
||||||
const excludeItems =
|
const excludeItems =
|
||||||
req.query.exclude != null ? req.query.exclude.split(',') : []
|
req.query.exclude != null ? req.query.exclude.split(',') : []
|
||||||
|
@ -100,7 +87,7 @@ module.exports = HttpController = {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error instanceof Errors.ProjectStateChangedError) {
|
if (error instanceof Errors.ProjectStateChangedError) {
|
||||||
res.sendStatus(409) // conflict
|
res.sendStatus(409) // conflict
|
||||||
} else if (error != null) {
|
} else if (error) {
|
||||||
next(error)
|
next(error)
|
||||||
} else {
|
} else {
|
||||||
logger.log(
|
logger.log(
|
||||||
|
@ -117,15 +104,12 @@ module.exports = HttpController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
clearProjectState(req, res, next) {
|
clearProjectState(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const timer = new Metrics.Timer('http.clearProjectState')
|
const timer = new Metrics.Timer('http.clearProjectState')
|
||||||
logger.log({ project_id }, 'clearing project state via http')
|
logger.log({ project_id }, 'clearing project state via http')
|
||||||
ProjectManager.clearProjectState(project_id, function (error) {
|
ProjectManager.clearProjectState(project_id, function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
next(error)
|
next(error)
|
||||||
} else {
|
} else {
|
||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
|
@ -134,9 +118,6 @@ module.exports = HttpController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
setDoc(req, res, next) {
|
setDoc(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { doc_id } = req.params
|
const { doc_id } = req.params
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const { lines, source, user_id, undoing } = req.body
|
const { lines, source, user_id, undoing } = req.body
|
||||||
|
@ -162,7 +143,7 @@ module.exports = HttpController = {
|
||||||
undoing,
|
undoing,
|
||||||
function (error) {
|
function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id, doc_id }, 'set doc via http')
|
logger.log({ project_id, doc_id }, 'set doc via http')
|
||||||
|
@ -172,9 +153,6 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
flushDocIfLoaded(req, res, next) {
|
flushDocIfLoaded(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { doc_id } = req.params
|
const { doc_id } = req.params
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
logger.log({ project_id, doc_id }, 'flushing doc via http')
|
logger.log({ project_id, doc_id }, 'flushing doc via http')
|
||||||
|
@ -183,7 +161,7 @@ module.exports = HttpController = {
|
||||||
error
|
error
|
||||||
) {
|
) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id, doc_id }, 'flushed doc via http')
|
logger.log({ project_id, doc_id }, 'flushed doc via http')
|
||||||
|
@ -192,9 +170,6 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
deleteDoc(req, res, next) {
|
deleteDoc(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { doc_id } = req.params
|
const { doc_id } = req.params
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const ignoreFlushErrors = req.query.ignore_flush_errors === 'true'
|
const ignoreFlushErrors = req.query.ignore_flush_errors === 'true'
|
||||||
|
@ -210,7 +185,7 @@ module.exports = HttpController = {
|
||||||
// failed and sometimes it is required
|
// failed and sometimes it is required
|
||||||
HistoryManager.flushProjectChangesAsync(project_id)
|
HistoryManager.flushProjectChangesAsync(project_id)
|
||||||
|
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id, doc_id }, 'deleted doc via http')
|
logger.log({ project_id, doc_id }, 'deleted doc via http')
|
||||||
|
@ -220,15 +195,12 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
flushProject(req, res, next) {
|
flushProject(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
logger.log({ project_id }, 'flushing project via http')
|
logger.log({ project_id }, 'flushing project via http')
|
||||||
const timer = new Metrics.Timer('http.flushProject')
|
const timer = new Metrics.Timer('http.flushProject')
|
||||||
ProjectManager.flushProjectWithLocks(project_id, function (error) {
|
ProjectManager.flushProjectWithLocks(project_id, function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id }, 'flushed project via http')
|
logger.log({ project_id }, 'flushed project via http')
|
||||||
|
@ -237,21 +209,18 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
deleteProject(req, res, next) {
|
deleteProject(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
logger.log({ project_id }, 'deleting project via http')
|
logger.log({ project_id }, 'deleting project via http')
|
||||||
const options = {}
|
const options = {}
|
||||||
if (req.query != null ? req.query.background : undefined) {
|
if (req.query.background) {
|
||||||
options.background = true
|
options.background = true
|
||||||
} // allow non-urgent flushes to be queued
|
} // allow non-urgent flushes to be queued
|
||||||
if (req.query != null ? req.query.shutdown : undefined) {
|
if (req.query.shutdown) {
|
||||||
options.skip_history_flush = true
|
options.skip_history_flush = true
|
||||||
} // don't flush history when realtime shuts down
|
} // don't flush history when realtime shuts down
|
||||||
if (req.query != null ? req.query.background : undefined) {
|
if (req.query.background) {
|
||||||
ProjectManager.queueFlushAndDeleteProject(project_id, function (error) {
|
ProjectManager.queueFlushAndDeleteProject(project_id, function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id }, 'queue delete of project via http')
|
logger.log({ project_id }, 'queue delete of project via http')
|
||||||
|
@ -264,7 +233,7 @@ module.exports = HttpController = {
|
||||||
options,
|
options,
|
||||||
function (error) {
|
function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id }, 'deleted project via http')
|
logger.log({ project_id }, 'deleted project via http')
|
||||||
|
@ -275,11 +244,7 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
deleteMultipleProjects(req, res, next) {
|
deleteMultipleProjects(req, res, next) {
|
||||||
if (next == null) {
|
const project_ids = req.body.project_ids || []
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const project_ids =
|
|
||||||
(req.body != null ? req.body.project_ids : undefined) || []
|
|
||||||
logger.log({ project_ids }, 'deleting multiple projects via http')
|
logger.log({ project_ids }, 'deleting multiple projects via http')
|
||||||
async.eachSeries(
|
async.eachSeries(
|
||||||
project_ids,
|
project_ids,
|
||||||
|
@ -288,7 +253,7 @@ module.exports = HttpController = {
|
||||||
ProjectManager.queueFlushAndDeleteProject(project_id, cb)
|
ProjectManager.queueFlushAndDeleteProject(project_id, cb)
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
res.sendStatus(204)
|
res.sendStatus(204)
|
||||||
|
@ -297,11 +262,8 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
acceptChanges(req, res, next) {
|
acceptChanges(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id, doc_id } = req.params
|
const { project_id, doc_id } = req.params
|
||||||
let change_ids = req.body != null ? req.body.change_ids : undefined
|
let change_ids = req.body.change_ids
|
||||||
if (change_ids == null) {
|
if (change_ids == null) {
|
||||||
change_ids = [req.params.change_id]
|
change_ids = [req.params.change_id]
|
||||||
}
|
}
|
||||||
|
@ -316,7 +278,7 @@ module.exports = HttpController = {
|
||||||
change_ids,
|
change_ids,
|
||||||
function (error) {
|
function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log(
|
logger.log(
|
||||||
|
@ -329,9 +291,6 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
deleteComment(req, res, next) {
|
deleteComment(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id, doc_id, comment_id } = req.params
|
const { project_id, doc_id, comment_id } = req.params
|
||||||
logger.log({ project_id, doc_id, comment_id }, 'deleting comment via http')
|
logger.log({ project_id, doc_id, comment_id }, 'deleting comment via http')
|
||||||
const timer = new Metrics.Timer('http.deleteComment')
|
const timer = new Metrics.Timer('http.deleteComment')
|
||||||
|
@ -341,7 +300,7 @@ module.exports = HttpController = {
|
||||||
comment_id,
|
comment_id,
|
||||||
function (error) {
|
function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log(
|
logger.log(
|
||||||
|
@ -354,9 +313,6 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
updateProject(req, res, next) {
|
updateProject(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const timer = new Metrics.Timer('http.updateProject')
|
const timer = new Metrics.Timer('http.updateProject')
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const {
|
const {
|
||||||
|
@ -380,7 +336,7 @@ module.exports = HttpController = {
|
||||||
version,
|
version,
|
||||||
function (error) {
|
function (error) {
|
||||||
timer.done()
|
timer.done()
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id }, 'updated project via http')
|
logger.log({ project_id }, 'updated project via http')
|
||||||
|
@ -390,9 +346,6 @@ module.exports = HttpController = {
|
||||||
}, // No Content
|
}, // No Content
|
||||||
|
|
||||||
resyncProjectHistory(req, res, next) {
|
resyncProjectHistory(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
const { project_id } = req.params
|
const { project_id } = req.params
|
||||||
const { projectHistoryId, docs, files } = req.body
|
const { projectHistoryId, docs, files } = req.body
|
||||||
|
|
||||||
|
@ -406,7 +359,7 @@ module.exports = HttpController = {
|
||||||
docs,
|
docs,
|
||||||
files,
|
files,
|
||||||
function (error) {
|
function (error) {
|
||||||
if (error != null) {
|
if (error) {
|
||||||
return next(error)
|
return next(error)
|
||||||
}
|
}
|
||||||
logger.log({ project_id }, 'queued project history resync via http')
|
logger.log({ project_id }, 'queued project history resync via http')
|
||||||
|
@ -416,9 +369,6 @@ module.exports = HttpController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
flushAllProjects(req, res, next) {
|
flushAllProjects(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
res.setTimeout(5 * 60 * 1000)
|
res.setTimeout(5 * 60 * 1000)
|
||||||
const options = {
|
const options = {
|
||||||
limit: req.query.limit || 1000,
|
limit: req.query.limit || 1000,
|
||||||
|
@ -426,7 +376,7 @@ module.exports = HttpController = {
|
||||||
dryRun: req.query.dryRun || false
|
dryRun: req.query.dryRun || false
|
||||||
}
|
}
|
||||||
ProjectFlusher.flushAllProjects(options, function (err, project_ids) {
|
ProjectFlusher.flushAllProjects(options, function (err, project_ids) {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
logger.err({ err }, 'error bulk flushing projects')
|
logger.err({ err }, 'error bulk flushing projects')
|
||||||
res.sendStatus(500)
|
res.sendStatus(500)
|
||||||
} else {
|
} else {
|
||||||
|
@ -436,9 +386,6 @@ module.exports = HttpController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
flushQueuedProjects(req, res, next) {
|
flushQueuedProjects(req, res, next) {
|
||||||
if (next == null) {
|
|
||||||
next = function (error) {}
|
|
||||||
}
|
|
||||||
res.setTimeout(10 * 60 * 1000)
|
res.setTimeout(10 * 60 * 1000)
|
||||||
const options = {
|
const options = {
|
||||||
limit: req.query.limit || 1000,
|
limit: req.query.limit || 1000,
|
||||||
|
@ -449,7 +396,7 @@ module.exports = HttpController = {
|
||||||
err,
|
err,
|
||||||
flushed
|
flushed
|
||||||
) {
|
) {
|
||||||
if (err != null) {
|
if (err) {
|
||||||
logger.err({ err }, 'error flushing old projects')
|
logger.err({ err }, 'error flushing old projects')
|
||||||
res.sendStatus(500)
|
res.sendStatus(500)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue