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'
10 const videosShareValidator = [
11 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
12 param('actorId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
14 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking videoShare parameters', { parameters: req.params })
17 if (areValidationErrors(req, res)) return
18 if (!await doesVideoExist(req.params.id, res)) return
20 const video = res.locals.video
22 const share = await VideoShareModel.load(req.params.actorId, video.id)
24 return res.status(404)
28 res.locals.videoShare = share
33 // ---------------------------------------------------------------------------