|
|
@@ -3,24 +3,23 @@ async = require "async"
|
|
|
Settings = require "settings-sharelatex"
|
|
|
request = require('request')
|
|
|
Project = require("../../models/Project").Project
|
|
|
+ProjectEntityHandler = require("../Project/ProjectEntityHandler")
|
|
|
logger = require "logger-sharelatex"
|
|
|
url = require("url")
|
|
|
|
|
|
module.exports = ClsiManager =
|
|
|
sendRequest: (project_id, callback = (error, success) ->) ->
|
|
|
- Project.findById project_id, (error, project) ->
|
|
|
+ ClsiManager._buildRequest project_id, (error, req) ->
|
|
|
return callback(error) if error?
|
|
|
- ClsiManager._buildRequest project, (error, req) ->
|
|
|
+ logger.log project_id: project_id, "sending compile to CLSI"
|
|
|
+ ClsiManager._postToClsi project_id, req, (error, response) ->
|
|
|
return callback(error) if error?
|
|
|
- logger.log project_id: project_id, "sending compile to CLSI"
|
|
|
- ClsiManager._postToClsi project_id, req, (error, response) ->
|
|
|
- return callback(error) if error?
|
|
|
- logger.log project_id: project_id, response: response, "received compile response from CLSI"
|
|
|
- callback(
|
|
|
- null
|
|
|
- (response?.compile?.status == "success")
|
|
|
- ClsiManager._parseOutputFiles(project_id, response?.compile?.outputFiles)
|
|
|
- )
|
|
|
+ logger.log project_id: project_id, response: response, "received compile response from CLSI"
|
|
|
+ callback(
|
|
|
+ null
|
|
|
+ (response?.compile?.status == "success")
|
|
|
+ ClsiManager._parseOutputFiles(project_id, response?.compile?.outputFiles)
|
|
|
+ )
|
|
|
|
|
|
getLogLines: (project_id, callback = (error, lines) ->) ->
|
|
|
request "#{Settings.apis.clsi.url}/project/#{project_id}/output/output.log", (error, response, body) ->
|
|
|
@@ -44,54 +43,45 @@ module.exports = ClsiManager =
|
|
|
return outputFiles
|
|
|
|
|
|
VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"]
|
|
|
- _buildRequest: (project, callback = (error, request) ->) ->
|
|
|
- if project.compiler not in @VALID_COMPILERS
|
|
|
- project.compiler = "pdflatex"
|
|
|
-
|
|
|
- resources = []
|
|
|
- rootResourcePath = null
|
|
|
-
|
|
|
- addDoc = (basePath, doc, callback = (error) ->) ->
|
|
|
- path = Path.join(basePath, doc.name)
|
|
|
- resources.push
|
|
|
- path: path
|
|
|
- content: doc.lines.join("\n")
|
|
|
- if doc._id.toString() == project.rootDoc_id.toString()
|
|
|
- rootResourcePath = path
|
|
|
- callback()
|
|
|
+ _buildRequest: (project_id, callback = (error, request) ->) ->
|
|
|
+ Project.findById project_id, {compiler: 1, rootDoc_id: 1}, (error, project) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ return callback(new Errors.NotFoundError("project does not exist: #{project_id}")) if !project?
|
|
|
|
|
|
- addFile = (basePath, file, callback = (error) ->) ->
|
|
|
- resources.push
|
|
|
- path: Path.join(basePath, file.name)
|
|
|
- url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}"
|
|
|
- modified: file.created?.getTime()
|
|
|
- callback()
|
|
|
+ if project.compiler not in ClsiManager.VALID_COMPILERS
|
|
|
+ project.compiler = "pdflatex"
|
|
|
|
|
|
- addFolder = (basePath, folder, callback = (error) ->) ->
|
|
|
- jobs = []
|
|
|
- for doc in folder.docs
|
|
|
- do (doc) ->
|
|
|
- jobs.push (callback) -> addDoc(basePath, doc, callback)
|
|
|
+ ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ ProjectEntityHandler.getAllFiles project_id, (error, files = {}) ->
|
|
|
+ return callback(error) if error?
|
|
|
|
|
|
- for file in folder.fileRefs
|
|
|
- do (file) ->
|
|
|
- jobs.push (callback) -> addFile(basePath, file, callback)
|
|
|
+ resources = []
|
|
|
+ rootResourcePath = null
|
|
|
|
|
|
- for childFolder in folder.folders
|
|
|
- do (childFolder) ->
|
|
|
- jobs.push (callback) -> addFolder(Path.join(basePath, childFolder.name), childFolder, callback)
|
|
|
+ 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
|
|
|
|
|
|
- async.series jobs, callback
|
|
|
+ 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()
|
|
|
|
|
|
- addFolder "", project.rootFolder[0], (error) ->
|
|
|
- if !rootResourcePath?
|
|
|
- callback new Error("no root document exists")
|
|
|
- else
|
|
|
- callback null, {
|
|
|
- compile:
|
|
|
- options:
|
|
|
- compiler: project.compiler
|
|
|
- rootResourcePath: rootResourcePath
|
|
|
- resources: resources
|
|
|
- }
|
|
|
+ if !rootResourcePath?
|
|
|
+ callback new Error("no root document exists")
|
|
|
+ else
|
|
|
+ callback null, {
|
|
|
+ compile:
|
|
|
+ options:
|
|
|
+ compiler: project.compiler
|
|
|
+ rootResourcePath: rootResourcePath
|
|
|
+ resources: resources
|
|
|
+ }
|
|
|
|