From 5b9f2e8fc1654902cb4a63553dcc11aef1cc5020 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 25 Feb 2015 17:06:27 +0000 Subject: [PATCH 1/4] pass build id through to clsi when requesting pdf --- .../coffee/Features/Compile/ClsiManager.coffee | 1 + .../Features/Compile/CompileController.coffee | 15 ++++++++++----- .../ide/pdf/controllers/PdfController.coffee | 13 +++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 0e910d8591..22598d7dfa 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -54,6 +54,7 @@ module.exports = ClsiManager = outputFiles.push path: url.parse(file.url).path.replace("/project/#{project_id}/output/", "") type: file.type + build: file.build return outputFiles VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"] diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index b95a8ed82c..16840ef576 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -85,15 +85,20 @@ module.exports = CompileController = url = "#{compilerUrl}#{url}" logger.log url: url, "proxying to CLSI" oneMinute = 60 * 1000 - # pass through If-* and Range headers for byte serving pdfs - # do not send any others, potential proxying loop if Host: is passed! + # the base request + options = { url: url, method: req.method, timeout: oneMinute } + # if we have a build parameter, pass it through to the clsi + if req.query?.build? + options.qs = {} + options.qs.build = req.query.build + # if we are byte serving pdfs, pass through If-* and Range headers + # do not send any others, there's a proxying loop if Host: is passed! if req.query?.pdfng newHeaders = {} for h, v of req.headers newHeaders[h] = req.headers[h] if h.match /^(If-|Range)/i - proxy = request(url: url, method: req.method, timeout: oneMinute, headers: newHeaders) - else - proxy = request(url: url, method: req.method, timeout: oneMinute) + options.headers = newHeaders + proxy = request(options) proxy.pipe(res) proxy.on "error", (error) -> logger.warn err: error, url: url, "CLSI proxy error" diff --git a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee index bd17965d26..43b11dd14f 100644 --- a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee +++ b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee @@ -41,12 +41,17 @@ define [ $scope.pdf.failure = true fetchLogs() else if response.status == "success" + $scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}" if response.compileGroup? $scope.pdf.compileGroup = response.compileGroup - $scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}" + - "&compileGroup=#{$scope.pdf.compileGroup}" - else - $scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}" + $scope.pdf.url = $scope.pdf.url + "&compileGroup=#{$scope.pdf.compileGroup}" + fileByPath = {} + for file in response.outputFiles + fileByPath[file.path] = file + if fileByPath['output.pdf']?.build? + build = fileByPath['output.pdf'].build + $scope.pdf.url = $scope.pdf.url + "&build=#{build}" + fetchLogs() IGNORE_FILES = ["output.fls", "output.fdb_latexmk"] From a64b8724bd727560f2d8a268f738dc784840499f Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 26 Feb 2015 16:19:36 +0000 Subject: [PATCH 2/4] include the build parameter in the compile unit tests --- .../coffee/Compile/ClsiManagerTests.coffee | 4 ++++ .../coffee/Compile/CompileControllerTests.coffee | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee index 431aabec97..8eda10fa56 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee @@ -36,9 +36,11 @@ describe "ClsiManager", -> outputFiles: [{ url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.pdf" type: "pdf" + build: 1234 },{ url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.log" type: "log" + build: 1234 }] }) @ClsiManager.sendRequest @project_id, {compileGroup:"standard"}, @callback @@ -57,9 +59,11 @@ describe "ClsiManager", -> outputFiles = [{ path: "output.pdf" type: "pdf" + build: 1234 },{ path: "output.log" type: "log" + build: 1234 }] @callback.calledWith(null, @status, outputFiles).should.equal true diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index fae9dec23f..e2115addbb 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -231,6 +231,21 @@ describe "CompileController", -> ) .should.equal true + describe "user with build parameter via query string", -> + beforeEach -> + @CompileManager.getProjectCompileLimits = sinon.stub().callsArgWith(1, null, {compileGroup: "standard"}) + @req.query = {build: 1234} + @CompileController.proxyToClsi(@project_id, @url = "/test", @req, @res, @next) + + it "should proxy to the standard url with the build parameter", ()-> + @request + .calledWith( + method: @req.method + qs: {build: 1234} + url: "#{@settings.apis.clsi.url}#{@url}", + timeout: 60 * 1000 + ) + .should.equal true describe "new pdf viewer", -> beforeEach -> From caed778117aaa50c0ec628be97027121d82d3e12 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 26 Feb 2015 16:47:47 +0000 Subject: [PATCH 3/4] load output files from cached build when known --- .../ide/pdf/controllers/PdfController.coffee | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee index 43b11dd14f..08d1543b31 100644 --- a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee +++ b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee @@ -41,18 +41,22 @@ define [ $scope.pdf.failure = true fetchLogs() else if response.status == "success" + # define the base url $scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}" + # add a query string parameter for the compile group if response.compileGroup? $scope.pdf.compileGroup = response.compileGroup $scope.pdf.url = $scope.pdf.url + "&compileGroup=#{$scope.pdf.compileGroup}" + # make a cache to look up files by name fileByPath = {} for file in response.outputFiles fileByPath[file.path] = file + # if the pdf file has a build number, pass it to the clsi if fileByPath['output.pdf']?.build? build = fileByPath['output.pdf'].build $scope.pdf.url = $scope.pdf.url + "&build=#{build}" - fetchLogs() + fetchLogs(fileByPath['output.log']) IGNORE_FILES = ["output.fls", "output.fdb_latexmk"] $scope.pdf.outputFiles = [] @@ -65,8 +69,9 @@ define [ file.name = file.path $scope.pdf.outputFiles.push file - fetchLogs = () -> - $http.get "/project/#{$scope.project_id}/output/output.log" + fetchLogs = (outputFile) -> + qs = if outputFile?.build? then "?build=#{outputFile.build}" else "" + $http.get "/project/#{$scope.project_id}/output/output.log" + qs .success (log) -> $scope.pdf.rawLog = log logEntries = LogParser.parse(log, ignoreDuplicates: true) @@ -156,7 +161,8 @@ define [ $scope.pdf.showRawLog = !$scope.pdf.showRawLog $scope.openOutputFile = (file) -> - window.open("/project/#{$scope.project_id}/output/#{file.path}") + qs = if file.build? then "?build=#{file.build}" else "" + window.open("/project/#{$scope.project_id}/output/#{file.path}#{qs}") $scope.openClearCacheModal = () -> modalInstance = $modal.open( From 7aea33b5627cfa361db9babbd8638e9bf5531cb6 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 2 Mar 2015 12:18:10 +0000 Subject: [PATCH 4/4] keep existing behaviour when loading other output files --- .../web/public/coffee/ide/pdf/controllers/PdfController.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee index af5036dd41..f7e4f91082 100644 --- a/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee +++ b/services/web/public/coffee/ide/pdf/controllers/PdfController.coffee @@ -165,8 +165,7 @@ define [ $scope.pdf.showRawLog = !$scope.pdf.showRawLog $scope.openOutputFile = (file) -> - qs = if file.build? then "?build=#{file.build}" else "" - window.open("/project/#{$scope.project_id}/output/#{file.path}#{qs}") + window.open("/project/#{$scope.project_id}/output/#{file.path}") $scope.openClearCacheModal = () -> modalInstance = $modal.open(