Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(limits): make bot attachment size limit configurable (#3822)

Hampuse8879e0e33ce
diff --git a/fluxer_admin/openapi-admin.json b/fluxer_admin/openapi-admin.json
index 2dba8d0ad..c884a65ab 100644
--- a/fluxer_admin/openapi-admin.json
+++ b/fluxer_admin/openapi-admin.json
@@ -17451,6 +17451,7 @@
"max_attachments_per_message",
"max_bio_length",
"max_bookmarks",
+ "max_bot_attachment_file_size",
"max_channels_per_category",
"max_custom_backgrounds",
"max_embeds_per_message",
diff --git a/fluxer_admin/src/admin_hints.rs b/fluxer_admin/src/admin_hints.rs
index c086502bb..23cb8a870 100644
--- a/fluxer_admin/src/admin_hints.rs
+++ b/fluxer_admin/src/admin_hints.rs
@@ -17,6 +17,11 @@ pub fn limit_key_hint(key: &str) -> Option<Hint<'static>> {
body: "In bits per second, so 9000000 is 9 Mbps. Raising it also raises the automatic bitrate of every screen share quality. Accounts with Higher Video Quality can pick their own bitrate up to this value.",
link: None,
}),
+ "max_bot_attachment_file_size" => Some(Hint {
+ name: Some("Max Bot Attachment File Size"),
+ body: "In bytes. Bots get the lower of this and Max Attachment File Size. Bots count as premium, so that is 500 MiB unless you change it. Raise Max Attachment File Size too only if you want bots above it. To raise it for one bot, give the bot a trait and add a rule for that trait, and set Max Attachment File Size in that rule too to go above 500 MiB.",
+ link: None,
+ }),
_ => None,
}
}
diff --git a/fluxer_api/src/api/channel/services/AttachmentUploadService.ts b/fluxer_api/src/api/channel/services/AttachmentUploadService.ts
index 7e6dcd9a8..c45ca71e6 100644
--- a/fluxer_api/src/api/channel/services/AttachmentUploadService.ts
+++ b/fluxer_api/src/api/channel/services/AttachmentUploadService.ts
@@ -28,9 +28,8 @@ import type {ThreadViewer} from '@app/api/experiment/ChannelThreadsGate';
import type {IPurgeQueue} from '@app/api/infrastructure/CachePurgeQueue';
import type {IGatewayService} from '@app/api/infrastructure/IGatewayService';
import type {IStorageService} from '@app/api/infrastructure/IStorageService';
+import {resolveAttachmentMaxFileSize} from '@app/api/limits/AttachmentFileSizeLimit';
import type {LimitConfigService} from '@app/api/limits/LimitConfigService';
-import {resolveLimitSafe} from '@app/api/limits/LimitConfigUtils';
-import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder';
import type {RequestCache} from '@app/api/middleware/RequestCacheMiddleware';
import type {Attachment} from '@app/api/models/Attachment';
import type {Channel} from '@app/api/models/Channel';
@@ -40,8 +39,6 @@ import {assertGuildMemberCanCommunicate} from '@app/api/utils/GuildCommunication
import {Permissions, TEXT_BASED_CHANNEL_TYPES} from '@fluxer/constants/src/ChannelConstants';
import {GuildOperations} from '@fluxer/constants/src/GuildConstants';
import {
- ATTACHMENT_MAX_SIZE_BOT,
- ATTACHMENT_MAX_SIZE_NON_PREMIUM,
ATTACHMENT_UPLOAD_CHUNK_THRESHOLD,
ATTACHMENT_UPLOAD_MAX_CHUNKS,
resolveAttachmentUploadPartSize,
@@ -511,12 +508,10 @@ export class AttachmentUploadService {
if (!user) {
throw new UnknownUserError();
}
- const fallbackMaxSize = ATTACHMENT_MAX_SIZE_NON_PREMIUM;
- const ctx = createLimitMatchContext({user, guildFeatures: guild?.features ?? null});
- const resolvedMaxFileSize = Math.floor(
- resolveLimitSafe(this.limitConfigService.getConfigSnapshot(), ctx, 'max_attachment_file_size', fallbackMaxSize),
- );
- const maxFileSize = user.isBot ? Math.min(resolvedMaxFileSize, ATTACHMENT_MAX_SIZE_BOT) : resolvedMaxFileSize;
+ const maxFileSize = resolveAttachmentMaxFileSize(this.limitConfigService.getConfigSnapshot(), {
+ user,
+ guildFeatures: guild?.features ?? null,
+ });
return {maxFileSize, assertCanAttachFiles};
}
diff --git a/fluxer_api/src/api/channel/services/message/MessagePersistenceService.ts b/fluxer_api/src/api/channel/services/message/MessagePersistenceService.ts
index 3f7e40788..5646c2f85 100644
--- a/fluxer_api/src/api/channel/services/message/MessagePersistenceService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessagePersistenceService.ts
@@ -32,9 +32,8 @@ import type {EmbedService} from '@app/api/infrastructure/EmbedService';
import type {IMediaService, MediaProxyNsfwMode} from '@app/api/infrastructure/IMediaService';
import type {ISnowflakeService} from '@app/api/infrastructure/ISnowflakeService';
import type {IStorageService} from '@app/api/infrastructure/IStorageService';
+import {resolveAttachmentMaxFileSize} from '@app/api/limits/AttachmentFileSizeLimit';
import type {LimitConfigService} from '@app/api/limits/LimitConfigService';
-import {resolveLimitSafe} from '@app/api/limits/LimitConfigUtils';
-import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder';
import type {Channel} from '@app/api/models/Channel';
import type {Message} from '@app/api/models/Message';
import type {MessageSnapshot} from '@app/api/models/MessageSnapshot';
@@ -42,7 +41,6 @@ import type {User} from '@app/api/models/User';
import type {ReadStateService} from '@app/api/read_state/ReadStateService';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
import {MessageFlags, Permissions, SENDABLE_MESSAGE_FLAGS} from '@fluxer/constants/src/ChannelConstants';
-import {ATTACHMENT_MAX_SIZE_NON_PREMIUM} from '@fluxer/constants/src/LimitConstants';
import {UserFlags} from '@fluxer/constants/src/UserConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
@@ -479,16 +477,10 @@ export class MessagePersistenceService {
'Attachment upload actor must be resolved before processing new attachments',
);
const uploader = await this.userRepository.findUnique(uploadUserId);
- const guildFeatures = guild?.features ?? null;
- const maxFileSize = Math.floor(
- resolveLimitSafe(
- this.limitConfigService.getConfigSnapshot(),
- createLimitMatchContext({user: uploader, guildFeatures}),
- 'max_attachment_file_size',
- ATTACHMENT_MAX_SIZE_NON_PREMIUM,
- guildFeatures ? 'guild' : 'user',
- ),
- );
+ const maxFileSize = resolveAttachmentMaxFileSize(this.limitConfigService.getConfigSnapshot(), {
+ user: uploader,
+ guildFeatures: guild?.features ?? null,
+ });
const uploadedSizes: Array<number> = [];
for (const [index, attachment] of newAttachments.entries()) {
const uploadedFile = await this.storageService.getObjectMetadata(
diff --git a/fluxer_api/src/api/channel/services/message/MessageValidationService.ts b/fluxer_api/src/api/channel/services/message/MessageValidationService.ts
index 486110629..eaa518096 100644
--- a/fluxer_api/src/api/channel/services/message/MessageValidationService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageValidationService.ts
@@ -4,6 +4,7 @@ import type {UserID} from '@app/api/BrandedTypes';
import type {MessageRequest, MessageUpdateRequest} from '@app/api/channel/MessageTypes';
import {assertAttachmentFileSizesWithinLimit} from '@app/api/channel/services/message/MessageHelpers';
import {contentModerationService} from '@app/api/infrastructure/ContentModerationService';
+import {resolveAttachmentMaxFileSize} from '@app/api/limits/AttachmentFileSizeLimit';
import type {LimitConfigService} from '@app/api/limits/LimitConfigService';
import {resolveLimitSafe} from '@app/api/limits/LimitConfigUtils';
import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder';
@@ -17,7 +18,6 @@ import {
SENDABLE_MESSAGE_FLAGS,
} from '@fluxer/constants/src/ChannelConstants';
import {
- ATTACHMENT_MAX_SIZE_NON_PREMIUM,
MAX_ATTACHMENTS_PER_MESSAGE,
MAX_EMBEDS_PER_MESSAGE,
MAX_MESSAGE_LENGTH_NON_PREMIUM,
@@ -161,18 +161,10 @@ export class MessageValidationService {
user: User,
guildFeatures?: Iterable<string> | null,
): void {
- const ctx = createLimitMatchContext({user, guildFeatures});
- const evaluationContext = guildFeatures ? 'guild' : 'user';
- const fallbackMaxSize = ATTACHMENT_MAX_SIZE_NON_PREMIUM;
- const maxFileSize = Math.floor(
- resolveLimitSafe(
- this.limitConfigService.getConfigSnapshot(),
- ctx,
- 'max_attachment_file_size',
- fallbackMaxSize,
- evaluationContext,
- ),
- );
+ const maxFileSize = resolveAttachmentMaxFileSize(this.limitConfigService.getConfigSnapshot(), {
+ user,
+ guildFeatures,
+ });
assertAttachmentFileSizesWithinLimit(
attachments.map(({size}) => size),
maxFileSize,
diff --git a/fluxer_api/src/api/limits/AttachmentFileSizeLimit.ts b/fluxer_api/src/api/limits/AttachmentFileSizeLimit.ts
new file mode 100644
index 000000000..e95db1d24
--- /dev/null
+++ b/fluxer_api/src/api/limits/AttachmentFileSizeLimit.ts
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {resolveLimitSafe} from '@app/api/limits/LimitConfigUtils';
+import {createLimitMatchContext} from '@app/api/limits/LimitMatchContextBuilder';
+import type {User} from '@app/api/models/User';
+import {ATTACHMENT_MAX_SIZE_BOT, ATTACHMENT_MAX_SIZE_NON_PREMIUM} from '@fluxer/constants/src/LimitConstants';
+import type {LimitConfigSnapshot} from '@fluxer/limits/src/LimitTypes';
+
+export function resolveAttachmentMaxFileSize(
+ snapshot: LimitConfigSnapshot | null | undefined,
+ {user, guildFeatures}: {user: User | null; guildFeatures?: Iterable<string> | null},
+): number {
+ const ctx = createLimitMatchContext({user, guildFeatures});
+ const evaluationContext = guildFeatures ? 'guild' : 'user';
+ const maxFileSize = Math.floor(
+ resolveLimitSafe(snapshot, ctx, 'max_attachment_file_size', ATTACHMENT_MAX_SIZE_NON_PREMIUM, evaluationContext),
+ );
+ if (!user?.isBot) {
+ return maxFileSize;
+ }
+ const maxBotFileSize = Math.floor(
+ resolveLimitSafe(snapshot, ctx, 'max_bot_attachment_file_size', ATTACHMENT_MAX_SIZE_BOT, evaluationContext),
+ );
+ return Math.min(maxFileSize, maxBotFileSize);
+}
diff --git a/fluxer_api/src/api/limits/tests/AttachmentFileSizeLimit.test.ts b/fluxer_api/src/api/limits/tests/AttachmentFileSizeLimit.test.ts
new file mode 100644
index 000000000..59ec0b58f
--- /dev/null
+++ b/fluxer_api/src/api/limits/tests/AttachmentFileSizeLimit.test.ts
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {resolveAttachmentMaxFileSize} from '@app/api/limits/AttachmentFileSizeLimit';
+import type {User} from '@app/api/models/User';
+import {
+ ATTACHMENT_MAX_SIZE_BOT,
+ ATTACHMENT_MAX_SIZE_NON_PREMIUM,
+ ATTACHMENT_MAX_SIZE_PREMIUM,
+} from '@fluxer/constants/src/LimitConstants';
+import {DEFAULT_RESTRICTED_LIMITS, DEFAULT_STOCK_LIMITS} from '@fluxer/limits/src/LimitDefaults';
+import type {LimitConfigSnapshot, LimitRule} from '@fluxer/limits/src/LimitTypes';
+import {describe, expect, it} from 'vitest';
+
+const MIB = 1024 * 1024;
+
+function account(isBot: boolean, traits: Array<string> = []): User {
+ return {
+ isBot,
+ traits: new Set(traits),
+ premiumType: null,
+ premiumUntil: null,
+ premiumFlags: 0,
+ premiumGiftExtensionEndsAt: null,
+ premiumGraceEndsAt: null,
+ } as unknown as User;
+}
+
+function snapshot(extraRules: Array<LimitRule> = []): LimitConfigSnapshot {
+ return {
+ traitDefinitions: ['premium', 'uploader'],
+ rules: [
+ {id: 'default', limits: {...DEFAULT_RESTRICTED_LIMITS}},
+ {id: 'premium', filters: {traits: ['premium']}, limits: {...DEFAULT_STOCK_LIMITS}},
+ ...extraRules,
+ ],
+ };
+}
+
+describe('resolveAttachmentMaxFileSize', () => {
+ it('gives bots the premium rule capped at the bot default', () => {
+ expect(resolveAttachmentMaxFileSize(snapshot(), {user: account(true)})).toBe(ATTACHMENT_MAX_SIZE_BOT);
+ expect(resolveAttachmentMaxFileSize(snapshot(), {user: account(false)})).toBe(ATTACHMENT_MAX_SIZE_NON_PREMIUM);
+ });
+
+ it('gives a bot the lower of the two keys', () => {
+ const raised = snapshot([
+ {id: 'uploader', filters: {traits: ['uploader']}, limits: {max_bot_attachment_file_size: 2000 * MIB}},
+ ]);
+
+ expect(resolveAttachmentMaxFileSize(raised, {user: account(true, ['uploader'])})).toBe(ATTACHMENT_MAX_SIZE_PREMIUM);
+ expect(resolveAttachmentMaxFileSize(raised, {user: account(true)})).toBe(ATTACHMENT_MAX_SIZE_BOT);
+ });
+
+ it('applies guild feature rules to the bot key', () => {
+ const guildRule = snapshot([
+ {id: 'big', filters: {guildFeatures: ['BIG_UPLOADS']}, limits: {max_bot_attachment_file_size: 200 * MIB}},
+ ]);
+
+ expect(resolveAttachmentMaxFileSize(guildRule, {user: account(true), guildFeatures: ['BIG_UPLOADS']})).toBe(
+ 200 * MIB,
+ );
+ expect(resolveAttachmentMaxFileSize(guildRule, {user: account(true), guildFeatures: []})).toBe(
+ ATTACHMENT_MAX_SIZE_BOT,
+ );
+ });
+
+ it('falls back to the constants without a snapshot', () => {
+ expect(resolveAttachmentMaxFileSize(null, {user: account(true)})).toBe(ATTACHMENT_MAX_SIZE_NON_PREMIUM);
+ });
+});
diff --git a/fluxer_api/src/api/limits/tests/BotAttachmentFileSizeLimit.test.ts b/fluxer_api/src/api/limits/tests/BotAttachmentFileSizeLimit.test.ts
new file mode 100644
index 000000000..4021f49fa
--- /dev/null
+++ b/fluxer_api/src/api/limits/tests/BotAttachmentFileSizeLimit.test.ts
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {createTestAccount, setUserACLs, type TestAccount} from '@app/api/auth/tests/AuthTestUtils';
+import {authorizeBot, createTestBotAccount} from '@app/api/bot/tests/BotTestUtils';
+import {getConfig} from '@app/api/Config';
+import {createMultipartFormData} from '@app/api/channel/tests/AttachmentTestUtils';
+import {createGuild} from '@app/api/guild/tests/GuildTestUtils';
+import {getCachedInstancePremiumMode, setCachedInstancePremiumMode} from '@app/api/limits/InstancePremiumModeCache';
+import {ensureSessionStarted} from '@app/api/message/tests/MessageTestUtils';
+import {setInjectedMediaService} from '@app/api/middleware/ServiceRegistry';
+import {getInstanceConfigRepository} from '@app/api/middleware/ServiceSingletons';
+import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';
+import {TestMediaService} from '@app/api/test/TestMediaService';
+import {createBuilder} from '@app/api/test/TestRequestBuilder';
+import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
+import {Permissions} from '@fluxer/constants/src/ChannelConstants';
+import type {LimitConfigGetResponse} from '@fluxer/schema/src/domains/admin/AdminSchemas';
+import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
+import type {z} from 'zod';
+
+type LimitConfigResponse = z.infer<typeof LimitConfigGetResponse>;
+
+const MIB = 1024 * 1024;
+
+describe('bot attachment file size limit', () => {
+ let harness: ApiTestHarness;
+ let admin: TestAccount;
+ let owner: TestAccount;
+ let channelId: string;
+ let botToken: string;
+ let originalSelfHosted: boolean;
+ let originalPresigned: boolean;
+ let originalPremiumMode: ReturnType<typeof getCachedInstancePremiumMode>;
+
+ beforeAll(async () => {
+ originalSelfHosted = getConfig().instance.selfHosted;
+ originalPresigned = getConfig().presignedAttachmentUploadsEnabled;
+ originalPremiumMode = getCachedInstancePremiumMode();
+ getConfig().instance.selfHosted = true;
+ getConfig().presignedAttachmentUploadsEnabled = true;
+ harness = await createApiTestHarness();
+ });
+
+ beforeEach(async () => {
+ await harness.reset();
+ setInjectedMediaService(new TestMediaService(harness.storageService));
+ await getInstanceConfigRepository().setAppPublicConfig({setup: {configured: true}});
+ admin = await setUserACLs(harness, await createTestAccount(harness), [
+ AdminACLs.AUTHENTICATE,
+ AdminACLs.INSTANCE_CONFIG_UPDATE,
+ AdminACLs.INSTANCE_LIMIT_CONFIG_VIEW,
+ AdminACLs.INSTANCE_LIMIT_CONFIG_UPDATE,
+ ]);
+ await createBuilder(harness, admin.token)
+ .patch('/admin/instance/config')
+ .body({policy: {premium_mode: 'everyone'}})
+ .execute();
+ owner = await createTestAccount(harness);
+ await ensureSessionStarted(harness, owner.token);
+ const guild = await createGuild(harness, owner.token, 'Bot Upload Guild');
+ channelId = guild.system_channel_id!;
+ const bot = await createTestBotAccount(harness);
+ await authorizeBot(harness, owner.token, bot.appId, ['bot'], guild.id, Permissions.ADMINISTRATOR.toString());
+ botToken = `Bot ${bot.botToken}`;
+ });
+
+ afterAll(async () => {
+ await harness.shutdown();
+ getConfig().instance.selfHosted = originalSelfHosted;
+ getConfig().presignedAttachmentUploadsEnabled = originalPresigned;
+ setCachedInstancePremiumMode(originalPremiumMode);
+ });
+
+ async function setDefaultRuleLimit(key: string, value: number): Promise<number> {
+ const {limit_config: config} = await createBuilder<LimitConfigResponse>(harness, admin.token)
+ .get('/admin/limit-config')
+ .execute();
+ const {response} = await createBuilder(harness, admin.token)
+ .put('/admin/limit-config')
+ .body({
+ limit_config: {
+ traitDefinitions: config.traitDefinitions,
+ rules: config.rules.map(({modifiedFields: _modifiedFields, ...rule}) =>
+ rule.id === 'default' ? {...rule, limits: {...rule.limits, [key]: value}} : rule,
+ ),
+ },
+ })
+ .executeRaw();
+ return response.status;
+ }
+
+ async function sendFormData(token: string, size: number): Promise<number> {
+ const {body, contentType} = createMultipartFormData(
+ {content: 'upload', attachments: [{id: 0, filename: 'file.bin'}]},
+ [{index: 0, filename: 'file.bin', data: Buffer.alloc(size)}],
+ );
+ const response = await harness.app.request(`/channels/${channelId}/messages`, {
+ method: 'POST',
+ headers: {Authorization: token, 'Content-Type': contentType, 'x-forwarded-for': '127.0.0.1'},
+ body,
+ });
+ return response.status;
+ }
+
+ async function requestPresigned(token: string, size: number): Promise<{status: number; code?: string}> {
+ const {response, json} = await createBuilder<{code?: string}>(harness, token)
+ .post(`/channels/${channelId}/attachments`)
+ .body({attachments: [{id: 0, filename: 'file.bin', file_size: size, content_type: 'application/octet-stream'}]})
+ .executeRaw();
+ return {status: response.status, code: json?.code};
+ }
+
+ const tooLarge = {status: 400, code: 'FILE_SIZE_TOO_LARGE'};
+ const accepted = {status: 200, code: undefined};
+
+ it('keeps bots at 50 MiB by default', async () => {
+ expect(await sendFormData(botToken, 51 * MIB)).toBe(400);
+ expect(await requestPresigned(botToken, 51 * MIB)).toEqual(tooLarge);
+ });
+
+ it('lets an admin raise the bot limit in the default rule', async () => {
+ expect(await setDefaultRuleLimit('max_bot_attachment_file_size', 200 * MIB)).toBe(200);
+
+ expect(await sendFormData(botToken, 60 * MIB)).toBe(200);
+ expect(await requestPresigned(botToken, 60 * MIB)).toEqual(accepted);
+ expect(await requestPresigned(botToken, 201 * MIB)).toEqual(tooLarge);
+ });
+
+ it('does not apply the bot limit to people', async () => {
+ expect(await requestPresigned(owner.token, 400 * MIB)).toEqual(accepted);
+ });
+});
diff --git a/fluxer_docs/src/content/docs/http-api/instance.mdx b/fluxer_docs/src/content/docs/http-api/instance.mdx
index 7993a7ab3..97ea773c9 100644
--- a/fluxer_docs/src/content/docs/http-api/instance.mdx
+++ b/fluxer_docs/src/content/docs/http-api/instance.mdx
@@ -354,6 +354,7 @@ A `feature_` key is `1` when the feature is available and `0` when it isn't. The
| max_attachments_per_message | Maximum attachments per message (user and guild) |
| max_bio_length | Maximum characters in a bio, at most 320 (user) |
| max_bookmarks | Maximum bookmarked messages (user) |
+| max_bot_attachment_file_size | Maximum size of each attachment a bot uploads in bytes, 52428800 by default. A bot gets the lower of this and `max_attachment_file_size` (user and guild) |
| max_channels_per_category | Maximum channels per category (guild) |
| max_custom_backgrounds | Maximum custom profile backgrounds (user) |
| max_embeds_per_message | Maximum embeds per message (user and guild) |
diff --git a/fluxer_docs/src/content/docs/http-api/messages.mdx b/fluxer_docs/src/content/docs/http-api/messages.mdx
index eebc19c3f..db4a018ce 100644
--- a/fluxer_docs/src/content/docs/http-api/messages.mdx
+++ b/fluxer_docs/src/content/docs/http-api/messages.mdx
@@ -784,7 +784,7 @@ The rate limit is 100 requests per 10 seconds, on the `channel:message:read::cha
Returns upload URLs for 1 to 10 files, as described in [Attachment upload objects](#attachment-upload-objects). In a guild channel you need `SEND_MESSAGES` and `ATTACH_FILES`.
-Each file can be up to the [`max_attachment_file_size`](/http-api/instance/#limit-keys) limit, which defaults to 524288000 bytes (500 MiB), or 26214400 bytes (25 MiB) without premium on an instance with premium tiers. Bots get at most 52428800 bytes (50 MiB).
+Each file can be up to the [`max_attachment_file_size`](/http-api/instance/#limit-keys) limit, which defaults to 524288000 bytes (500 MiB), or 26214400 bytes (25 MiB) without premium on an instance with premium tiers. A bot gets the lower of that limit and [`max_bot_attachment_file_size`](/http-api/instance/#limit-keys), which defaults to 52428800 bytes (50 MiB).
### JSON body
diff --git a/packages/constants/src/LimitConfigMetadata.ts b/packages/constants/src/LimitConfigMetadata.ts
index b33db1a86..e5b6c31fe 100644
--- a/packages/constants/src/LimitConfigMetadata.ts
+++ b/packages/constants/src/LimitConfigMetadata.ts
@@ -24,6 +24,7 @@ export const LIMIT_KEYS = [
'max_attachments_per_message',
'max_bio_length',
'max_bookmarks',
+ 'max_bot_attachment_file_size',
'max_channels_per_category',
'max_custom_backgrounds',
'max_embeds_per_message',
@@ -77,6 +78,7 @@ export const LIMIT_KEY_SCOPES: Record<LimitKey, LimitScope> = {
max_attachments_per_message: 'both',
max_bio_length: 'user',
max_bookmarks: 'user',
+ max_bot_attachment_file_size: 'both',
max_channels_per_category: 'guild',
max_custom_backgrounds: 'user',
max_embeds_per_message: 'both',
@@ -369,12 +371,23 @@ export const LIMIT_KEY_METADATA: Record<LimitKey, LimitKeyMetadata> = {
key: 'max_attachment_file_size',
label: 'Max Attachment File Size',
description:
- 'Maximum size of each attachment file. Above 500 MiB, also raise FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES on the media proxy',
+ 'Maximum size of each attachment file. The upload relay limit FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES applies to each upload part, so it only matters for files above about 10 GB',
category: 'files',
scope: 'both',
isToggle: false,
unit: 'bytes',
},
+ max_bot_attachment_file_size: {
+ key: 'max_bot_attachment_file_size',
+ label: 'Max Bot Attachment File Size',
+ description:
+ 'Maximum size of each attachment file a bot uploads. A bot gets the lower of this and Max Attachment File Size',
+ category: 'files',
+ scope: 'both',
+ isToggle: false,
+ unit: 'bytes',
+ min: 0,
+ },
avatar_max_size: {
key: 'avatar_max_size',
label: 'Avatar Max Size',
diff --git a/packages/limits/src/LimitDefaults.ts b/packages/limits/src/LimitDefaults.ts
index 127f656bc..13bde2979 100644
--- a/packages/limits/src/LimitDefaults.ts
+++ b/packages/limits/src/LimitDefaults.ts
@@ -2,6 +2,7 @@
import type {LimitKey} from '@fluxer/constants/src/LimitConfigMetadata';
import {
+ ATTACHMENT_MAX_SIZE_BOT,
ATTACHMENT_MAX_SIZE_NON_PREMIUM,
ATTACHMENT_MAX_SIZE_PREMIUM,
AVATAR_MAX_SIZE,
@@ -59,6 +60,7 @@ export const DEFAULT_RESTRICTED_LIMITS: Record<LimitKey, number> = {
max_attachments_per_message: MAX_ATTACHMENTS_PER_MESSAGE,
max_bio_length: MAX_BIO_LENGTH,
max_bookmarks: MAX_BOOKMARKS_NON_PREMIUM,
+ max_bot_attachment_file_size: ATTACHMENT_MAX_SIZE_BOT,
max_channels_per_category: MAX_CHANNELS_PER_CATEGORY,
max_custom_backgrounds: 1,
max_embeds_per_message: MAX_EMBEDS_PER_MESSAGE,