overleaf/services/web/app/coffee/Features/Cooldown/CooldownMiddlewear.coffee

18 lines
556 B
CoffeeScript
Raw Normal View History

CooldownManager = require('./CooldownManager')
logger = require('logger-sharelatex')
module.exports = CooldownMiddlewear =
freezeProject: (req, res, next) ->
projectId = req.params.Project_id
2017-05-10 10:25:23 -04:00
if !projectId?
return next(new Error('[Cooldown] No projectId parameter on route'))
CooldownManager.isProjectOnCooldown projectId, (err, projectIsOnCooldown) ->
if err?
return next(err)
if projectIsOnCooldown
logger.log {projectId}, "[Cooldown] project is on cooldown, denying request"
return res.sendStatus(429)
next()