bulk.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import express from 'express'
  2. import { body } from 'express-validator'
  3. import { isBulkRemoveCommentsOfScopeValid } from '@server/helpers/custom-validators/bulk'
  4. import { HttpStatusCode, UserRight } from '@shared/models'
  5. import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
  6. import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
  7. const bulkRemoveCommentsOfValidator = [
  8. body('accountName')
  9. .exists(),
  10. body('scope')
  11. .custom(isBulkRemoveCommentsOfScopeValid),
  12. async (req: express.Request, res: express.Response, next: express.NextFunction) => {
  13. if (areValidationErrors(req, res)) return
  14. if (!await doesAccountNameWithHostExist(req.body.accountName, res)) return
  15. const user = res.locals.oauth.token.User
  16. const body = req.body as BulkRemoveCommentsOfBody
  17. if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) {
  18. return res.fail({
  19. status: HttpStatusCode.FORBIDDEN_403,
  20. message: 'User cannot remove any comments of this instance.'
  21. })
  22. }
  23. return next()
  24. }
  25. ]
  26. // ---------------------------------------------------------------------------
  27. export {
  28. bulkRemoveCommentsOfValidator
  29. }
  30. // ---------------------------------------------------------------------------