]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-shares.ts
Fix pt_PT and el_GR translations
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-shares.ts
CommitLineData
5c6d985f
C
1import * as express from 'express'
2import 'express-validator'
3import { param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5c6d985f
C
5import { logger } from '../../../helpers/logger'
6import { VideoShareModel } from '../../../models/video/video-share'
7import { areValidationErrors } from '../utils'
3e753302 8import { doesVideoExist } from '../../../helpers/middlewares'
5c6d985f
C
9
10const 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
dae86118 20 const video = res.locals.video
5c6d985f
C
21
22 const share = await VideoShareModel.load(req.params.actorId, video.id)
23 if (!share) {
24 return res.status(404)
25 .end()
26 }
27
28 res.locals.videoShare = share
29 return next()
30 }
31]
32
33// ---------------------------------------------------------------------------
34
35export {
36 videosShareValidator
37}