split request to mongo into separate method

This commit is contained in:
Brian Gough 2017-07-28 15:17:10 +01:00
parent 3e28eca26f
commit d66382382f

View file

@ -110,50 +110,56 @@ module.exports = ClsiManager =
if project.compiler not in ClsiManager.VALID_COMPILERS
project.compiler = "pdflatex"
DocumentUpdaterHandler.flushProjectToMongo project_id, (error) ->
ClsiManager._getContentFromMongo project_id, (error, docs, files) ->
return callback(error) if error?
ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) ->
return callback(error) if error?
ProjectEntityHandler.getAllFiles project_id, (error, files = {}) ->
return callback(error) if error?
ClsiManager._finaliseRequest project_id, options, project, docs, files, callback
resources = []
rootResourcePath = null
rootResourcePathOverride = null
_getContentFromMongo: (project_id, callback = (error, docs, files) ->) ->
DocumentUpdaterHandler.flushProjectToMongo project_id, (error) ->
return callback(error) if error?
ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) ->
return callback(error) if error?
ProjectEntityHandler.getAllFiles project_id, (error, files = {}) ->
callback(null, docs, files)
for path, doc of docs
path = path.replace(/^\//, "") # Remove leading /
resources.push
path: path
content: doc.lines.join("\n")
if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString()
rootResourcePath = path
if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString()
rootResourcePathOverride = path
_finaliseRequest: (project_id, options, project, docs, files, callback = (error, params) -> ) ->
resources = []
rootResourcePath = null
rootResourcePathOverride = null
rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
if !rootResourcePath?
logger.warn {project_id}, "no root document found, setting to main.tex"
rootResourcePath = "main.tex"
for path, doc of docs
path = path.replace(/^\//, "") # Remove leading /
resources.push
path: path
content: doc.lines.join("\n")
if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString()
rootResourcePath = path
if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString()
rootResourcePathOverride = path
for path, file of files
path = path.replace(/^\//, "") # Remove leading /
resources.push
path: path
url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}"
modified: file.created?.getTime()
rootResourcePath = rootResourcePathOverride if rootResourcePathOverride?
if !rootResourcePath?
logger.warn {project_id}, "no root document found, setting to main.tex"
rootResourcePath = "main.tex"
callback null, {
compile:
options:
compiler: project.compiler
timeout: options.timeout
imageName: project.imageName
draft: !!options.draft
check: options.check
rootResourcePath: rootResourcePath
resources: resources
}
for path, file of files
path = path.replace(/^\//, "") # Remove leading /
resources.push
path: path
url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}"
modified: file.created?.getTime()
callback null, {
compile:
options:
compiler: project.compiler
timeout: options.timeout
imageName: project.imageName
draft: !!options.draft
check: options.check
rootResourcePath: rootResourcePath
resources: resources
}
wordCount: (project_id, user_id, file, options, callback = (error, response) ->) ->
ClsiManager._buildRequest project_id, options, (error, req) ->