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'
|
2021-07-16 10:42:24 +02:00
|
|
|
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
|
2021-06-28 17:30:59 +02:00
|
|
|
import { isIdValid } from '../../../helpers/custom-validators/misc'
|
2018-11-14 15:01:28 +01:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2021-06-28 17:30:59 +02:00
|
|
|
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
|
2018-11-14 15:01:28 +01:00
|
|
|
|
|
|
|
const videosShareValidator = [
|
2021-06-28 17:30:59 +02:00
|
|
|
isValidVideoIdParam('id'),
|
|
|
|
|
|
|
|
param('actorId')
|
|
|
|
.custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'),
|
2018-11-14 15:01:28 +01:00
|
|
|
|
|
|
|
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-08-15 11:53:26 +02:00
|
|
|
const video = res.locals.videoAll
|
2018-11-14 15:01:28 +01:00
|
|
|
|
|
|
|
const share = await VideoShareModel.load(req.params.actorId, video.id)
|
|
|
|
if (!share) {
|
2020-12-07 14:32:36 +01:00
|
|
|
return res.status(HttpStatusCode.NOT_FOUND_404)
|
2018-11-14 15:01:28 +01:00
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoShare = share
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
videosShareValidator
|
|
|
|
}
|