2
1

video-shares.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as express from 'express'
  2. import 'express-validator'
  3. import { param } from 'express-validator/check'
  4. import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
  5. import { doesVideoExist } from '../../../helpers/custom-validators/videos'
  6. import { logger } from '../../../helpers/logger'
  7. import { VideoShareModel } from '../../../models/video/video-share'
  8. import { areValidationErrors } from '../utils'
  9. const videosShareValidator = [
  10. param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
  11. param('actorId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
  12. async (req: express.Request, res: express.Response, next: express.NextFunction) => {
  13. logger.debug('Checking videoShare parameters', { parameters: req.params })
  14. if (areValidationErrors(req, res)) return
  15. if (!await doesVideoExist(req.params.id, res)) return
  16. const video = res.locals.video
  17. const share = await VideoShareModel.load(req.params.actorId, video.id)
  18. if (!share) {
  19. return res.status(404)
  20. .end()
  21. }
  22. res.locals.videoShare = share
  23. return next()
  24. }
  25. ]
  26. // ---------------------------------------------------------------------------
  27. export {
  28. videosShareValidator
  29. }