video-shares.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as express from 'express'
  2. import { param } from 'express-validator'
  3. import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
  4. import { logger } from '../../../helpers/logger'
  5. import { VideoShareModel } from '../../../models/video/video-share'
  6. import { areValidationErrors } from '../utils'
  7. import { doesVideoExist } from '../../../helpers/middlewares'
  8. import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
  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.videoAll
  17. const share = await VideoShareModel.load(req.params.actorId, video.id)
  18. if (!share) {
  19. return res.status(HttpStatusCode.NOT_FOUND_404)
  20. .end()
  21. }
  22. res.locals.videoShare = share
  23. return next()
  24. }
  25. ]
  26. // ---------------------------------------------------------------------------
  27. export {
  28. videosShareValidator
  29. }