diff options
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r-- | server/middlewares/validators/videos/video-live.ts | 42 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param } from 'express-validator' |
3 | import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos' | 3 | import { checkUserCanManageVideo, doesVideoChannelOfAccountExist, doesVideoExist } from '@server/helpers/middlewares/videos' |
4 | import { UserRight } from '@shared/models' | 4 | import { VideoLiveModel } from '@server/models/video/video-live' |
5 | import { isIdOrUUIDValid, isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc' | 5 | import { UserRight, VideoState } from '@shared/models' |
6 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../../helpers/custom-validators/misc' | ||
6 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' | 7 | import { isVideoNameValid } from '../../../helpers/custom-validators/videos' |
7 | import { cleanUpReqFiles } from '../../../helpers/express-utils' | 8 | import { cleanUpReqFiles } from '../../../helpers/express-utils' |
8 | import { logger } from '../../../helpers/logger' | 9 | import { logger } from '../../../helpers/logger' |
9 | import { CONFIG } from '../../../initializers/config' | 10 | import { CONFIG } from '../../../initializers/config' |
10 | import { areValidationErrors } from '../utils' | 11 | import { areValidationErrors } from '../utils' |
11 | import { getCommonVideoEditAttributes } from './videos' | 12 | import { getCommonVideoEditAttributes } from './videos' |
12 | import { VideoLiveModel } from '@server/models/video/video-live' | ||
13 | 13 | ||
14 | const videoLiveGetValidator = [ | 14 | const 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 | ||
71 | const 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 | ||
63 | export { | 98 | export { |
64 | videoLiveAddValidator, | 99 | videoLiveAddValidator, |
100 | videoLiveUpdateValidator, | ||
65 | videoLiveGetValidator | 101 | videoLiveGetValidator |
66 | } | 102 | } |