Bots settings (WIP).
This commit is contained in:
@ -4,8 +4,9 @@ import { getBaseRouterRoute } from '../helpers'
|
||||
import { ProsodyFilePaths } from './config/paths'
|
||||
import { ConfigLogExpiration, ProsodyConfigContent } from './config/content'
|
||||
import { getProsodyDomain } from './config/domain'
|
||||
import { getAPIKey } from '../apikey'
|
||||
import { getAPIKey, getExternalComponentKey } from '../apikey'
|
||||
import type { ProsodyLogLevel } from './config/content'
|
||||
import { parseConfigDemoBotUUIDs } from './config/bots'
|
||||
|
||||
async function getWorkingDir (options: RegisterServerOptions): Promise<string> {
|
||||
const peertubeHelpers = options.peertubeHelpers
|
||||
@ -63,6 +64,9 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
||||
}
|
||||
}
|
||||
|
||||
interface ProsodyConfigBots {
|
||||
demo?: string[] // if the demo bot is activated, here are the video UUIDS where it will be.
|
||||
}
|
||||
interface ProsodyConfig {
|
||||
content: string
|
||||
paths: ProsodyFilePaths
|
||||
@ -72,25 +76,40 @@ interface ProsodyConfig {
|
||||
roomType: 'video' | 'channel'
|
||||
logByDefault: boolean
|
||||
logExpiration: ConfigLogExpiration
|
||||
bots: ProsodyConfigBots
|
||||
}
|
||||
async function getProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
logger.debug('Calling getProsodyConfig')
|
||||
|
||||
const port = (await options.settingsManager.getSetting('prosody-port') as string) || '52800'
|
||||
let useExternalComponents = false
|
||||
const bots: ProsodyConfigBots = {}
|
||||
|
||||
const settings = await options.settingsManager.getSettings([
|
||||
'prosody-port',
|
||||
'prosody-muc-log-by-default',
|
||||
'prosody-muc-expiration',
|
||||
'prosody-c2s',
|
||||
'prosody-room-type',
|
||||
'prosody-peertube-uri',
|
||||
'prosody-c2s-port',
|
||||
'prosody-component-port',
|
||||
'chat-videos-list'
|
||||
])
|
||||
|
||||
const port = (settings['prosody-port'] as string) || '52800'
|
||||
if (!/^\d+$/.test(port)) {
|
||||
throw new Error('Invalid port')
|
||||
}
|
||||
const logByDefault = (await options.settingsManager.getSetting('prosody-muc-log-by-default') as boolean) ?? true
|
||||
const logExpirationSetting =
|
||||
(await options.settingsManager.getSetting('prosody-muc-expiration') as string) ?? DEFAULTLOGEXPIRATION
|
||||
const enableC2s = (await options.settingsManager.getSetting('prosody-c2s') as boolean) || false
|
||||
const logByDefault = (settings['prosody-muc-log-by-default'] as boolean) ?? true
|
||||
const logExpirationSetting = (settings['prosody-muc-expiration'] as string) ?? DEFAULTLOGEXPIRATION
|
||||
const enableC2s = (settings['prosody-c2s'] as boolean) || false
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
const paths = await getProsodyFilePaths(options)
|
||||
const roomType = (await options.settingsManager.getSetting('prosody-room-type')) === 'channel' ? 'channel' : 'video'
|
||||
const roomType = (settings['prosody-room-type']) === 'channel' ? 'channel' : 'video'
|
||||
|
||||
const apikey = await getAPIKey(options)
|
||||
let baseApiUrl = await options.settingsManager.getSetting('prosody-peertube-uri') as string
|
||||
let baseApiUrl = settings['prosody-peertube-uri'] as string
|
||||
if (baseApiUrl && !/^https?:\/\/[a-z0-9.-_]+(?::\d+)?$/.test(baseApiUrl)) {
|
||||
throw new Error('Invalid prosody-peertube-uri')
|
||||
}
|
||||
@ -109,7 +128,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
config.useMucHttpDefault(roomApiUrl)
|
||||
|
||||
if (enableC2s) {
|
||||
const c2sPort = (await options.settingsManager.getSetting('prosody-c2s-port') as string) || '52822'
|
||||
const c2sPort = (settings['prosody-c2s-port'] as string) || '52822'
|
||||
if (!/^\d+$/.test(c2sPort)) {
|
||||
throw new Error('Invalid c2s port')
|
||||
}
|
||||
@ -139,6 +158,22 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
logLevel = 'info'
|
||||
}
|
||||
config.setLog(logLevel)
|
||||
|
||||
const demoBotUUIDs = parseConfigDemoBotUUIDs((settings['chat-videos-list'] as string) || '')
|
||||
if (demoBotUUIDs?.length > 0) {
|
||||
useExternalComponents = true
|
||||
config.useDemoBot(await getExternalComponentKey(options, 'DEMOBOT'))
|
||||
bots.demo = demoBotUUIDs
|
||||
}
|
||||
|
||||
if (useExternalComponents) {
|
||||
const externalComponentsPort = (settings['prosody-component-port'] as string) || '53470'
|
||||
if (!/^\d+$/.test(externalComponentsPort)) {
|
||||
throw new Error('Invalid external components port')
|
||||
}
|
||||
config.useExternalComponents(externalComponentsPort)
|
||||
}
|
||||
|
||||
const content = config.write()
|
||||
|
||||
return {
|
||||
@ -149,7 +184,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
host: prosodyDomain,
|
||||
roomType,
|
||||
logByDefault,
|
||||
logExpiration
|
||||
logExpiration,
|
||||
bots
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user