From 5364e8da26d015d258e106f8f565d45e92cbd80f Mon Sep 17 00:00:00 2001 From: bunnybeam Date: Thu, 28 Aug 2025 21:12:03 +0100 Subject: [PATCH] make dialog announcement cap configurable --- .config/cypress-devcontainer.yml | 2 ++ .config/docker_example.yml | 2 ++ .config/example.yml | 2 ++ packages/backend/src/config.ts | 5 ++++- packages/backend/src/core/AnnouncementService.ts | 6 +++++- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.config/cypress-devcontainer.yml b/.config/cypress-devcontainer.yml index 97263da68f..eae7e14308 100644 --- a/.config/cypress-devcontainer.yml +++ b/.config/cypress-devcontainer.yml @@ -250,6 +250,8 @@ id: 'aidx' #maxAltTextLength: 20000 # Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1) #maxRemoteAltTextLength: 100000 +# Amount of dialog-style announcements that can be active at a time. (minimum: 1) +#maxDialogAnnouncements: 5 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 9b57eec88b..de43d3e43c 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -345,6 +345,8 @@ id: 'aidx' #maxBioLength: 1500 # Amount of characters that will be saved for remote user bios. Longer descriptions will be truncated to this length. (minimum: 1) #maxRemoteBioLength: 15000 +# Amount of dialog-style announcements that can be active at a time. (minimum: 1) +#maxDialogAnnouncements: 5 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/.config/example.yml b/.config/example.yml index 46ace4abc2..745004305d 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -348,6 +348,8 @@ id: 'aidx' #maxBioLength: 1500 # Amount of characters that will be saved for remote user bios. Longer descriptions will be truncated to this length. (minimum: 1) #maxRemoteBioLength: 15000 +# Amount of dialog-style announcements that can be active at a time. (minimum: 1) +#maxDialogAnnouncements: 5 # Proxy for HTTP/HTTPS #proxy: http://127.0.0.1:3128 diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 21396a1f7f..9d0736d94e 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -98,6 +98,7 @@ type Source = { maxRemoteAltTextLength?: number; maxBioLength?: number; maxRemoteBioLength?: number; + maxDialogAnnouncements?: number; clusterLimit?: number; @@ -265,6 +266,7 @@ export type Config = { maxRemoteAltTextLength: number; maxBioLength: number; maxRemoteBioLength: number; + maxDialogAnnouncements: number; clusterLimit: number | undefined; id: string; outgoingAddress: string | undefined; @@ -467,6 +469,7 @@ export function loadConfig(): Config { maxRemoteAltTextLength: config.maxRemoteAltTextLength ?? 100000, maxBioLength: config.maxBioLength ?? 1500, maxRemoteBioLength: config.maxRemoteBioLength ?? 15000, + maxDialogAnnouncements: config.maxDialogAnnouncements ?? 5, clusterLimit: config.clusterLimit, outgoingAddress: config.outgoingAddress, outgoingAddressFamily: config.outgoingAddressFamily, @@ -664,7 +667,7 @@ function applyEnvOverrides(config: Source) { _apply_top(['sentryForFrontend', 'browserTracingIntegration', 'routeLabel']); _apply_top([['clusterLimit', 'deliverJobConcurrency', 'inboxJobConcurrency', 'relashionshipJobConcurrency', 'deliverJobPerSec', 'inboxJobPerSec', 'relashionshipJobPerSec', 'deliverJobMaxAttempts', 'inboxJobMaxAttempts']]); _apply_top([['outgoingAddress', 'outgoingAddressFamily', 'proxy', 'proxySmtp', 'mediaDirectory', 'mediaProxy', 'proxyRemoteFiles', 'videoThumbnailGenerator']]); - _apply_top([['maxFileSize', 'maxNoteLength', 'maxRemoteNoteLength', 'maxAltTextLength', 'maxRemoteAltTextLength', 'maxBioLength', 'maxRemoteBioLength', 'pidFile', 'filePermissionBits']]); + _apply_top([['maxFileSize', 'maxNoteLength', 'maxRemoteNoteLength', 'maxAltTextLength', 'maxRemoteAltTextLength', 'maxBioLength', 'maxRemoteBioLength', 'maxDialogAnnouncements', 'pidFile', 'filePermissionBits']]); _apply_top(['import', ['downloadTimeout', 'maxFileSize']]); _apply_top([['signToActivityPubGet', 'checkActivityPubGetSignature', 'setupPassword', 'disallowExternalApRedirect']]); _apply_top(['logging', 'sql', ['disableQueryTruncation', 'enableQueryParamLogging']]); diff --git a/packages/backend/src/core/AnnouncementService.ts b/packages/backend/src/core/AnnouncementService.ts index 51ab4881fd..0959cd5245 100644 --- a/packages/backend/src/core/AnnouncementService.ts +++ b/packages/backend/src/core/AnnouncementService.ts @@ -15,10 +15,14 @@ import { AnnouncementEntityService } from '@/core/entities/AnnouncementEntitySer import { GlobalEventService } from '@/core/GlobalEventService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; +import type { Config } from '@/config.js'; @Injectable() export class AnnouncementService { constructor( + @Inject(DI.config) + private config: Config, + @Inject(DI.announcementsRepository) private announcementsRepository: AnnouncementsRepository, @@ -241,7 +245,7 @@ export class AnnouncementService { display: 'dialog', }) .getCount(); - if (dialogCount >= 5) { + if (dialogCount >= this.config.maxDialogAnnouncements) { throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.'); } }