aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-10-26 16:44:23 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commitb5b687550d8ef8beafdf706e45d6556fb5f4c876 (patch)
tree232412d463c78af1f7ab5797db5aecf1096d08da /server/middlewares/validators
parentef680f68351ec10ab73a1131570a6d14ce14c195 (diff)
downloadPeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.gz
PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.tar.zst
PeerTube-b5b687550d8ef8beafdf706e45d6556fb5f4c876.zip
Add ability to save live replay
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/videos/video-live.ts42
1 files changed, 39 insertions, 3 deletions
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index a4c364976..ab57e67bf 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -1,15 +1,15 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator' 2import { body, param } from 'express-validator'
3import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos' 3import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos'
4import { UserRight } from '@shared/models' 4import { VideoLiveModel } from '@server/models/video/video-live'
5import { isIdOrUUIDValid, isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' 5import { UserRight, VideoState } from '@shared/models'
6import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
6import { isVideoNameValid } from '../../../helpers/custom-validators/videos' 7import { isVideoNameValid } from '../../../helpers/custom-validators/videos'
7import { cleanUpReqFiles } from '../../../helpers/express-utils' 8import { cleanUpReqFiles } from '../../../helpers/express-utils'
8import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
9import { CONFIG } from '../../../initializers/config' 10import { CONFIG } from '../../../initializers/config'
10import { areValidationErrors } from '../utils' 11import { areValidationErrors } from '../utils'
11import { getCommonVideoEditAttributes } from './videos' 12import { getCommonVideoEditAttributes } from './videos'
12import { VideoLiveModel } from '@server/models/video/video-live'
13 13
14const videoLiveGetValidator = [ 14const videoLiveGetValidator = [
15 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 15 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@@ -41,6 +41,11 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
41 body('name') 41 body('name')
42 .custom(isVideoNameValid).withMessage('Should have a valid name'), 42 .custom(isVideoNameValid).withMessage('Should have a valid name'),
43 43
44 body('saveReplay')
45 .optional()
46 .customSanitizer(toBooleanOrNull)
47 .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'),
48
44 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 49 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
45 logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body }) 50 logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body })
46 51
@@ -49,6 +54,11 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
49 .json({ error: 'Live is not enabled on this instance' }) 54 .json({ error: 'Live is not enabled on this instance' })
50 } 55 }
51 56
57 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) {
58 return res.status(403)
59 .json({ error: 'Saving live replay is not allowed instance' })
60 }
61
52 if (areValidationErrors(req, res)) return cleanUpReqFiles(req) 62 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
53 63
54 const user = res.locals.oauth.token.User 64 const user = res.locals.oauth.token.User
@@ -58,9 +68,35 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
58 } 68 }
59]) 69])
60 70
71const videoLiveUpdateValidator = [
72 body('saveReplay')
73 .optional()
74 .customSanitizer(toBooleanOrNull)
75 .custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'),
76
77 (req: express.Request, res: express.Response, next: express.NextFunction) => {
78 logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body })
79
80 if (areValidationErrors(req, res)) return
81
82 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) {
83 return res.status(403)
84 .json({ error: 'Saving live replay is not allowed instance' })
85 }
86
87 if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) {
88 return res.status(400)
89 .json({ error: 'Cannot update a live that has already started' })
90 }
91
92 return next()
93 }
94]
95
61// --------------------------------------------------------------------------- 96// ---------------------------------------------------------------------------
62 97
63export { 98export {
64 videoLiveAddValidator, 99 videoLiveAddValidator,
100 videoLiveUpdateValidator,
65 videoLiveGetValidator 101 videoLiveGetValidator
66} 102}