Fix: the emojis import function could add more entries than max allowed emoji count.

+ another minor fix.
This commit is contained in:
John Livingston 2024-06-20 11:38:04 +02:00
parent 83dd3130a1
commit a0b4b5f61a
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
5 changed files with 15 additions and 1 deletions

View File

@ -3,6 +3,7 @@
## 10.1.1 (Not released yet) ## 10.1.1 (Not released yet)
* #436: Saving emojis per batch, to avoid hitting max payload limit. * #436: Saving emojis per batch, to avoid hitting max payload limit.
* Fix: the emojis import function could add more entries than max allowed emoji count.
## 10.1.0 ## 10.1.0

View File

@ -83,6 +83,7 @@ declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_BOT_NICKNAME: string
declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FOR_MORE_INFO: string declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_FOR_MORE_INFO: string
declare const LOC_VALIDATION_ERROR: string declare const LOC_VALIDATION_ERROR: string
declare const LOC_TOO_MANY_ENTRIES: string
declare const LOC_INVALID_VALUE: string declare const LOC_INVALID_VALUE: string
declare const LOC_INVALID_VALUE_MISSING: string declare const LOC_INVALID_VALUE_MISSING: string
declare const LOC_INVALID_VALUE_WRONG_TYPE: string declare const LOC_INVALID_VALUE_WRONG_TYPE: string

View File

@ -181,6 +181,16 @@ export class ChannelDetailsService {
public async validateEmojisConfiguration (channelEmojis: ChannelEmojis): Promise<boolean> { public async validateEmojisConfiguration (channelEmojis: ChannelEmojis): Promise<boolean> {
const propertiesError: ValidationError['properties'] = {} const propertiesError: ValidationError['properties'] = {}
if (channelEmojis.customEmojis.length > maxEmojisPerChannel) {
// This can happen when using the import function.
const validationError = new ValidationError(
'ChannelEmojisValidationError',
await this._registerClientOptions.peertubeHelpers.translate(LOC_TOO_MANY_ENTRIES),
propertiesError
)
throw validationError
}
const seen = new Map<string, true>() const seen = new Map<string, true>()
for (const [i, e] of channelEmojis.customEmojis.entries()) { for (const [i, e] of channelEmojis.customEmojis.entries()) {
propertiesError[`emojis.${i}.sn`] = [] propertiesError[`emojis.${i}.sn`] = []
@ -233,7 +243,7 @@ export class ChannelDetailsService {
let watchDog = 0 let watchDog = 0
while (i >= 0) { while (i >= 0) {
watchDog++ watchDog++
if (watchDog > maxEmojisPerChannel + 10) { // just to avoid infinite loop if (watchDog > channelEmojis.customEmojis.length + 10) { // just to avoid infinite loop
throw new Error('Seems we have sent too many emojis, this was not expected') throw new Error('Seems we have sent too many emojis, this was not expected')
} }
const data: CustomEmojiDefinition[] = customEmojis.slice(0, i + 1) // all elements until first new file const data: CustomEmojiDefinition[] = customEmojis.slice(0, i + 1) // all elements until first new file

View File

@ -455,6 +455,7 @@ invalid_value_wrong_format: "Value is in the wrong format."
invalid_value_not_in_range: "Value is not in authorized range." invalid_value_not_in_range: "Value is not in authorized range."
invalid_value_file_too_big: "File size is too big (max size: %s)." invalid_value_file_too_big: "File size is too big (max size: %s)."
invalid_value_duplicate: "Duplicate value" invalid_value_duplicate: "Duplicate value"
too_many_entries: "Too many entries"
slow_mode_info: "Slow mode is enabled, users can send a message every %1$s seconds." slow_mode_info: "Slow mode is enabled, users can send a message every %1$s seconds."

View File

@ -522,3 +522,4 @@ livechat_token_disabled_description: "Les utilisateur⋅rices peuvent générer
pour inclure le tchat dans les docks web dans OBS.\nConsultez <a href=\"https://livingston.frama.io/peertube-plugin-livechat/fr/documentation/user/obs\"\ pour inclure le tchat dans les docks web dans OBS.\nConsultez <a href=\"https://livingston.frama.io/peertube-plugin-livechat/fr/documentation/user/obs\"\
\ target=\"_blank\">la documentation</a> pour plus d'informations.\nVous pouvez \ target=\"_blank\">la documentation</a> pour plus d'informations.\nVous pouvez
désactiver cette fonctionnalité en cochant ce paramètre.\n" désactiver cette fonctionnalité en cochant ce paramètre.\n"
too_many_entries: "Trop d'entrées"