From d93eb448e3d987d2783db98b0c1c5892764802cd Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Fri, 15 Jun 2018 16:20:55 +0100 Subject: [PATCH] Move Clsi logic to ClsiManager --- .../app/coffee/Features/Compile/ClsiManager.coffee | 8 ++++++++ .../LinkedFiles/ProjectOutputFileAgent.coffee | 11 ++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index e5158cdb9b..232b416e66 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -182,6 +182,14 @@ module.exports = ClsiManager = return callback(error) if error? 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) ->) -> ProjectEntityHandler.getAllDocPathsFromProject project, (error, docPath) -> return callback(error) if error? diff --git a/services/web/app/coffee/Features/LinkedFiles/ProjectOutputFileAgent.coffee b/services/web/app/coffee/Features/LinkedFiles/ProjectOutputFileAgent.coffee index d194032273..0c84d3f7dc 100644 --- a/services/web/app/coffee/Features/LinkedFiles/ProjectOutputFileAgent.coffee +++ b/services/web/app/coffee/Features/LinkedFiles/ProjectOutputFileAgent.coffee @@ -4,8 +4,8 @@ ProjectGetter = require('../Project/ProjectGetter') FileWriter = require('../../infrastructure/FileWriter') Settings = require 'settings-sharelatex' CompileManager = require '../Compile/CompileManager' -CompileController = require '../Compile/CompileController' ClsiCookieManager = require '../Compile/ClsiCookieManager' +ClsiManager = require '../Compile/ClsiManager' ProjectFileAgent = require './ProjectFileAgent' _ = require "underscore" request = require "request" @@ -59,16 +59,13 @@ module.exports = ProjectOutputFileAgent = { source_project_id = project._id CompileManager.compile source_project_id, null, {}, (err) -> return callback(err) if err? - url = "#{Settings.apis.clsi.url}/project/#{source_project_id}/output/#{source_output_file_path}" - ClsiCookieManager.getCookieJar source_project_id, (err, jar)-> + ClsiManager.getOutputFileStream source_project_id, source_output_file_path, (err, readStream) -> return callback(err) if err? - oneMinute = 60 * 1000 - # the base request - options = { url: url, method: "GET", timeout: oneMinute, jar : jar } - readStream = request(options) + readStream.pause() readStream.on "error", callback readStream.on "response", (response) -> if 200 <= response.statusCode < 300 + readStream.resume() FileWriter.writeStreamToDisk project_id, readStream, callback else error = new OutputFileFetchFailedError("Output file fetch failed: #{url}")