]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-shares.ts
Fix filters on playlists
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-shares.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { param } from 'express-validator'
c0e8b12e 3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
d4a8e7a6 4import { isIdValid } from '../../../helpers/custom-validators/misc'
5c6d985f 5import { VideoShareModel } from '../../../models/video/video-share'
d4a8e7a6 6import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
5c6d985f
C
7
8const 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
33export {
34 videosShareValidator
35}