Move Clsi logic to ClsiManager

This commit is contained in:
Shane Kilkelly 2018-06-15 16:20:55 +01:00
parent 54cdbd738c
commit d93eb448e3
2 changed files with 12 additions and 7 deletions

View file

@ -182,6 +182,14 @@ module.exports = ClsiManager =
return callback(error) if error? return callback(error) if error?
callback(null, projectStateHash, docs) callback(null, projectStateHash, docs)
getOutputFileStream: (project_id, output_file_path, callback=(err, readStream)->) ->
url = "#{Settings.apis.clsi.url}/project/#{project_id}/output/#{output_file_path}"
ClsiCookieManager.getCookieJar project_id, (err, jar)->
return callback(err) if err?
options = { url: url, method: "GET", timeout: 60 * 1000, jar : jar }
readStream = request(options)
callback(null, readStream)
_buildRequestFromDocupdater: (project_id, options, project, projectStateHash, docUpdaterDocs, callback = (error, request) ->) -> _buildRequestFromDocupdater: (project_id, options, project, projectStateHash, docUpdaterDocs, callback = (error, request) ->) ->
ProjectEntityHandler.getAllDocPathsFromProject project, (error, docPath) -> ProjectEntityHandler.getAllDocPathsFromProject project, (error, docPath) ->
return callback(error) if error? return callback(error) if error?

View file

@ -4,8 +4,8 @@ ProjectGetter = require('../Project/ProjectGetter')
FileWriter = require('../../infrastructure/FileWriter') FileWriter = require('../../infrastructure/FileWriter')
Settings = require 'settings-sharelatex' Settings = require 'settings-sharelatex'
CompileManager = require '../Compile/CompileManager' CompileManager = require '../Compile/CompileManager'
CompileController = require '../Compile/CompileController'
ClsiCookieManager = require '../Compile/ClsiCookieManager' ClsiCookieManager = require '../Compile/ClsiCookieManager'
ClsiManager = require '../Compile/ClsiManager'
ProjectFileAgent = require './ProjectFileAgent' ProjectFileAgent = require './ProjectFileAgent'
_ = require "underscore" _ = require "underscore"
request = require "request" request = require "request"
@ -59,16 +59,13 @@ module.exports = ProjectOutputFileAgent = {
source_project_id = project._id source_project_id = project._id
CompileManager.compile source_project_id, null, {}, (err) -> CompileManager.compile source_project_id, null, {}, (err) ->
return callback(err) if err? return callback(err) if err?
url = "#{Settings.apis.clsi.url}/project/#{source_project_id}/output/#{source_output_file_path}" ClsiManager.getOutputFileStream source_project_id, source_output_file_path, (err, readStream) ->
ClsiCookieManager.getCookieJar source_project_id, (err, jar)->
return callback(err) if err? return callback(err) if err?
oneMinute = 60 * 1000 readStream.pause()
# the base request
options = { url: url, method: "GET", timeout: oneMinute, jar : jar }
readStream = request(options)
readStream.on "error", callback readStream.on "error", callback
readStream.on "response", (response) -> readStream.on "response", (response) ->
if 200 <= response.statusCode < 300 if 200 <= response.statusCode < 300
readStream.resume()
FileWriter.writeStreamToDisk project_id, readStream, callback FileWriter.writeStreamToDisk project_id, readStream, callback
else else
error = new OutputFileFetchFailedError("Output file fetch failed: #{url}") error = new OutputFileFetchFailedError("Output file fetch failed: #{url}")