2018-11-14 09:01:28 -05:00
|
|
|
import * as express from 'express'
|
2019-07-25 10:23:44 -04:00
|
|
|
import { param } from 'express-validator'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2018-11-14 09:01:28 -05:00
|
|
|
import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
2021-06-03 11:33:44 -04:00
|
|
|
import { areValidationErrors, doesVideoExist } from '../shared'
|
2018-11-14 09:01:28 -05: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 04:26:50 -04:00
|
|
|
if (!await doesVideoExist(req.params.id, res)) return
|
2018-11-14 09:01:28 -05:00
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
const video = res.locals.videoAll
|
2018-11-14 09:01:28 -05:00
|
|
|
|
|
|
|
const share = await VideoShareModel.load(req.params.actorId, video.id)
|
|
|
|
if (!share) {
|
2020-12-07 08:32:36 -05:00
|
|
|
return res.status(HttpStatusCode.NOT_FOUND_404)
|
2018-11-14 09:01:28 -05:00
|
|
|
.end()
|
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.videoShare = share
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
videosShareValidator
|
|
|
|
}
|