diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index e128a6fb24..77c96d0f3e 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -41,6 +41,20 @@ module.exports = CompileController = project_id = req.params.Project_id 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)-> res.contentType("application/pdf") if !!req.query.popupDownload @@ -50,19 +64,7 @@ module.exports = CompileController = logger.log project_id: project_id, "download pdf to embed in browser" res.header('Content-Disposition', "filename=#{project.getSafeProjectName()}.pdf") - - 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)-> + rateLimit (err, canContinue)-> if err? logger.err err:err, "error checking rate limit for pdf download" return res.send 500 diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index 7fddfec33d..f1a31fcef9 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -129,9 +129,6 @@ describe "CompileController", -> 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 - 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", -> it "should check the rate limiter when pdfng is not set", (done)->