VideoState
} from '@shared/models'
import { exists, isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc'
-import { isVideoNameValid } from '../../../helpers/custom-validators/videos'
+import { isVideoNameValid, isVideoPrivacyValid } from '../../../helpers/custom-validators/videos'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
import { logger } from '../../../helpers/logger'
import { CONFIG } from '../../../initializers/config'
.customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
+ body('replaySettings.privacy')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isVideoPrivacyValid),
+
body('permanentLive')
.optional()
.customSanitizer(toBooleanOrNull)
.customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
+ body('replaySettings.privacy')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isVideoPrivacyValid),
+
body('latencyMode')
.optional()
.customSanitizer(toIntOrNull)
})
}
+ if (!checkLiveSettingsReplayConsistency({ res, body })) return
+
if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) {
return res.fail({ message: 'Cannot update a live that has already started' })
}
return true
}
+
+function checkLiveSettingsReplayConsistency (options: {
+ res: express.Response
+ body: LiveVideoUpdate
+}) {
+ const { res, body } = options
+
+ // We now save replays of this live, so replay settings are mandatory
+ if (res.locals.videoLive.saveReplay !== true && body.saveReplay === true) {
+
+ if (!exists(body.replaySettings)) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: 'Replay settings are missing now the live replay is saved'
+ })
+ return false
+ }
+
+ if (!exists(body.replaySettings.privacy)) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: 'Privacy replay setting is missing now the live replay is saved'
+ })
+ return false
+ }
+ }
+
+ // Save replay was and is not enabled, so send an error the user if it specified replay settings
+ if ((!exists(body.saveReplay) && res.locals.videoLive.saveReplay === false) || body.saveReplay === false) {
+ if (exists(body.replaySettings)) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: 'Cannot save replay settings since live replay is not enabled'
+ })
+ return false
+ }
+ }
+
+ return true
+}