aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorFlorian CUNY <poslovitch@bentobox.world>2021-10-26 16:42:10 +0200
committerGitHub <noreply@github.com>2021-10-26 16:42:10 +0200
commit754b6f5f41bdc40aaaeefdb3c351666c305abe20 (patch)
treed36c8081f3137f1e2c9763879f71d41aa9a3efc1 /server
parent615836dbd4f48fc563551446529fa9d3b14dc329 (diff)
downloadPeerTube-754b6f5f41bdc40aaaeefdb3c351666c305abe20.tar.gz
PeerTube-754b6f5f41bdc40aaaeefdb3c351666c305abe20.tar.zst
PeerTube-754b6f5f41bdc40aaaeefdb3c351666c305abe20.zip
Made the video channels limit (per user) server-wide configurable (#4491)
* Made the video channels limit (per user) server-wide configurable Implements https://github.com/Chocobozzz/PeerTube/issues/3092 Also added a "quota bar" in the account's settings page * Fixed lint errors * Another pass at fixing lint errors * Applied code suggestions * Removed 'video channels quota'
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts3
-rw-r--r--server/initializers/checker-before-init.ts1
-rw-r--r--server/initializers/config.ts3
-rw-r--r--server/initializers/constants.ts5
-rw-r--r--server/lib/server-config-manager.ts3
-rw-r--r--server/middlewares/validators/config.ts2
-rw-r--r--server/middlewares/validators/videos/video-channels.ts6
-rw-r--r--server/models/video/video-channel.ts5
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/server/config.ts7
10 files changed, 28 insertions, 10 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 5ea1f67c9..8965cacc9 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -196,6 +196,9 @@ function customConfig (): CustomConfig {
196 videoQuota: CONFIG.USER.VIDEO_QUOTA, 196 videoQuota: CONFIG.USER.VIDEO_QUOTA,
197 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY 197 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
198 }, 198 },
199 videoChannels: {
200 maxPerUser: CONFIG.VIDEO_CHANNELS.MAX_PER_USER
201 },
199 transcoding: { 202 transcoding: {
200 enabled: CONFIG.TRANSCODING.ENABLED, 203 enabled: CONFIG.TRANSCODING.ENABLED,
201 allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS, 204 allowAdditionalExtensions: CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS,
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 16dc137c0..72acdd422 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -19,6 +19,7 @@ function checkMissedConfig () {
19 'storage.redundancy', 'storage.tmp', 'storage.streaming_playlists', 'storage.plugins', 19 'storage.redundancy', 'storage.tmp', 'storage.streaming_playlists', 'storage.plugins',
20 'log.level', 20 'log.level',
21 'user.video_quota', 'user.video_quota_daily', 21 'user.video_quota', 'user.video_quota_daily',
22 'video_channels.max_per_user',
22 'csp.enabled', 'csp.report_only', 'csp.report_uri', 23 'csp.enabled', 'csp.report_only', 'csp.report_uri',
23 'security.frameguard.enabled', 24 'security.frameguard.enabled',
24 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled', 25 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled',
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index cab60a61f..8375bf430 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -233,6 +233,9 @@ const CONFIG = {
233 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) }, 233 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
234 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) } 234 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
235 }, 235 },
236 VIDEO_CHANNELS: {
237 get MAX_PER_USER () { return config.get<number>('video_channels.max_per_user') }
238 },
236 TRANSCODING: { 239 TRANSCODING: {
237 get ENABLED () { return config.get<boolean>('transcoding.enabled') }, 240 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
238 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') }, 241 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index f6c19dab4..3781f9508 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -512,10 +512,6 @@ const OVERVIEWS = {
512 } 512 }
513} 513}
514 514
515const VIDEO_CHANNELS = {
516 MAX_PER_USER: 20
517}
518
519// --------------------------------------------------------------------------- 515// ---------------------------------------------------------------------------
520 516
521const SERVER_ACTOR_NAME = 'peertube' 517const SERVER_ACTOR_NAME = 'peertube'
@@ -897,7 +893,6 @@ export {
897 VIDEO_TRANSCODING_FPS, 893 VIDEO_TRANSCODING_FPS,
898 FFMPEG_NICE, 894 FFMPEG_NICE,
899 ABUSE_STATES, 895 ABUSE_STATES,
900 VIDEO_CHANNELS,
901 LRU_CACHE, 896 LRU_CACHE,
902 REQUEST_TIMEOUT, 897 REQUEST_TIMEOUT,
903 USER_PASSWORD_RESET_LIFETIME, 898 USER_PASSWORD_RESET_LIFETIME,
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts
index b78251e8c..bdf6492f9 100644
--- a/server/lib/server-config-manager.ts
+++ b/server/lib/server-config-manager.ts
@@ -184,6 +184,9 @@ class ServerConfigManager {
184 videoQuota: CONFIG.USER.VIDEO_QUOTA, 184 videoQuota: CONFIG.USER.VIDEO_QUOTA,
185 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY 185 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
186 }, 186 },
187 videoChannels: {
188 maxPerUser: CONFIG.VIDEO_CHANNELS.MAX_PER_USER
189 },
187 trending: { 190 trending: {
188 videos: { 191 videos: {
189 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS, 192 intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS,
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index f0385ab44..da52b14ba 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -38,6 +38,8 @@ const customConfigUpdateValidator = [
38 body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'), 38 body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'),
39 body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'), 39 body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'),
40 40
41 body('videoChannels.maxPerUser').isInt().withMessage("Should have a valid maximum amount of video channels per user"),
42
41 body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'), 43 body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'),
42 body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'), 44 body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'),
43 body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'), 45 body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'),
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index c4705192a..edce48c7f 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -1,6 +1,5 @@
1import express from 'express' 1import express from 'express'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { VIDEO_CHANNELS } from '@server/initializers/constants'
4import { MChannelAccountDefault, MUser } from '@server/types/models' 3import { MChannelAccountDefault, MUser } from '@server/types/models'
5import { UserRight } from '../../../../shared' 4import { UserRight } from '../../../../shared'
6import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' 5import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
@@ -15,6 +14,7 @@ import { logger } from '../../../helpers/logger'
15import { ActorModel } from '../../../models/actor/actor' 14import { ActorModel } from '../../../models/actor/actor'
16import { VideoChannelModel } from '../../../models/video/video-channel' 15import { VideoChannelModel } from '../../../models/video/video-channel'
17import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared' 16import { areValidationErrors, doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } from '../shared'
17import { CONFIG } from '@server/initializers/config'
18 18
19const videoChannelsAddValidator = [ 19const videoChannelsAddValidator = [
20 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), 20 body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'),
@@ -37,8 +37,8 @@ const videoChannelsAddValidator = [
37 } 37 }
38 38
39 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) 39 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id)
40 if (count >= VIDEO_CHANNELS.MAX_PER_USER) { 40 if (count >= CONFIG.VIDEO_CHANNELS.MAX_PER_USER) {
41 res.fail({ message: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) 41 res.fail({ message: `You cannot create more than ${CONFIG.VIDEO_CHANNELS.MAX_PER_USER} channels` })
42 return false 42 return false
43 } 43 }
44 44
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 4151dc5b5..b652d8531 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -26,7 +26,7 @@ import {
26 isVideoChannelDisplayNameValid, 26 isVideoChannelDisplayNameValid,
27 isVideoChannelSupportValid 27 isVideoChannelSupportValid
28} from '../../helpers/custom-validators/video-channels' 28} from '../../helpers/custom-validators/video-channels'
29import { CONSTRAINTS_FIELDS, VIDEO_CHANNELS, WEBSERVER } from '../../initializers/constants' 29import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
30import { sendDeleteActor } from '../../lib/activitypub/send' 30import { sendDeleteActor } from '../../lib/activitypub/send'
31import { 31import {
32 MChannelActor, 32 MChannelActor,
@@ -44,6 +44,7 @@ import { setAsUpdated } from '../shared'
44import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' 44import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
45import { VideoModel } from './video' 45import { VideoModel } from './video'
46import { VideoPlaylistModel } from './video-playlist' 46import { VideoPlaylistModel } from './video-playlist'
47import { CONFIG } from '@server/initializers/config'
47 48
48export enum ScopeNames { 49export enum ScopeNames {
49 FOR_API = 'FOR_API', 50 FOR_API = 'FOR_API',
@@ -584,7 +585,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
584 585
585 static listAllByAccount (accountId: number) { 586 static listAllByAccount (accountId: number) {
586 const query = { 587 const query = {
587 limit: VIDEO_CHANNELS.MAX_PER_USER, 588 limit: CONFIG.VIDEO_CHANNELS.MAX_PER_USER,
588 include: [ 589 include: [
589 { 590 {
590 attributes: [], 591 attributes: [],
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 87cb2287e..273b1f718 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -81,6 +81,9 @@ describe('Test config API validators', function () {
81 videoQuota: 5242881, 81 videoQuota: 5242881,
82 videoQuotaDaily: 318742 82 videoQuotaDaily: 318742
83 }, 83 },
84 videoChannels: {
85 maxPerUser: 20
86 },
84 transcoding: { 87 transcoding: {
85 enabled: true, 88 enabled: true,
86 allowAdditionalExtensions: true, 89 allowAdditionalExtensions: true,
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 1d996d454..8d5b3ac7f 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -58,6 +58,8 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
58 expect(data.user.videoQuota).to.equal(5242880) 58 expect(data.user.videoQuota).to.equal(5242880)
59 expect(data.user.videoQuotaDaily).to.equal(-1) 59 expect(data.user.videoQuotaDaily).to.equal(-1)
60 60
61 expect(data.videoChannels.maxPerUser).to.equal(20)
62
61 expect(data.transcoding.enabled).to.be.false 63 expect(data.transcoding.enabled).to.be.false
62 expect(data.transcoding.allowAdditionalExtensions).to.be.false 64 expect(data.transcoding.allowAdditionalExtensions).to.be.false
63 expect(data.transcoding.allowAudioFiles).to.be.false 65 expect(data.transcoding.allowAudioFiles).to.be.false
@@ -153,6 +155,8 @@ function checkUpdatedConfig (data: CustomConfig) {
153 expect(data.user.videoQuota).to.equal(5242881) 155 expect(data.user.videoQuota).to.equal(5242881)
154 expect(data.user.videoQuotaDaily).to.equal(318742) 156 expect(data.user.videoQuotaDaily).to.equal(318742)
155 157
158 expect(data.videoChannels.maxPerUser).to.equal(24)
159
156 expect(data.transcoding.enabled).to.be.true 160 expect(data.transcoding.enabled).to.be.true
157 expect(data.transcoding.threads).to.equal(1) 161 expect(data.transcoding.threads).to.equal(1)
158 expect(data.transcoding.concurrency).to.equal(3) 162 expect(data.transcoding.concurrency).to.equal(3)
@@ -265,6 +269,9 @@ const newCustomConfig: CustomConfig = {
265 videoQuota: 5242881, 269 videoQuota: 5242881,
266 videoQuotaDaily: 318742 270 videoQuotaDaily: 318742
267 }, 271 },
272 videoChannels: {
273 maxPerUser: 24
274 },
268 transcoding: { 275 transcoding: {
269 enabled: true, 276 enabled: true,
270 allowAdditionalExtensions: true, 277 allowAdditionalExtensions: true,