Support broadcast messages

This commit is contained in:
Chocobozzz
2020-05-28 11:15:38 +02:00
committed by Chocobozzz
parent 8adf0a767f
commit 72c33e716f
20 changed files with 281 additions and 19 deletions

View File

@@ -172,6 +172,13 @@ async function getConfig (req: express.Request, res: express.Response) {
indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
}
}
},
broadcastMessage: {
enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
level: CONFIG.BROADCAST_MESSAGE.LEVEL,
dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
}
}
@@ -432,6 +439,12 @@ function customConfig (): CustomConfig {
indexUrl: CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_INDEX.INDEX_URL
}
}
},
broadcastMessage: {
enabled: CONFIG.BROADCAST_MESSAGE.ENABLED,
message: CONFIG.BROADCAST_MESSAGE.MESSAGE,
level: CONFIG.BROADCAST_MESSAGE.LEVEL,
dismissable: CONFIG.BROADCAST_MESSAGE.DISMISSABLE
}
}
}

View File

@@ -107,6 +107,10 @@ function checkConfig () {
}
}
if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) {
logger.warn('Redundancy directory should be different than the videos folder.')
}
// Transcoding
if (CONFIG.TRANSCODING.ENABLED) {
if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) {
@@ -114,8 +118,14 @@ function checkConfig () {
}
}
if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) {
logger.warn('Redundancy directory should be different than the videos folder.')
// Broadcast message
if (CONFIG.BROADCAST_MESSAGE.ENABLED) {
const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL
const available = [ 'info', 'warning', 'error' ]
if (available.includes(currentLevel) === false) {
return 'Broadcast message level should be ' + available.join(' or ') + ' instead of ' + currentLevel
}
}
return null

View File

@@ -6,6 +6,7 @@ import { buildPath, parseBytes, parseDurationToMs, root } from '../helpers/core-
import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
import * as bytes from 'bytes'
import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type'
import { BroadcastMessageLevel } from '@shared/models/server'
// Use a variable to reload the configuration if we need
let config: IConfig = require('config')
@@ -285,6 +286,12 @@ const CONFIG = {
},
THEME: {
get DEFAULT () { return config.get<string>('theme.default') }
},
BROADCAST_MESSAGE: {
get ENABLED () { return config.get<boolean>('broadcast_message.enabled') },
get MESSAGE () { return config.get<string>('broadcast_message.message') },
get LEVEL () { return config.get<BroadcastMessageLevel>('broadcast_message.level') },
get DISMISSABLE () { return config.get<boolean>('broadcast_message.dismissable') }
}
}

View File

@@ -55,6 +55,11 @@ const customConfigUpdateValidator = [
body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'),
body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'),
body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'),
body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'),
body('broadcastMessage.dismissable').exists().withMessage('Should have a valid broadcast dismissable boolean'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })

View File

@@ -133,6 +133,12 @@ describe('Test config API validators', function () {
indexUrl: 'https://index.example.com'
}
}
},
broadcastMessage: {
enabled: true,
dismissable: true,
message: 'super message',
level: 'warning'
}
}

View File

@@ -87,6 +87,11 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
expect(data.followings.instance.autoFollowBack.enabled).to.be.false
expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
expect(data.broadcastMessage.enabled).to.be.false
expect(data.broadcastMessage.level).to.equal('info')
expect(data.broadcastMessage.message).to.equal('')
expect(data.broadcastMessage.dismissable).to.be.false
}
function checkUpdatedConfig (data: CustomConfig) {
@@ -155,6 +160,11 @@ function checkUpdatedConfig (data: CustomConfig) {
expect(data.followings.instance.autoFollowBack.enabled).to.be.true
expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
expect(data.broadcastMessage.enabled).to.be.true
expect(data.broadcastMessage.level).to.equal('error')
expect(data.broadcastMessage.message).to.equal('super bad message')
expect(data.broadcastMessage.dismissable).to.be.true
}
describe('Test config', function () {
@@ -324,6 +334,12 @@ describe('Test config', function () {
indexUrl: 'https://updated.example.com'
}
}
},
broadcastMessage: {
enabled: true,
level: 'error',
message: 'super bad message',
dismissable: true
}
}
await updateCustomConfig(server.url, server.accessToken, newCustomConfig)