]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { param } from 'express-validator' |
c0e8b12e | 3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
d4a8e7a6 | 4 | import { isIdValid } from '../../../helpers/custom-validators/misc' |
5c6d985f | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
d4a8e7a6 | 6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' |
5c6d985f C |
7 | |
8 | const videosShareValidator = [ | |
d4a8e7a6 C |
9 | isValidVideoIdParam('id'), |
10 | ||
11 | param('actorId') | |
396f6f01 | 12 | .custom(isIdValid), |
5c6d985f C |
13 | |
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
5c6d985f | 15 | if (areValidationErrors(req, res)) return |
0f6acda1 | 16 | if (!await doesVideoExist(req.params.id, res)) return |
5c6d985f | 17 | |
453e83ea | 18 | const video = res.locals.videoAll |
5c6d985f C |
19 | |
20 | const share = await VideoShareModel.load(req.params.actorId, video.id) | |
21 | if (!share) { | |
2d53be02 | 22 | return res.status(HttpStatusCode.NOT_FOUND_404) |
5c6d985f C |
23 | .end() |
24 | } | |
25 | ||
26 | res.locals.videoShare = share | |
27 | return next() | |
28 | } | |
29 | ] | |
30 | ||
31 | // --------------------------------------------------------------------------- | |
32 | ||
33 | export { | |
34 | videosShareValidator | |
35 | } |