fix(media): stream large files and honour size settings (#3387)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-11 13:28:24 +02:00
1 parent 6acd7f3d22
commit 45b78a13c2
97 files changed
+2547 -409

No files matched your search

@@ -1,9 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {AVATAR_MAX_SIZE, EMOJI_MAX_SIZE, STICKER_MAX_SIZE} from '@fluxer/constants/src/LimitConstants';
import {
AVATAR_MAX_SIZE,
BASE64_IMAGE_MAX_SIZE,
EMOJI_MAX_SIZE,
STICKER_MAX_SIZE,
} from '@fluxer/constants/src/LimitConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {
base64LengthForBytes,
createBase64ImageType,
createBase64StringType,
FilenameType,
isValidBase64,
@@ -120,6 +126,7 @@ describe('base64LengthForBytes', () => {
[4, 8],
[EMOJI_MAX_SIZE, 699052],
[AVATAR_MAX_SIZE, 13981016],
[BASE64_IMAGE_MAX_SIZE, 139810136],
])('encodes a ceiling of %i bytes in %i characters', (bytes, expected) => {
expect(base64LengthForBytes(bytes)).toBe(expected);
});
@@ -138,3 +145,13 @@ describe('base64LengthForBytes', () => {
},
);
});
describe('createBase64ImageType', () => {
it.each([EMOJI_MAX_SIZE + 1, STICKER_MAX_SIZE * 2, AVATAR_MAX_SIZE + 1])(
'accepts %i decoded bytes so configured size limits above the stock values can apply',
(bytes) => {
const encoded = Buffer.alloc(bytes, 1).toString('base64');
expect(createBase64ImageType().parse(encoded)).toBe(encoded);
},
);
});