mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-08 07:11:58 +00:00
Merge pull request #1746 from overleaf/sk-fix-stale-pdf-download-3
Pass build-id when downloading pdf GitOrigin-RevId: bc4b1558170661172304df1b71f9b859a59abc5b
This commit is contained in:
parent
cbab60476a
commit
36035e8ccd
3 changed files with 45 additions and 4 deletions
services/web
app/coffee
public/src/ide/pdf/controllers
test/unit/coffee/Compile
|
@ -219,8 +219,28 @@ module.exports = class Router
|
|||
|
||||
webRouter.post '/project/:Project_id/compile/stop', AuthorizationMiddleware.ensureUserCanReadProject, CompileController.stopCompile
|
||||
|
||||
# Used by the web download buttons, adds filename header
|
||||
# LEGACY: Used by the web download buttons, adds filename header, TODO: remove at some future date
|
||||
webRouter.get '/project/:Project_id/output/output.pdf', AuthorizationMiddleware.ensureUserCanReadProject, CompileController.downloadPdf
|
||||
|
||||
# PDF Download button
|
||||
webRouter.get /^\/download\/project\/([^\/]*)\/output\/output\.pdf$/,
|
||||
((req, res, next) ->
|
||||
params =
|
||||
"Project_id": req.params[0]
|
||||
req.params = params
|
||||
next()
|
||||
), AuthorizationMiddleware.ensureUserCanReadProject, CompileController.downloadPdf
|
||||
|
||||
# PDF Download button for specific build
|
||||
webRouter.get /^\/download\/project\/([^\/]*)\/build\/([0-9a-f-]+)\/output\/output\.pdf$/,
|
||||
((req, res, next) ->
|
||||
params =
|
||||
"Project_id": req.params[0]
|
||||
"build_id": req.params[1]
|
||||
req.params = params
|
||||
next()
|
||||
), AuthorizationMiddleware.ensureUserCanReadProject, CompileController.downloadPdf
|
||||
|
||||
# Used by the pdf viewers
|
||||
webRouter.get /^\/project\/([^\/]*)\/output\/(.*)$/,
|
||||
((req, res, next) ->
|
||||
|
|
|
@ -503,12 +503,19 @@ define([
|
|||
}
|
||||
// convert the qs hash into a query string and append it
|
||||
$scope.pdf.url += createQueryString(qs)
|
||||
|
||||
// Save all downloads as files
|
||||
qs.popupDownload = true
|
||||
$scope.pdf.downloadUrl =
|
||||
`/project/${$scope.project_id}/output/output.pdf` +
|
||||
createQueryString(qs)
|
||||
|
||||
// Pass build id to download if we have it
|
||||
let buildId = null
|
||||
if (fileByPath['output.pdf'] && fileByPath['output.pdf'].build) {
|
||||
buildId = fileByPath['output.pdf'].build
|
||||
}
|
||||
$scope.pdf.downloadUrl =
|
||||
`/download/project/${$scope.project_id}${
|
||||
buildId ? '/build/' + buildId : ''
|
||||
}/output/output.pdf` + createQueryString(qs)
|
||||
fetchLogs(fileByPath, { pdfDownloadDomain })
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,20 @@ describe "CompileController", ->
|
|||
it "should proxy the PDF from the CLSI", ->
|
||||
@CompileController.proxyToClsi.calledWith(@project_id, "/project/#{@project_id}/user/#{@user_id}/output/output.pdf", @req, @res, @next).should.equal true
|
||||
|
||||
describe "when the a build-id is provided", ->
|
||||
beforeEach ->
|
||||
@req.params.build_id = @buildId = '1234-5678'
|
||||
@CompileController.proxyToClsi = sinon.stub()
|
||||
@RateLimiter.addCount.callsArgWith(1, null, true)
|
||||
@CompileController.downloadPdf(@req, @res, @next)
|
||||
|
||||
it "should proxy the PDF from the CLSI, with a build-id", ->
|
||||
@CompileController.proxyToClsi.calledWith(
|
||||
@project_id,
|
||||
"/project/#{@project_id}/user/#{@user_id}/build/#{@buildId}/output/output.pdf",
|
||||
@req, @res, @next
|
||||
).should.equal true
|
||||
|
||||
describe "when the pdf is not going to be used in pdfjs viewer", ->
|
||||
|
||||
it "should check the rate limiter when pdfng is not set", (done)->
|
||||
|
|
Loading…
Add table
Reference in a new issue