From 5c6d985faeef1d6793d3f44ca6374f1a9b722806 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 14 Nov 2018 15:01:28 +0100 Subject: Check activities host --- .../middlewares/validators/videos/video-shares.ts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/middlewares/validators/videos/video-shares.ts (limited to 'server/middlewares/validators/videos/video-shares.ts') diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts new file mode 100644 index 000000000..646d7acb1 --- /dev/null +++ b/server/middlewares/validators/videos/video-shares.ts @@ -0,0 +1,38 @@ +import * as express from 'express' +import 'express-validator' +import { param } from 'express-validator/check' +import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' +import { isVideoExist } from '../../../helpers/custom-validators/videos' +import { logger } from '../../../helpers/logger' +import { VideoShareModel } from '../../../models/video/video-share' +import { areValidationErrors } from '../utils' +import { VideoModel } from '../../../models/video/video' + +const videosShareValidator = [ + param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), + param('actorId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking videoShare parameters', { parameters: req.params }) + + if (areValidationErrors(req, res)) return + if (!await isVideoExist(req.params.id, res)) return + + const video: VideoModel = res.locals.video + + const share = await VideoShareModel.load(req.params.actorId, video.id) + if (!share) { + return res.status(404) + .end() + } + + res.locals.videoShare = share + return next() + } +] + +// --------------------------------------------------------------------------- + +export { + videosShareValidator +} -- cgit v1.2.3