aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorWicklow <123956049+wickloww@users.noreply.github.com>2023-03-31 07:12:21 +0000
committerGitHub <noreply@github.com>2023-03-31 09:12:21 +0200
commit05a60d85997c108d39bcfb14f1ffd4c74f8b1e93 (patch)
tree5041a95ef945620a17f25ba934064b41f6bb00b7 /server/middlewares/validators
parentebd61437c1ec92bea9772924c7051cb00d71f778 (diff)
downloadPeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.gz
PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.tar.zst
PeerTube-05a60d85997c108d39bcfb14f1ffd4c74f8b1e93.zip
Feature/Add replay privacy (#5692)
* Add replay settings feature * Fix replay settings behaviour * Fix tests * Fix tests * Fix tests * Update openapi doc and fix tests * Add tests and fix code * Models correction * Add migration and update controller and middleware * Add check params tests * Fix video live middleware * Updated code based on review comments
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/videos/video-live.ts54
1 files changed, 53 insertions, 1 deletions
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index 328760dde..e80fe1593 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -17,7 +17,7 @@ import {
17 VideoState 17 VideoState
18} from '@shared/models' 18} from '@shared/models'
19import { exists, isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' 19import { exists, isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
20import { isVideoNameValid } from '../../../helpers/custom-validators/videos' 20import { isVideoNameValid, isVideoPrivacyValid } from '../../../helpers/custom-validators/videos'
21import { cleanUpReqFiles } from '../../../helpers/express-utils' 21import { cleanUpReqFiles } from '../../../helpers/express-utils'
22import { logger } from '../../../helpers/logger' 22import { logger } from '../../../helpers/logger'
23import { CONFIG } from '../../../initializers/config' 23import { CONFIG } from '../../../initializers/config'
@@ -66,6 +66,11 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
66 .customSanitizer(toBooleanOrNull) 66 .customSanitizer(toBooleanOrNull)
67 .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), 67 .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
68 68
69 body('replaySettings.privacy')
70 .optional()
71 .customSanitizer(toIntOrNull)
72 .custom(isVideoPrivacyValid),
73
69 body('permanentLive') 74 body('permanentLive')
70 .optional() 75 .optional()
71 .customSanitizer(toBooleanOrNull) 76 .customSanitizer(toBooleanOrNull)
@@ -153,6 +158,11 @@ const videoLiveUpdateValidator = [
153 .customSanitizer(toBooleanOrNull) 158 .customSanitizer(toBooleanOrNull)
154 .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'), 159 .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
155 160
161 body('replaySettings.privacy')
162 .optional()
163 .customSanitizer(toIntOrNull)
164 .custom(isVideoPrivacyValid),
165
156 body('latencyMode') 166 body('latencyMode')
157 .optional() 167 .optional()
158 .customSanitizer(toIntOrNull) 168 .customSanitizer(toIntOrNull)
@@ -177,6 +187,8 @@ const videoLiveUpdateValidator = [
177 }) 187 })
178 } 188 }
179 189
190 if (!checkLiveSettingsReplayConsistency({ res, body })) return
191
180 if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) { 192 if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) {
181 return res.fail({ message: 'Cannot update a live that has already started' }) 193 return res.fail({ message: 'Cannot update a live that has already started' })
182 } 194 }
@@ -272,3 +284,43 @@ function hasValidLatencyMode (body: LiveVideoUpdate | LiveVideoCreate) {
272 284
273 return true 285 return true
274} 286}
287
288function checkLiveSettingsReplayConsistency (options: {
289 res: express.Response
290 body: LiveVideoUpdate
291}) {
292 const { res, body } = options
293
294 // We now save replays of this live, so replay settings are mandatory
295 if (res.locals.videoLive.saveReplay !== true && body.saveReplay === true) {
296
297 if (!exists(body.replaySettings)) {
298 res.fail({
299 status: HttpStatusCode.BAD_REQUEST_400,
300 message: 'Replay settings are missing now the live replay is saved'
301 })
302 return false
303 }
304
305 if (!exists(body.replaySettings.privacy)) {
306 res.fail({
307 status: HttpStatusCode.BAD_REQUEST_400,
308 message: 'Privacy replay setting is missing now the live replay is saved'
309 })
310 return false
311 }
312 }
313
314 // Save replay was and is not enabled, so send an error the user if it specified replay settings
315 if ((!exists(body.saveReplay) && res.locals.videoLive.saveReplay === false) || body.saveReplay === false) {
316 if (exists(body.replaySettings)) {
317 res.fail({
318 status: HttpStatusCode.BAD_REQUEST_400,
319 message: 'Cannot save replay settings since live replay is not enabled'
320 })
321 return false
322 }
323 }
324
325 return true
326}