aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-09-25 16:19:35 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commitfb7194043d0486ce0a6a40b2ffbdf32878c33a6f (patch)
tree6ed304a5d730a75da0a4460b3009df88684fa598 /server/middlewares/validators
parenta5cf76afa378aae81af2a9b0ce548e5d2582f832 (diff)
downloadPeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.tar.gz
PeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.tar.zst
PeerTube-fb7194043d0486ce0a6a40b2ffbdf32878c33a6f.zip
Check live duration and size
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/config.ts40
-rw-r--r--server/middlewares/validators/users.ts2
-rw-r--r--server/middlewares/validators/videos/videos.ts5
3 files changed, 38 insertions, 9 deletions
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index d3669f6be..41a6ae4f9 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' 3import { isIntOrNull } from '@server/helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger' 4import { isEmailEnabled } from '@server/initializers/config'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { areValidationErrors } from './utils'
7import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 6import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
8import { logger } from '../../helpers/logger'
8import { isThemeRegistered } from '../../lib/plugins/theme-utils' 9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
9import { isEmailEnabled } from '@server/initializers/config' 10import { areValidationErrors } from './utils'
10 11
11const customConfigUpdateValidator = [ 12const customConfigUpdateValidator = [
12 body('instance.name').exists().withMessage('Should have a valid instance name'), 13 body('instance.name').exists().withMessage('Should have a valid instance name'),
@@ -43,6 +44,7 @@ const customConfigUpdateValidator = [
43 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), 44 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
44 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), 45 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
45 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), 46 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
47 body('transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'),
46 48
47 body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), 49 body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'),
48 body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), 50 body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'),
@@ -60,6 +62,18 @@ const customConfigUpdateValidator = [
60 body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), 62 body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'),
61 body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), 63 body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'),
62 64
65 body('live.enabled').isBoolean().withMessage('Should have a valid live enabled boolean'),
66 body('live.allowReplay').isBoolean().withMessage('Should have a valid live allow replay boolean'),
67 body('live.maxDuration').custom(isIntOrNull).withMessage('Should have a valid live max duration'),
68 body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'),
69 body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'),
70 body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
71 body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
72 body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
73 body('live.transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
74 body('live.transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
75 body('live.transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'),
76
63 body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), 77 body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'),
64 body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), 78 body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'),
65 body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), 79 body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'),
@@ -71,8 +85,9 @@ const customConfigUpdateValidator = [
71 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) 85 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
72 86
73 if (areValidationErrors(req, res)) return 87 if (areValidationErrors(req, res)) return
74 if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return 88 if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return
75 if (!checkInvalidTranscodingConfig(req.body as CustomConfig, res)) return 89 if (!checkInvalidTranscodingConfig(req.body, res)) return
90 if (!checkInvalidLiveConfig(req.body, res)) return
76 91
77 return next() 92 return next()
78 } 93 }
@@ -109,3 +124,16 @@ function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express
109 124
110 return true 125 return true
111} 126}
127
128function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) {
129 if (customConfig.live.enabled === false) return true
130
131 if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) {
132 res.status(400)
133 .send({ error: 'You cannot allow live replay if transcoding is not enabled' })
134 .end()
135 return false
136 }
137
138 return true
139}
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 76ecff884..452c7fb93 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -497,7 +497,7 @@ export {
497 497
498function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) { 498function checkUserIdExist (idArg: number | string, res: express.Response, withStats = false) {
499 const id = parseInt(idArg + '', 10) 499 const id = parseInt(idArg + '', 10)
500 return checkUserExist(() => UserModel.loadById(id, withStats), res) 500 return checkUserExist(() => UserModel.loadByIdWithChannels(id, withStats), res)
501} 501}
502 502
503function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) { 503function checkUserEmailExist (email: string, res: express.Response, abortResponse = true) {
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index b022b2c23..ff90e347a 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -1,5 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { isAbleToUploadVideo } from '@server/lib/user'
3import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
4import { MVideoFullLight } from '@server/types/models' 5import { MVideoFullLight } from '@server/types/models'
5import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 6import { ServerErrorCode, UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
@@ -73,7 +74,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
73 74
74 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 75 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
75 76
76 if (await user.isAbleToUploadVideo(videoFile) === false) { 77 if (await isAbleToUploadVideo(user.id, videoFile.size) === false) {
77 res.status(403) 78 res.status(403)
78 .json({ error: 'The user video quota is exceeded with this video.' }) 79 .json({ error: 'The user video quota is exceeded with this video.' })
79 80
@@ -291,7 +292,7 @@ const videosAcceptChangeOwnershipValidator = [
291 292
292 const user = res.locals.oauth.token.User 293 const user = res.locals.oauth.token.User
293 const videoChangeOwnership = res.locals.videoChangeOwnership 294 const videoChangeOwnership = res.locals.videoChangeOwnership
294 const isAble = await user.isAbleToUploadVideo(videoChangeOwnership.Video.getMaxQualityFile()) 295 const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size)
295 if (isAble === false) { 296 if (isAble === false) {
296 res.status(403) 297 res.status(403)
297 .json({ error: 'The user video quota is exceeded with this video.' }) 298 .json({ error: 'The user video quota is exceeded with this video.' })