CooldownMiddleware.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. import CooldownManager from './CooldownManager.mjs'
  14. import logger from '@overleaf/logger'
  15. let CooldownMiddleware
  16. export default 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.debug(
  30. { projectId },
  31. '[Cooldown] project is on cooldown, denying request'
  32. )
  33. return res.sendStatus(429)
  34. }
  35. return next()
  36. }
  37. )
  38. },
  39. }