]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-shares.ts
replace numbers with typed http status codes (#3409)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-shares.ts
CommitLineData
5c6d985f 1import * as express from 'express'
c8861d5d 2import { param } from 'express-validator'
5c6d985f 3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5c6d985f
C
4import { logger } from '../../../helpers/logger'
5import { VideoShareModel } from '../../../models/video/video-share'
6import { areValidationErrors } from '../utils'
3e753302 7import { doesVideoExist } from '../../../helpers/middlewares'
2d53be02 8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
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
453e83ea 20 const video = res.locals.videoAll
5c6d985f
C
21
22 const share = await VideoShareModel.load(req.params.actorId, video.id)
23 if (!share) {
2d53be02 24 return res.status(HttpStatusCode.NOT_FOUND_404)
5c6d985f
C
25 .end()
26 }
27
28 res.locals.videoShare = share
29 return next()
30 }
31]
32
33// ---------------------------------------------------------------------------
34
35export {
36 videosShareValidator
37}