]>
Commit | Line | Data |
---|---|---|
5c6d985f | 1 | import * as express from 'express' |
c8861d5d | 2 | import { param } from 'express-validator' |
5c6d985f | 3 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5c6d985f C |
4 | import { logger } from '../../../helpers/logger' |
5 | import { VideoShareModel } from '../../../models/video/video-share' | |
6 | import { areValidationErrors } from '../utils' | |
3e753302 | 7 | import { doesVideoExist } from '../../../helpers/middlewares' |
2d53be02 | 8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
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 | |
453e83ea | 20 | const video = res.locals.videoAll |
5c6d985f C |
21 | |
22 | const share = await VideoShareModel.load(req.params.actorId, video.id) | |
23 | if (!share) { | |
2d53be02 | 24 | return res.status(HttpStatusCode.NOT_FOUND_404) |
5c6d985f C |
25 | .end() |
26 | } | |
27 | ||
28 | res.locals.videoShare = share | |
29 | return next() | |
30 | } | |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | videosShareValidator | |
37 | } |