Renaming 'moderation' pages to 'configuration'.

This commit is contained in:
John Livingston 2023-09-06 15:23:39 +02:00
parent 85e7598c1f
commit 5373fb1570
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
13 changed files with 132 additions and 130 deletions

View File

@ -34,13 +34,13 @@ declare const LOC_CONNECT_USING_XMPP_HELP: string
declare const LOC_SAVE: string
declare const LOC_CANCEL: string
declare const LOC_SUCCESSFULLY_SAVED: string
declare const LOC_MENU_MODERATION_LABEL: string
declare const LOC_LIVECHAT_MODERATION_TITLE: string
declare const LOC_LIVECHAT_MODERATION_DESC: string
declare const LOC_LIVECHAT_MODERATION_PLEASE_SELECT: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_TITLE: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_DESC: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string
declare const LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL: string
declare const LOC_MENU_CONFIGURATION_LABEL: string
declare const LOC_LIVECHAT_CONFIGURATION_TITLE: string
declare const LOC_LIVECHAT_CONFIGURATION_DESC: string
declare const LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL: string

View File

@ -1,6 +1,6 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types'
import { registerModeration } from './common/moderation/register'
import { registerConfiguration } from './common/configuration/register'
async function register (clientOptions: RegisterClientOptions): Promise<void> {
const { peertubeHelpers, registerHook, registerVideoField } = clientOptions
@ -52,7 +52,7 @@ async function register (clientOptions: RegisterClientOptions): Promise<void> {
registerVideoField(webchatFieldOptions, { type: 'update' })
registerVideoField(webchatFieldOptions, { type: 'go-live' })
await registerModeration(clientOptions)
await registerConfiguration(clientOptions)
}
export {

View File

@ -1,23 +1,23 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { ChannelModerationOptions } from 'shared/lib/types'
import type { ChannelConfigurationOptions } from 'shared/lib/types'
import { getBaseRoute } from '../../../videowatch/uri'
/**
* Adds the front-end logic on the generated html for the channel moderation options.
* Adds the front-end logic on the generated html for the channel configuration options.
* @param clientOptions Peertube client options
* @param rootEl The root element in which the template was rendered
*/
async function vivifyModerationChannel (
async function vivifyConfigurationChannel (
clientOptions: RegisterClientOptions,
rootEl: HTMLElement,
channelId: string
): Promise<void> {
const form = rootEl.querySelector('form[livechat-moderation-channel-options]') as HTMLFormElement
const form = rootEl.querySelector('form[livechat-configuration-channel-options]') as HTMLFormElement
if (!form) { return }
const labelSaved = await clientOptions.peertubeHelpers.translate(LOC_SUCCESSFULLY_SAVED)
const labelError = await clientOptions.peertubeHelpers.translate(LOC_ERROR)
const enableBotCB = form.querySelector('input[name=bot]') as HTMLInputElement
const botEnabledEl = form.querySelector('[livechat-moderation-channel-options-bot-enabled]') as HTMLElement
const botEnabledEl = form.querySelector('[livechat-configuration-channel-options-bot-enabled]') as HTMLElement
const refresh: Function = () => {
botEnabledEl.style.display = enableBotCB.checked ? 'initial' : 'none'
@ -25,7 +25,7 @@ async function vivifyModerationChannel (
const submitForm: Function = async () => {
const data = new FormData(form)
const channelModerationOptions: ChannelModerationOptions = {
const channelConfigurationOptions: ChannelConfigurationOptions = {
bot: data.get('bot') === '1',
bannedJIDs: (data.get('banned_jids')?.toString() ?? '').split(/\r?\n|\r|\n/g),
forbiddenWords: (data.get('forbidden_words')?.toString() ?? '').split(/\r?\n|\r|\n/g)
@ -35,16 +35,16 @@ async function vivifyModerationChannel (
headers['content-type'] = 'application/json;charset=UTF-8'
const response = await fetch(
getBaseRoute(clientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId),
getBaseRoute(clientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId),
{
method: 'POST',
headers,
body: JSON.stringify(channelModerationOptions)
body: JSON.stringify(channelConfigurationOptions)
}
)
if (!response.ok) {
throw new Error('Failed to save moderation options.')
throw new Error('Failed to save configuration options.')
}
}
const toggleSubmit: Function = (disabled: boolean) => {
@ -80,5 +80,5 @@ async function vivifyModerationChannel (
}
export {
vivifyModerationChannel
vivifyConfigurationChannel
}

View File

@ -1,42 +1,42 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { renderModerationHome } from './templates/home'
import { renderModerationChannel } from './templates/channel'
import { vivifyModerationChannel } from './logic/channel'
import { renderConfigurationHome } from './templates/home'
import { renderConfigurationChannel } from './templates/channel'
import { vivifyConfigurationChannel } from './logic/channel'
/**
* Registers stuff related to the moderation settings.
* Registers stuff related to the user's configuration pages.
* @param clientOptions Peertube client options
*/
async function registerModeration (clientOptions: RegisterClientOptions): Promise<void> {
async function registerConfiguration (clientOptions: RegisterClientOptions): Promise<void> {
const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions
registerClientRoute({
route: 'livechat/moderation',
route: 'livechat/configuration',
onMount: async ({ rootEl }) => {
rootEl.innerHTML = await renderModerationHome(clientOptions)
rootEl.innerHTML = await renderConfigurationHome(clientOptions)
}
})
registerClientRoute({
route: 'livechat/moderation/channel',
route: 'livechat/configuration/channel',
onMount: async ({ rootEl }) => {
const urlParams = new URLSearchParams(window.location.search)
const channelId = urlParams.get('channelId') ?? ''
const html = await renderModerationChannel(clientOptions, channelId)
const html = await renderConfigurationChannel(clientOptions, channelId)
if (!html) {
// renderModerationChannel has already used the notifier to display an error
// renderConfigurationChannel has already used the notifier to display an error
rootEl.innerHTML = ''
return
}
rootEl.innerHTML = html
await vivifyModerationChannel(clientOptions, rootEl, channelId)
await vivifyConfigurationChannel(clientOptions, rootEl, channelId)
}
})
registerHook({
target: 'filter:left-menu.links.create.result',
handler: async (links: any) => {
// Adding the links to livechat/moderation for logged users.
// Adding the links to livechat/configuration for logged users.
if (!peertubeHelpers.isLoggedIn()) { return links }
if (!Array.isArray(links)) { return links }
@ -52,11 +52,11 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis
if (!myLibraryLinks) { return links }
if (!Array.isArray(myLibraryLinks.links)) { return links }
const label = await peertubeHelpers.translate(LOC_MENU_MODERATION_LABEL)
const label = await peertubeHelpers.translate(LOC_MENU_CONFIGURATION_LABEL)
myLibraryLinks.links.push({
label,
shortLabel: label,
path: '/p/livechat/moderation',
path: '/p/livechat/configuration',
icon: 'live'
})
return links
@ -65,5 +65,5 @@ async function registerModeration (clientOptions: RegisterClientOptions): Promis
}
export {
registerModeration
registerConfiguration
}

View File

@ -1,16 +1,16 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { ChannelModeration } from 'shared/lib/types'
import type { ChannelConfiguration } from 'shared/lib/types'
import { getBaseRoute } from '../../../videowatch/uri'
// Must use require for mustache, import seems buggy.
const Mustache = require('mustache')
/**
* Renders the moderation settings page for a given channel.
* Renders the configuration settings page for a given channel.
* @param registerClientOptions Peertube client options
* @param channelId The channel id
* @returns The page content
*/
async function renderModerationChannel (
async function renderConfigurationChannel (
registerClientOptions: RegisterClientOptions,
channelId: string
): Promise<string | false> {
@ -22,63 +22,65 @@ async function renderModerationChannel (
}
const response = await fetch(
getBaseRoute(registerClientOptions) + '/api/moderation/channel/' + encodeURIComponent(channelId),
getBaseRoute(registerClientOptions) + '/api/configuration/channel/' + encodeURIComponent(channelId),
{
method: 'GET',
headers: peertubeHelpers.getAuthHeader()
}
)
if (!response.ok) {
throw new Error('Can\'t get channel moderation options.')
throw new Error('Can\'t get channel configuration options.')
}
const channelModeration: ChannelModeration = await (response).json()
const channelConfiguration: ChannelConfiguration = await (response).json()
// Basic testing that channelModeration has the correct format
if ((typeof channelModeration !== 'object') || !channelModeration.channel) {
throw new Error('Invalid channel moderation options.')
// Basic testing that channelConfiguration has the correct format
if ((typeof channelConfiguration !== 'object') || !channelConfiguration.channel) {
throw new Error('Invalid channel configuration options.')
}
const view = {
title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_TITLE),
description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_DESC),
enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_ENABLE_BOT_LABEL),
botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BOT_OPTIONS_TITLE),
forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_FORBIDDEN_WORDS_LABEL),
bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_CHANNEL_BANNED_JIDS_LABEL),
title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE),
description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_DESC),
enableBot: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_ENABLE_BOT_LABEL),
botOptions: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_OPTIONS_TITLE),
forbiddenWords: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL),
bannedJIDs: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_BANNED_JIDS_LABEL),
save: await peertubeHelpers.translate(LOC_SAVE),
cancel: await peertubeHelpers.translate(LOC_CANCEL),
channelModeration
channelConfiguration
}
return Mustache.render(`
<div class="margin-content">
<h1>{{title}} {{channelModeration.channel.displayName}}</h1>
<h1>{{title}} {{channelConfiguration.channel.displayName}}</h1>
<p>{{description}}</p>
<form livechat-moderation-channel-options>
<form livechat-configuration-channel-options>
<fieldset>
<label>
<input
type="checkbox" name="bot"
value="1"
{{#channelModeration.moderation.bot}} checked="checked" {{/channelModeration.moderation.bot}}
{{#channelConfiguration.configuration.bot}}
checked="checked"
{{/channelConfiguration.configuration.bot}}
/>
{{enableBot}}
</label>
</fieldset>
<fieldset livechat-moderation-channel-options-bot-enabled>
<fieldset livechat-configuration-channel-options-bot-enabled>
<legend>{{botOptions}}</legend>
<label>
{{forbiddenWords}}
<textarea name="forbidden_words">
{{#channelModeration.moderation.forbiddenWords}}{{.}}
{{/channelModeration.moderation.forbiddenWords}}
{{#channelConfiguration.configuration.forbiddenWords}}{{.}}
{{/channelConfiguration.configuration.forbiddenWords}}
</textarea>
</label>
<label>
{{bannedJIDs}}
<textarea name="banned_jids">
{{#channelModeration.moderation.bannedJIDs}}{{.}}
{{/channelModeration.moderation.bannedJIDs}}
{{#channelConfiguration.configuration.bannedJIDs}}{{.}}
{{/channelConfiguration.configuration.bannedJIDs}}
</textarea>
</label>
</fieldset>
@ -94,5 +96,5 @@ async function renderModerationChannel (
}
export {
renderModerationChannel
renderConfigurationChannel
}

View File

@ -3,11 +3,11 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client'
const Mustache = require('mustache')
/**
* Renders the livechat moderation setup home page.
* Renders the livechat configuration setup home page.
* @param registerClientOptions Peertube client options
* @returns The page content
*/
async function renderModerationHome (registerClientOptions: RegisterClientOptions): Promise<string> {
async function renderConfigurationHome (registerClientOptions: RegisterClientOptions): Promise<string> {
const { peertubeHelpers } = registerClientOptions
try {
@ -29,13 +29,13 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
}
for (const channel of channels.data) {
channel.livechatModerationUri = '/p/livechat/moderation/channel?channelId=' + encodeURIComponent(channel.id)
channel.livechatConfigurationUri = '/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channel.id)
}
const view = {
title: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_TITLE),
description: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_DESC),
please_select: await peertubeHelpers.translate(LOC_LIVECHAT_MODERATION_PLEASE_SELECT),
title: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_TITLE),
description: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_DESC),
please_select: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_PLEASE_SELECT),
channels: channels.data
}
@ -47,7 +47,7 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
<ul>
{{#channels}}
<li>
<a href="{{livechatModerationUri}}">
<a href="{{livechatConfigurationUri}}">
{{displayName}}
</a>
</li>
@ -62,5 +62,5 @@ async function renderModerationHome (registerClientOptions: RegisterClientOption
}
export {
renderModerationHome
renderConfigurationHome
}

View File

@ -296,14 +296,14 @@ prosody_components_list_description: |
save: "Save"
cancel: "Cancel"
successfully_saved: "Successfully saved"
menu_moderation_label: "Chatrooms"
livechat_moderation_title: "Configure your live's chatrooms moderation policies"
livechat_moderation_desc: "Here you can configure some advanced options for chatrooms associated to your live streams."
livechat_moderation_please_select: "Please select bellow one of your channel, to setup its chatting options."
livechat_moderation_channel_title: "Moderation policies for channel:"
livechat_moderation_channel_desc: "You can setup here your moderation policies for this channel."
livechat_moderation_channel_enable_bot_label: "Enable moderation bot"
livechat_moderation_channel_bot_options_title: "Moderation bot options"
livechat_moderation_channel_forbidden_words_label: "Forbidden words or expressions"
livechat_moderation_channel_banned_jids_label: "Banned users and patterns"
menu_configuration_label: "Chatrooms"
livechat_configuration_title: "Configure your live's chatrooms"
livechat_configuration_desc: "Here you can configure some advanced options for chatrooms associated to your live streams."
livechat_configuration_please_select: "Please select bellow one of your channel, to setup its chatting options."
livechat_configuration_channel_title: "Moderation policies for channel:"
livechat_configuration_channel_desc: "You can setup here your moderation policies for this channel."
livechat_configuration_channel_enable_bot_label: "Enable moderation bot"
livechat_configuration_channel_bot_options_title: "Moderation bot options"
livechat_configuration_channel_forbidden_words_label: "Forbidden words or expressions"
livechat_configuration_channel_banned_jids_label: "Banned users and patterns"

View File

@ -1,19 +1,19 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { ChannelModerationOptions, ChannelInfos } from '../../../../shared/lib/types'
import type { ChannelConfigurationOptions, ChannelInfos } from '../../../../shared/lib/types'
/**
* Sanitize data so that they can safely be used/stored for channel moderation configuration.
* Sanitize data so that they can safely be used/stored for channel configuration configuration.
* Throw an error if the format is obviously wrong.
* Cleans data (removing empty values, ...)
* @param options Peertube server options
* @param _channelInfos Channel infos
* @param data Input data
*/
async function sanitizeChannelModerationOptions (
async function sanitizeChannelConfigurationOptions (
_options: RegisterServerOptions,
_channelInfos: ChannelInfos,
data: any
): Promise<ChannelModerationOptions> {
): Promise<ChannelConfigurationOptions> {
const result = {
bot: false,
bannedJIDs: [],
@ -28,7 +28,7 @@ async function sanitizeChannelModerationOptions (
if (!(f in data) || (typeof data[f] !== 'boolean')) {
throw new Error('Invalid data type for field ' + f)
}
result[f as keyof ChannelModerationOptions] = data[f]
result[f as keyof ChannelConfigurationOptions] = data[f]
}
// value/regexp array fields
for (const f of ['bannedJIDs', 'forbiddenWords']) {
@ -50,7 +50,7 @@ async function sanitizeChannelModerationOptions (
} catch (_err) {
throw new Error('Invalid value in field ' + f)
}
(result[f as keyof ChannelModerationOptions] as string[]).push(v)
(result[f as keyof ChannelConfigurationOptions] as string[]).push(v)
}
}
@ -58,5 +58,5 @@ async function sanitizeChannelModerationOptions (
}
export {
sanitizeChannelModerationOptions
sanitizeChannelConfigurationOptions
}

View File

@ -1,27 +1,27 @@
import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { ChannelModeration, ChannelInfos } from '../../../../shared/lib/types'
import { sanitizeChannelModerationOptions } from '../../moderation/channel/sanitize'
import type { ChannelConfiguration, ChannelInfos } from '../../../../shared/lib/types'
import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize'
import * as fs from 'fs'
import * as path from 'path'
/**
* Get saved moderation options for the given channel.
* Get saved configuration options for the given channel.
* Can throw an exception.
* @param options Peertube server options
* @param channelInfos Info from channel from which we want to get infos
* @returns Channel moderation data
* @returns Channel configuration data
*/
async function getChannelModerationOptions (
async function getChannelConfigurationOptions (
options: RegisterServerOptions,
channelInfos: ChannelInfos
): Promise<ChannelModeration> {
): Promise<ChannelConfiguration> {
const logger = options.peertubeHelpers.logger
const filePath = _getFilePath(options, channelInfos)
if (!fs.existsSync(filePath)) {
logger.debug('No stored data for channel, returning default values')
return {
channel: channelInfos,
moderation: {
configuration: {
bot: false,
bannedJIDs: [],
forbiddenWords: []
@ -31,24 +31,24 @@ async function getChannelModerationOptions (
const content = await fs.promises.readFile(filePath, {
encoding: 'utf-8'
})
const sanitized = await sanitizeChannelModerationOptions(options, channelInfos, JSON.parse(content))
const sanitized = await sanitizeChannelConfigurationOptions(options, channelInfos, JSON.parse(content))
return {
channel: channelInfos,
moderation: sanitized
configuration: sanitized
}
}
/**
* Save channel moderation options.
* Save channel configuration options.
* Can throw an exception.
* @param _options Peertube server options
* @param _channelModeration data to save
* @param options Peertube server options
* @param channelConfiguration data to save
*/
async function storeChannelModerationOptions (
async function storeChannelConfigurationOptions (
options: RegisterServerOptions,
channelModeration: ChannelModeration
channelConfiguration: ChannelConfiguration
): Promise<void> {
const channelInfos = channelModeration.channel
const channelInfos = channelConfiguration.channel
const filePath = _getFilePath(options, channelInfos)
if (!fs.existsSync(filePath)) {
@ -58,7 +58,7 @@ async function storeChannelModerationOptions (
}
}
const jsonContent = JSON.stringify(channelModeration.moderation)
const jsonContent = JSON.stringify(channelConfiguration.configuration)
await fs.promises.writeFile(filePath, jsonContent, {
encoding: 'utf-8'
@ -77,12 +77,12 @@ function _getFilePath (
return path.resolve(
options.peertubeHelpers.plugin.getDataDirectoryPath(),
'channelModerationOptions',
'channelConfigurationOptions',
channelId.toString() + '.json'
)
}
export {
getChannelModerationOptions,
storeChannelModerationOptions
getChannelConfigurationOptions,
storeChannelConfigurationOptions
}

View File

@ -6,11 +6,11 @@ import { isUserAdminOrModerator } from '../../helpers'
/**
* Returns a middleware handler to get the channelInfos from the channel parameter.
* This is used in api related to channel moderation options.
* This is used in api related to channel configuration options.
* @param options Peertube server options
* @returns middleware function
*/
function getCheckModerationChannelMiddleware (options: RegisterServerOptions): RequestPromiseHandler {
function getCheckConfigurationChannelMiddleware (options: RegisterServerOptions): RequestPromiseHandler {
return async (req: Request, res: Response, next: NextFunction) => {
const logger = options.peertubeHelpers.logger
const channelId = req.params.channelId
@ -42,12 +42,12 @@ function getCheckModerationChannelMiddleware (options: RegisterServerOptions): R
return
}
logger.debug('User can access the moderation channel api.')
logger.debug('User can access the configuration channel api.')
res.locals.channelInfos = channelInfos
next()
}
}
export {
getCheckModerationChannelMiddleware
getCheckConfigurationChannelMiddleware
}

View File

@ -7,7 +7,7 @@ import { isDebugMode } from '../debug'
import { initRoomApiRouter } from './api/room'
import { initAuthApiRouter, initUserAuthApiRouter } from './api/auth'
import { initFederationServerInfosApiRouter } from './api/federation-server-infos'
import { initModerationApiRouter } from './api/moderation'
import { initConfigurationApiRouter } from './api/configuration'
/**
* Initiate API routes
@ -53,7 +53,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
))
}
router.use('/moderation', await initModerationApiRouter(options))
router.use('/configuration', await initConfigurationApiRouter(options))
return router
}

View File

@ -2,16 +2,16 @@ import type { RegisterServerOptions } from '@peertube/peertube-types'
import type { Router, Request, Response, NextFunction } from 'express'
import type { ChannelInfos } from '../../../../shared/lib/types'
import { asyncMiddleware } from '../../middlewares/async'
import { getCheckModerationChannelMiddleware } from '../../middlewares/moderation/channel'
import { getChannelModerationOptions, storeChannelModerationOptions } from '../../moderation/channel/storage'
import { sanitizeChannelModerationOptions } from '../../moderation/channel/sanitize'
import { getCheckConfigurationChannelMiddleware } from '../../middlewares/configuration/channel'
import { getChannelConfigurationOptions, storeChannelConfigurationOptions } from '../../configuration/channel/storage'
import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize'
async function initModerationApiRouter (options: RegisterServerOptions): Promise<Router> {
async function initConfigurationApiRouter (options: RegisterServerOptions): Promise<Router> {
const router = options.getRouter()
const logger = options.peertubeHelpers.logger
router.get('/channel/:channelId', asyncMiddleware([
getCheckModerationChannelMiddleware(options),
getCheckConfigurationChannelMiddleware(options),
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
if (!res.locals.channelInfos) {
logger.error('Missing channelInfos in res.locals, should not happen')
@ -20,14 +20,14 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise
}
const channelInfos = res.locals.channelInfos as ChannelInfos
const result = await getChannelModerationOptions(options, channelInfos)
const result = await getChannelConfigurationOptions(options, channelInfos)
res.status(200)
res.json(result)
}
]))
router.post('/channel/:channelId', asyncMiddleware([
getCheckModerationChannelMiddleware(options),
getCheckConfigurationChannelMiddleware(options),
async (req: Request, res: Response, _next: NextFunction): Promise<void> => {
if (!res.locals.channelInfos) {
logger.error('Missing channelInfos in res.locals, should not happen')
@ -35,11 +35,11 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise
return
}
const channelInfos = res.locals.channelInfos as ChannelInfos
logger.debug('Trying to save ChannelModerationOptions')
logger.debug('Trying to save ChannelConfigurationOptions')
let moderation
let configuration
try {
moderation = await sanitizeChannelModerationOptions(options, channelInfos, req.body)
configuration = await sanitizeChannelConfigurationOptions(options, channelInfos, req.body)
} catch (err) {
logger.warn(err)
res.sendStatus(400)
@ -49,9 +49,9 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise
logger.debug('Data seems ok, storing them.')
const result = {
channel: channelInfos,
moderation
configuration
}
await storeChannelModerationOptions(options, result)
await storeChannelConfigurationOptions(options, result)
res.status(200)
res.json(result)
}
@ -61,5 +61,5 @@ async function initModerationApiRouter (options: RegisterServerOptions): Promise
}
export {
initModerationApiRouter
initConfigurationApiRouter
}

View File

@ -52,15 +52,15 @@ interface ChannelInfos {
displayName: string
}
interface ChannelModerationOptions {
interface ChannelConfigurationOptions {
bot: boolean
forbiddenWords: string[]
bannedJIDs: string[]
}
interface ChannelModeration {
interface ChannelConfiguration {
channel: ChannelInfos
moderation: ChannelModerationOptions
configuration: ChannelConfigurationOptions
}
export type {
@ -69,6 +69,6 @@ export type {
ProsodyListRoomsResult,
ProsodyListRoomsResultRoom,
ChannelInfos,
ChannelModerationOptions,
ChannelModeration
ChannelConfigurationOptions,
ChannelConfiguration
}