Moving max and default values in constants.
This commit is contained in:
parent
5225257bb5
commit
6f479d26c5
@ -10,6 +10,7 @@ import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements
|
|||||||
import { ptTr } from '../../../lib/directives/translation'
|
import { ptTr } from '../../../lib/directives/translation'
|
||||||
import { html, TemplateResult } from 'lit'
|
import { html, TemplateResult } from 'lit'
|
||||||
import { classMap } from 'lit/directives/class-map.js'
|
import { classMap } from 'lit/directives/class-map.js'
|
||||||
|
import { noDuplicateMaxDelay, forbidSpecialCharsMaxTolerance } from 'shared/lib/constants'
|
||||||
|
|
||||||
export function tplChannelConfiguration (el: ChannelConfigurationElement): TemplateResult {
|
export function tplChannelConfiguration (el: ChannelConfigurationElement): TemplateResult {
|
||||||
const tableHeaderList: Record<string, DynamicFormHeader> = {
|
const tableHeaderList: Record<string, DynamicFormHeader> = {
|
||||||
@ -381,7 +382,7 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
min="0"
|
min="0"
|
||||||
max="10"
|
max="${forbidSpecialCharsMaxTolerance}"
|
||||||
id="peertube-livechat-forbid-special-chars-tolerance"
|
id="peertube-livechat-forbid-special-chars-tolerance"
|
||||||
aria-describedby="peertube-livechat-forbid-special-chars-tolerance-feedback"
|
aria-describedby="peertube-livechat-forbid-special-chars-tolerance-feedback"
|
||||||
@input=${(event: InputEvent) => {
|
@input=${(event: InputEvent) => {
|
||||||
@ -501,7 +502,7 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
min="0"
|
min="0"
|
||||||
max="10"
|
max="${noDuplicateMaxDelay.toString()}"
|
||||||
id="peertube-livechat-no-duplicate-delay"
|
id="peertube-livechat-no-duplicate-delay"
|
||||||
aria-describedby="peertube-livechat-no-duplicate-delay-feedback"
|
aria-describedby="peertube-livechat-no-duplicate-delay-feedback"
|
||||||
@input=${(event: InputEvent) => {
|
@input=${(event: InputEvent) => {
|
||||||
|
@ -11,7 +11,7 @@ import type {
|
|||||||
import { ValidationError, ValidationErrorType } from '../../lib/models/validation'
|
import { ValidationError, ValidationErrorType } from '../../lib/models/validation'
|
||||||
import { getBaseRoute } from '../../../utils/uri'
|
import { getBaseRoute } from '../../../utils/uri'
|
||||||
import { maxEmojisPerChannel } from 'shared/lib/emojis'
|
import { maxEmojisPerChannel } from 'shared/lib/emojis'
|
||||||
import { channelTermsMaxLength } from 'shared/lib/constants'
|
import { channelTermsMaxLength, noDuplicateMaxDelay, forbidSpecialCharsMaxTolerance } from 'shared/lib/constants'
|
||||||
|
|
||||||
export class ChannelDetailsService {
|
export class ChannelDetailsService {
|
||||||
public _registerClientOptions: RegisterClientOptions
|
public _registerClientOptions: RegisterClientOptions
|
||||||
@ -83,7 +83,7 @@ export class ChannelDetailsService {
|
|||||||
propertiesError['bot.forbidSpecialChars.tolerance'].push(ValidationErrorType.WrongType)
|
propertiesError['bot.forbidSpecialChars.tolerance'].push(ValidationErrorType.WrongType)
|
||||||
} else if (
|
} else if (
|
||||||
forbidSpecialCharsTolerance < 0 ||
|
forbidSpecialCharsTolerance < 0 ||
|
||||||
forbidSpecialCharsTolerance > 10
|
forbidSpecialCharsTolerance > forbidSpecialCharsMaxTolerance
|
||||||
) {
|
) {
|
||||||
propertiesError['bot.forbidSpecialChars.tolerance'].push(ValidationErrorType.NotInRange)
|
propertiesError['bot.forbidSpecialChars.tolerance'].push(ValidationErrorType.NotInRange)
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ export class ChannelDetailsService {
|
|||||||
propertiesError['bot.noDuplicate.delay'].push(ValidationErrorType.WrongType)
|
propertiesError['bot.noDuplicate.delay'].push(ValidationErrorType.WrongType)
|
||||||
} else if (
|
} else if (
|
||||||
noDuplicateDelay < 0 ||
|
noDuplicateDelay < 0 ||
|
||||||
noDuplicateDelay > 24 * 3600
|
noDuplicateDelay > noDuplicateMaxDelay
|
||||||
) {
|
) {
|
||||||
propertiesError['bot.noDuplicate.delay'].push(ValidationErrorType.NotInRange)
|
propertiesError['bot.noDuplicate.delay'].push(ValidationErrorType.NotInRange)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,13 @@
|
|||||||
|
|
||||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||||
import type { ChannelConfigurationOptions } from '../../../../shared/lib/types'
|
import type { ChannelConfigurationOptions } from '../../../../shared/lib/types'
|
||||||
import { channelTermsMaxLength } from '../../../../shared/lib/constants'
|
import {
|
||||||
|
channelTermsMaxLength,
|
||||||
|
forbidSpecialCharsMaxTolerance,
|
||||||
|
forbidSpecialCharsDefaultTolerance,
|
||||||
|
noDuplicateDefaultDelay,
|
||||||
|
noDuplicateMaxDelay
|
||||||
|
} from '../../../../shared/lib/constants'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize data so that they can safely be used/stored for channel configuration configuration.
|
* Sanitize data so that they can safely be used/stored for channel configuration configuration.
|
||||||
@ -53,7 +59,7 @@ async function sanitizeChannelConfigurationOptions (
|
|||||||
botData.forbidSpecialChars ??= {
|
botData.forbidSpecialChars ??= {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
reason: '',
|
reason: '',
|
||||||
tolerance: 0,
|
tolerance: forbidSpecialCharsDefaultTolerance,
|
||||||
applyToModerators: false
|
applyToModerators: false
|
||||||
}
|
}
|
||||||
if (!_assertObjectType(botData.forbidSpecialChars)) {
|
if (!_assertObjectType(botData.forbidSpecialChars)) {
|
||||||
@ -64,7 +70,7 @@ async function sanitizeChannelConfigurationOptions (
|
|||||||
botData.noDuplicate ??= {
|
botData.noDuplicate ??= {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
reason: '',
|
reason: '',
|
||||||
delay: 60,
|
delay: noDuplicateDefaultDelay,
|
||||||
applyToModerators: false
|
applyToModerators: false
|
||||||
}
|
}
|
||||||
if (!_assertObjectType(botData.noDuplicate)) {
|
if (!_assertObjectType(botData.noDuplicate)) {
|
||||||
@ -272,7 +278,7 @@ async function _readForbidSpecialChars (
|
|||||||
const result: ChannelConfigurationOptions['bot']['forbidSpecialChars'] = {
|
const result: ChannelConfigurationOptions['bot']['forbidSpecialChars'] = {
|
||||||
enabled: _readBoolean(botData.forbidSpecialChars, 'enabled'),
|
enabled: _readBoolean(botData.forbidSpecialChars, 'enabled'),
|
||||||
reason: _readSimpleInput(botData.forbidSpecialChars, 'reason'),
|
reason: _readSimpleInput(botData.forbidSpecialChars, 'reason'),
|
||||||
tolerance: _readInteger(botData.forbidSpecialChars, 'tolerance', 0, 10),
|
tolerance: _readInteger(botData.forbidSpecialChars, 'tolerance', 0, forbidSpecialCharsMaxTolerance),
|
||||||
applyToModerators: _readBoolean(botData.forbidSpecialChars, 'applyToModerators')
|
applyToModerators: _readBoolean(botData.forbidSpecialChars, 'applyToModerators')
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -287,7 +293,7 @@ async function _readNoDuplicate (
|
|||||||
const result: ChannelConfigurationOptions['bot']['noDuplicate'] = {
|
const result: ChannelConfigurationOptions['bot']['noDuplicate'] = {
|
||||||
enabled: _readBoolean(botData.noDuplicate, 'enabled'),
|
enabled: _readBoolean(botData.noDuplicate, 'enabled'),
|
||||||
reason: _readSimpleInput(botData.noDuplicate, 'reason'),
|
reason: _readSimpleInput(botData.noDuplicate, 'reason'),
|
||||||
delay: _readInteger(botData.noDuplicate, 'delay', 0, 24 * 3600),
|
delay: _readInteger(botData.noDuplicate, 'delay', 0, noDuplicateMaxDelay),
|
||||||
applyToModerators: _readBoolean(botData.noDuplicate, 'applyToModerators')
|
applyToModerators: _readBoolean(botData.noDuplicate, 'applyToModerators')
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -7,6 +7,10 @@ import type { ChannelConfigurationOptions } from '../../../../shared/lib/types'
|
|||||||
import type { ChannelCommonRoomConf } from '../../configuration/bot'
|
import type { ChannelCommonRoomConf } from '../../configuration/bot'
|
||||||
import { RoomChannel } from '../../room-channel'
|
import { RoomChannel } from '../../room-channel'
|
||||||
import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize'
|
import { sanitizeChannelConfigurationOptions } from '../../configuration/channel/sanitize'
|
||||||
|
import {
|
||||||
|
forbidSpecialCharsDefaultTolerance,
|
||||||
|
noDuplicateDefaultDelay
|
||||||
|
} from '../../../../shared/lib/constants'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
@ -47,13 +51,13 @@ function getDefaultChannelConfigurationOptions (_options: RegisterServerOptions)
|
|||||||
forbidSpecialChars: {
|
forbidSpecialChars: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
reason: '',
|
reason: '',
|
||||||
tolerance: 0,
|
tolerance: forbidSpecialCharsDefaultTolerance,
|
||||||
applyToModerators: false
|
applyToModerators: false
|
||||||
},
|
},
|
||||||
noDuplicate: {
|
noDuplicate: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
reason: '',
|
reason: '',
|
||||||
delay: 60,
|
delay: noDuplicateDefaultDelay,
|
||||||
applyToModerators: false
|
applyToModerators: false
|
||||||
},
|
},
|
||||||
quotes: [],
|
quotes: [],
|
||||||
|
@ -3,3 +3,9 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
export const channelTermsMaxLength = 400
|
export const channelTermsMaxLength = 400
|
||||||
|
|
||||||
|
export const forbidSpecialCharsDefaultTolerance = 0
|
||||||
|
export const forbidSpecialCharsMaxTolerance = 10
|
||||||
|
|
||||||
|
export const noDuplicateMaxDelay = 86400
|
||||||
|
export const noDuplicateDefaultDelay = 60
|
||||||
|
Loading…
Reference in New Issue
Block a user