aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-06 13:59:50 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commit3cabf3532b9118a19311f14ca3e171d12d554a2f (patch)
tree46072616df4623d91c87f648e4033b3f1d05d404 /server/middlewares/validators
parentc8f3cfeba7acc2ab9c5f03161d22856202a49326 (diff)
downloadPeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.tar.gz
PeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.tar.zst
PeerTube-3cabf3532b9118a19311f14ca3e171d12d554a2f.zip
Add live server hooks
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/videos/video-live.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index cbc48fe93..ff92db910 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -11,6 +11,8 @@ import { CONFIG } from '../../../initializers/config'
11import { areValidationErrors } from '../utils' 11import { areValidationErrors } from '../utils'
12import { getCommonVideoEditAttributes } from './videos' 12import { getCommonVideoEditAttributes } from './videos'
13import { VideoModel } from '@server/models/video/video' 13import { VideoModel } from '@server/models/video/video'
14import { Hooks } from '@server/lib/plugins/hooks'
15import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
14 16
15const videoLiveGetValidator = [ 17const videoLiveGetValidator = [
16 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 18 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@@ -97,6 +99,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
97 } 99 }
98 } 100 }
99 101
102 if (!await isLiveVideoAccepted(req, res)) return cleanUpReqFiles(req)
103
100 return next() 104 return next()
101 } 105 }
102]) 106])
@@ -137,3 +141,29 @@ export {
137 videoLiveUpdateValidator, 141 videoLiveUpdateValidator,
138 videoLiveGetValidator 142 videoLiveGetValidator
139} 143}
144
145// ---------------------------------------------------------------------------
146
147async function isLiveVideoAccepted (req: express.Request, res: express.Response) {
148 // Check we accept this video
149 const acceptParameters = {
150 liveVideoBody: req.body,
151 user: res.locals.oauth.token.User
152 }
153 const acceptedResult = await Hooks.wrapFun(
154 isLocalLiveVideoAccepted,
155 acceptParameters,
156 'filter:api.live-video.create.accept.result'
157 )
158
159 if (!acceptedResult || acceptedResult.accepted !== true) {
160 logger.info('Refused local live video.', { acceptedResult, acceptParameters })
161
162 res.status(403)
163 .json({ error: acceptedResult.errorMessage || 'Refused local live video' })
164
165 return false
166 }
167
168 return true
169}