mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
only rate limit full pdf downloads
This commit is contained in:
parent
da9535f442
commit
16670cb3e3
2 changed files with 15 additions and 16 deletions
|
@ -41,6 +41,20 @@ module.exports = CompileController =
|
||||||
project_id = req.params.Project_id
|
project_id = req.params.Project_id
|
||||||
isPdfjsPartialDownload = req.query?.pdfng
|
isPdfjsPartialDownload = req.query?.pdfng
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
rateLimit = (callback)->
|
||||||
|
if isPdfjsPartialDownload
|
||||||
|
callback null, true
|
||||||
|
|
||||||
|
else
|
||||||
|
rateLimitOpts =
|
||||||
|
endpointName: "full-pdf-download"
|
||||||
|
throttle: 30
|
||||||
|
subjectName : req.ip
|
||||||
|
timeInterval : 60 * 5
|
||||||
|
RateLimiter.addCount rateLimitOpts, callback
|
||||||
|
|
||||||
Project.findById project_id, {name: 1}, (err, project)->
|
Project.findById project_id, {name: 1}, (err, project)->
|
||||||
res.contentType("application/pdf")
|
res.contentType("application/pdf")
|
||||||
if !!req.query.popupDownload
|
if !!req.query.popupDownload
|
||||||
|
@ -50,19 +64,7 @@ module.exports = CompileController =
|
||||||
logger.log project_id: project_id, "download pdf to embed in browser"
|
logger.log project_id: project_id, "download pdf to embed in browser"
|
||||||
res.header('Content-Disposition', "filename=#{project.getSafeProjectName()}.pdf")
|
res.header('Content-Disposition', "filename=#{project.getSafeProjectName()}.pdf")
|
||||||
|
|
||||||
|
rateLimit (err, canContinue)->
|
||||||
if isPdfjsPartialDownload
|
|
||||||
rateLimitOpts =
|
|
||||||
endpointName: "partial-pdf-download"
|
|
||||||
throttle: 500
|
|
||||||
else
|
|
||||||
rateLimitOpts =
|
|
||||||
endpointName: "full-pdf-download"
|
|
||||||
throttle: 30
|
|
||||||
|
|
||||||
rateLimitOpts.subjectName = req.ip
|
|
||||||
rateLimitOpts.timeInterval = 60 * 5
|
|
||||||
RateLimiter.addCount rateLimitOpts, (err, canContinue)->
|
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, "error checking rate limit for pdf download"
|
logger.err err:err, "error checking rate limit for pdf download"
|
||||||
return res.send 500
|
return res.send 500
|
||||||
|
|
|
@ -129,9 +129,6 @@ describe "CompileController", ->
|
||||||
it "should proxy the PDF from the CLSI", ->
|
it "should proxy the PDF from the CLSI", ->
|
||||||
@CompileController.proxyToClsi.calledWith(@project_id, "/project/#{@project_id}/output/output.pdf", @req, @res, @next).should.equal true
|
@CompileController.proxyToClsi.calledWith(@project_id, "/project/#{@project_id}/output/output.pdf", @req, @res, @next).should.equal true
|
||||||
|
|
||||||
it "should check the rate limiter", ->
|
|
||||||
@RateLimiter.addCount.args[0][0].throttle.should.equal 500
|
|
||||||
|
|
||||||
describe "when the pdf is not going to be used in pdfjs viewer", ->
|
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)->
|
it "should check the rate limiter when pdfng is not set", (done)->
|
||||||
|
|
Loading…
Reference in a new issue