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