2017-05-09 06:40:42 -04:00
|
|
|
CooldownManager = require('./CooldownManager')
|
|
|
|
logger = require('logger-sharelatex')
|
|
|
|
|
|
|
|
|
2019-03-04 07:02:28 -05:00
|
|
|
module.exports = CooldownMiddleware =
|
2017-05-09 06:40:42 -04:00
|
|
|
|
|
|
|
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'))
|
2017-05-09 06:40:42 -04:00
|
|
|
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()
|