aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts13
-rw-r--r--server/initializers/checker-after-init.ts14
-rw-r--r--server/initializers/config.ts7
-rw-r--r--server/middlewares/validators/config.ts5
-rw-r--r--server/tests/api/check-params/config.ts6
-rw-r--r--server/tests/api/server/config.ts16
6 files changed, 59 insertions, 2 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index edcb0b99e..41e5027b9 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -172,6 +172,13 @@ async function getConfig (req: express.Request, res: express.Response) {
172 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL 172 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
173 } 173 }
174 } 174 }
175 },
176
177 broadcastMessage: {
178 enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
179 message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
180 level: CONFIG.BROADCAST_MESSAGE.LEVEL,
181 dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
175 } 182 }
176 } 183 }
177 184
@@ -432,6 +439,12 @@ function customConfig (): CustomConfig {
432 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL 439 indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
433 } 440 }
434 } 441 }
442 },
443 broadcastMessage: {
444 enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
445 message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
446 level: CONFIG.BROADCAST_MESSAGE.LEVEL,
447 dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
435 } 448 }
436 } 449 }
437} 450}
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts
index f111be2ae..b5b854137 100644
--- a/server/initializers/checker-after-init.ts
+++ b/server/initializers/checker-after-init.ts
@@ -107,6 +107,10 @@ function checkConfig () {
107 } 107 }
108 } 108 }
109 109
110 if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) {
111 logger.warn('Redundancy directory should be different than the videos folder.')
112 }
113
110 // Transcoding 114 // Transcoding
111 if (CONFIG.TRANSCODING.ENABLED) { 115 if (CONFIG.TRANSCODING.ENABLED) {
112 if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) { 116 if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) {
@@ -114,8 +118,14 @@ function checkConfig () {
114 } 118 }
115 } 119 }
116 120
117 if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) { 121 // Broadcast message
118 logger.warn('Redundancy directory should be different than the videos folder.') 122 if (CONFIG.BROADCAST_MESSAGE.ENABLED) {
123 const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL
124 const available = [ 'info', 'warning', 'error' ]
125
126 if (available.includes(currentLevel) === false) {
127 return 'Broadcast message level should be ' + available.join(' or ') + ' instead of ' + currentLevel
128 }
119 } 129 }
120 130
121 return null 131 return null
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index 6932b41e1..e2920ce9e 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -6,6 +6,7 @@ import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-
6import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 6import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
7import * as bytes from 'bytes' 7import * as bytes from 'bytes'
8import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' 8import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
9import { BroadcastMessageLevel } from '@shared/models/server'
9 10
10// Use a variable to reload the configuration if we need 11// Use a variable to reload the configuration if we need
11let config: IConfig = require('config') 12let config: IConfig = require('config')
@@ -285,6 +286,12 @@ const CONFIG = {
285 }, 286 },
286 THEME: { 287 THEME: {
287 get DEFAULT () { return config.get<string>('theme.default') } 288 get DEFAULT () { return config.get<string>('theme.default') }
289 },
290 BROADCAST_MESSAGE: {
291 get ENABLED () { return config.get<boolean>('broadcast_message.enabled') },
292 get MESSAGE () { return config.get<string>('broadcast_message.message') },
293 get LEVEL () { return config.get<BroadcastMessageLevel>('broadcast_message.level') },
294 get DISMISSABLE () { return config.get<boolean>('broadcast_message.dismissable') }
288 } 295 }
289} 296}
290 297
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index dfa549e76..6905ac762 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -55,6 +55,11 @@ const customConfigUpdateValidator = [
55 55
56 body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), 56 body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'),
57 57
58 body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'),
59 body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'),
60 body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'),
61 body('broadcastMessage.dismissable').exists().withMessage('Should have a valid broadcast dismissable boolean'),
62
58 (req: express.Request, res: express.Response, next: express.NextFunction) => { 63 (req: express.Request, res: express.Response, next: express.NextFunction) => {
59 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) 64 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
60 65
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index f1a79806b..7c96fa762 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -133,6 +133,12 @@ describe('Test config API validators', function () {
133 indexUrl: 'https://index.example.com' 133 indexUrl: 'https://index.example.com'
134 } 134 }
135 } 135 }
136 },
137 broadcastMessage: {
138 enabled: true,
139 dismissable: true,
140 message: 'super message',
141 level: 'warning'
136 } 142 }
137 } 143 }
138 144
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 8580835d6..d18a93082 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -87,6 +87,11 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
87 expect(data.followings.instance.autoFollowBack.enabled).to.be.false 87 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
88 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false 88 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
89 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('') 89 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
90
91 expect(data.broadcastMessage.enabled).to.be.false
92 expect(data.broadcastMessage.level).to.equal('info')
93 expect(data.broadcastMessage.message).to.equal('')
94 expect(data.broadcastMessage.dismissable).to.be.false
90} 95}
91 96
92function checkUpdatedConfig (data: CustomConfig) { 97function checkUpdatedConfig (data: CustomConfig) {
@@ -155,6 +160,11 @@ function checkUpdatedConfig (data: CustomConfig) {
155 expect(data.followings.instance.autoFollowBack.enabled).to.be.true 160 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
156 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true 161 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
157 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com') 162 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
163
164 expect(data.broadcastMessage.enabled).to.be.true
165 expect(data.broadcastMessage.level).to.equal('error')
166 expect(data.broadcastMessage.message).to.equal('super bad message')
167 expect(data.broadcastMessage.dismissable).to.be.true
158} 168}
159 169
160describe('Test config', function () { 170describe('Test config', function () {
@@ -324,6 +334,12 @@ describe('Test config', function () {
324 indexUrl: 'https://updated.example.com' 334 indexUrl: 'https://updated.example.com'
325 } 335 }
326 } 336 }
337 },
338 broadcastMessage: {
339 enabled: true,
340 level: 'error',
341 message: 'super bad message',
342 dismissable: true
327 } 343 }
328 } 344 }
329 await updateCustomConfig(server.url, server.accessToken, newCustomConfig) 345 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)