]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/videos/video-shares.ts
Fix redis connection timeout
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-shares.ts
1 import express from 'express'
2 import { param } from 'express-validator'
3 import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
4 import { isIdValid } from '../../../helpers/custom-validators/misc'
5 import { logger } from '../../../helpers/logger'
6 import { VideoShareModel } from '../../../models/video/video-share'
7 import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
8
9 const videosShareValidator = [
10 isValidVideoIdParam('id'),
11
12 param('actorId')
13 .custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
14
15 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking videoShare parameters', { parameters: req.params })
17
18 if (areValidationErrors(req, res)) return
19 if (!await doesVideoExist(req.params.id, res)) return
20
21 const video = res.locals.videoAll
22
23 const share = await VideoShareModel.load(req.params.actorId, video.id)
24 if (!share) {
25 return res.status(HttpStatusCode.NOT_FOUND_404)
26 .end()
27 }
28
29 res.locals.videoShare = share
30 return next()
31 }
32 ]
33
34 // ---------------------------------------------------------------------------
35
36 export {
37 videosShareValidator
38 }