CooldownMiddleware.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. let CooldownMiddleware
  14. const CooldownManager = require('./CooldownManager')
  15. const logger = require('logger-sharelatex')
  16. module.exports = CooldownMiddleware = {
  17. freezeProject(req, res, next) {
  18. const projectId = req.params.Project_id
  19. if (projectId == null) {
  20. return next(new Error('[Cooldown] No projectId parameter on route'))
  21. }
  22. return CooldownManager.isProjectOnCooldown(
  23. projectId,
  24. function (err, projectIsOnCooldown) {
  25. if (err != null) {
  26. return next(err)
  27. }
  28. if (projectIsOnCooldown) {
  29. logger.log(
  30. { projectId },
  31. '[Cooldown] project is on cooldown, denying request'
  32. )
  33. return res.sendStatus(429)
  34. }
  35. return next()
  36. }
  37. )
  38. }
  39. }