PeerTube/server/middlewares/validators/videos/video-shares.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-11-14 15:01:28 +01:00
import * as express from 'express'
2019-07-25 16:23:44 +02:00
import { param } from 'express-validator'
2018-11-14 15:01:28 +01:00
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
import { logger } from '../../../helpers/logger'
import { VideoShareModel } from '../../../models/video/video-share'
import { areValidationErrors } from '../utils'
2019-07-23 10:40:39 +02:00
import { doesVideoExist } from '../../../helpers/middlewares'
2018-11-14 15:01:28 +01:00
const videosShareValidator = [
param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
param('actorId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoShare parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
2019-03-19 09:26:50 +01:00
if (!await doesVideoExist(req.params.id, res)) return
2018-11-14 15:01:28 +01:00
2019-03-19 10:35:15 +01:00
const video = res.locals.video
2018-11-14 15:01:28 +01:00
const share = await VideoShareModel.load(req.params.actorId, video.id)
if (!share) {
return res.status(404)
.end()
}
res.locals.videoShare = share
return next()
}
]
// ---------------------------------------------------------------------------
export {
videosShareValidator
}