+const videoLiveUpdateValidator = [
+ body('saveReplay')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body })
+
+ if (areValidationErrors(req, res)) return
+
+ if (req.body.permanentLive && req.body.saveReplay) {
+ return res.status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Cannot set this live as permanent while saving its replay' })
+ }
+
+ if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) {
+ return res.status(HttpStatusCode.FORBIDDEN_403)
+ .json({ error: 'Saving live replay is not allowed instance' })
+ }
+
+ if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) {
+ return res.status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Cannot update a live that has already started' })
+ }
+
+ // Check the user can manage the live
+ const user = res.locals.oauth.token.User
+ if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res)) return
+
+ return next()
+ }
+]
+