mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-25 00:21:30 +00:00
Merge pull request #156 from sharelatex/support-cached-pdfs
Support cached pdfs with build parameter
This commit is contained in:
commit
c29329cb37
5 changed files with 47 additions and 12 deletions
|
@ -54,6 +54,7 @@ module.exports = ClsiManager =
|
||||||
outputFiles.push
|
outputFiles.push
|
||||||
path: url.parse(file.url).path.replace("/project/#{project_id}/output/", "")
|
path: url.parse(file.url).path.replace("/project/#{project_id}/output/", "")
|
||||||
type: file.type
|
type: file.type
|
||||||
|
build: file.build
|
||||||
return outputFiles
|
return outputFiles
|
||||||
|
|
||||||
VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"]
|
VALID_COMPILERS: ["pdflatex", "latex", "xelatex", "lualatex"]
|
||||||
|
|
|
@ -85,15 +85,20 @@ module.exports = CompileController =
|
||||||
url = "#{compilerUrl}#{url}"
|
url = "#{compilerUrl}#{url}"
|
||||||
logger.log url: url, "proxying to CLSI"
|
logger.log url: url, "proxying to CLSI"
|
||||||
oneMinute = 60 * 1000
|
oneMinute = 60 * 1000
|
||||||
# pass through If-* and Range headers for byte serving pdfs
|
# the base request
|
||||||
# do not send any others, potential proxying loop if Host: is passed!
|
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
|
if req.query?.pdfng
|
||||||
newHeaders = {}
|
newHeaders = {}
|
||||||
for h, v of req.headers
|
for h, v of req.headers
|
||||||
newHeaders[h] = req.headers[h] if h.match /^(If-|Range)/i
|
newHeaders[h] = req.headers[h] if h.match /^(If-|Range)/i
|
||||||
proxy = request(url: url, method: req.method, timeout: oneMinute, headers: newHeaders)
|
options.headers = newHeaders
|
||||||
else
|
proxy = request(options)
|
||||||
proxy = request(url: url, method: req.method, timeout: oneMinute)
|
|
||||||
proxy.pipe(res)
|
proxy.pipe(res)
|
||||||
proxy.on "error", (error) ->
|
proxy.on "error", (error) ->
|
||||||
logger.warn err: error, url: url, "CLSI proxy error"
|
logger.warn err: error, url: url, "CLSI proxy error"
|
||||||
|
|
|
@ -41,13 +41,22 @@ define [
|
||||||
$scope.pdf.failure = true
|
$scope.pdf.failure = true
|
||||||
fetchLogs()
|
fetchLogs()
|
||||||
else if response.status == "success"
|
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?
|
if response.compileGroup?
|
||||||
$scope.pdf.compileGroup = response.compileGroup
|
$scope.pdf.compileGroup = response.compileGroup
|
||||||
$scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}" +
|
$scope.pdf.url = $scope.pdf.url + "&compileGroup=#{$scope.pdf.compileGroup}"
|
||||||
"&compileGroup=#{$scope.pdf.compileGroup}"
|
# make a cache to look up files by name
|
||||||
else
|
fileByPath = {}
|
||||||
$scope.pdf.url = "/project/#{$scope.project_id}/output/output.pdf?cache_bust=#{Date.now()}"
|
for file in response.outputFiles
|
||||||
fetchLogs()
|
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(fileByPath['output.log'])
|
||||||
|
|
||||||
IGNORE_FILES = ["output.fls", "output.fdb_latexmk"]
|
IGNORE_FILES = ["output.fls", "output.fdb_latexmk"]
|
||||||
$scope.pdf.outputFiles = []
|
$scope.pdf.outputFiles = []
|
||||||
|
@ -63,8 +72,9 @@ define [
|
||||||
file.name = file.path
|
file.name = file.path
|
||||||
$scope.pdf.outputFiles.push file
|
$scope.pdf.outputFiles.push file
|
||||||
|
|
||||||
fetchLogs = () ->
|
fetchLogs = (outputFile) ->
|
||||||
$http.get "/project/#{$scope.project_id}/output/output.log"
|
qs = if outputFile?.build? then "?build=#{outputFile.build}" else ""
|
||||||
|
$http.get "/project/#{$scope.project_id}/output/output.log" + qs
|
||||||
.success (log) ->
|
.success (log) ->
|
||||||
$scope.pdf.rawLog = log
|
$scope.pdf.rawLog = log
|
||||||
logEntries = LogParser.parse(log, ignoreDuplicates: true)
|
logEntries = LogParser.parse(log, ignoreDuplicates: true)
|
||||||
|
|
|
@ -36,9 +36,11 @@ describe "ClsiManager", ->
|
||||||
outputFiles: [{
|
outputFiles: [{
|
||||||
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.pdf"
|
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.pdf"
|
||||||
type: "pdf"
|
type: "pdf"
|
||||||
|
build: 1234
|
||||||
},{
|
},{
|
||||||
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.log"
|
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.log"
|
||||||
type: "log"
|
type: "log"
|
||||||
|
build: 1234
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
@ClsiManager.sendRequest @project_id, {compileGroup:"standard"}, @callback
|
@ClsiManager.sendRequest @project_id, {compileGroup:"standard"}, @callback
|
||||||
|
@ -57,9 +59,11 @@ describe "ClsiManager", ->
|
||||||
outputFiles = [{
|
outputFiles = [{
|
||||||
path: "output.pdf"
|
path: "output.pdf"
|
||||||
type: "pdf"
|
type: "pdf"
|
||||||
|
build: 1234
|
||||||
},{
|
},{
|
||||||
path: "output.log"
|
path: "output.log"
|
||||||
type: "log"
|
type: "log"
|
||||||
|
build: 1234
|
||||||
}]
|
}]
|
||||||
@callback.calledWith(null, @status, outputFiles).should.equal true
|
@callback.calledWith(null, @status, outputFiles).should.equal true
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,21 @@ describe "CompileController", ->
|
||||||
)
|
)
|
||||||
.should.equal true
|
.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", ->
|
describe "new pdf viewer", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue