]>
Commit | Line | Data |
---|---|---|
5c6d985f C |
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' | |
0f6acda1 | 5 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' |
5c6d985f C |
6 | import { logger } from '../../../helpers/logger' |
7 | import { VideoShareModel } from '../../../models/video/video-share' | |
8 | import { areValidationErrors } from '../utils' | |
5c6d985f C |
9 | |
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'), | |
13 | ||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
15 | logger.debug('Checking videoShare parameters', { parameters: req.params }) | |
16 | ||
17 | if (areValidationErrors(req, res)) return | |
0f6acda1 | 18 | if (!await doesVideoExist(req.params.id, res)) return |
5c6d985f | 19 | |
dae86118 | 20 | const video = res.locals.video |
5c6d985f C |
21 | |
22 | const share = await VideoShareModel.load(req.params.actorId, video.id) | |
23 | if (!share) { | |
24 | return res.status(404) | |
25 | .end() | |
26 | } | |
27 | ||
28 | res.locals.videoShare = share | |
29 | return next() | |
30 | } | |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | videosShareValidator | |
37 | } |