fix: Bug - Sending files between users doesn't really work
Stream oversized generic attachments to disk instead of silently dropping chunks, avoid loading completed file downloads into renderer memory, and surface a clear error when the browser client cannot receive a file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
getWatchedAttachmentRoomIdFromUrl,
|
||||
isDirectMessageAttachmentRoomId,
|
||||
shouldCopyUploaderMediaToAppData
|
||||
shouldCopyUploaderMediaToAppData,
|
||||
shouldStreamAttachmentReceiveToDisk,
|
||||
canReceiveAttachment
|
||||
} from './attachment.logic';
|
||||
|
||||
describe('attachment logic', () => {
|
||||
@@ -44,4 +46,36 @@ describe('attachment logic', () => {
|
||||
mime: 'video/mp4'
|
||||
}, undefined, true)).toBe(false);
|
||||
});
|
||||
|
||||
it('streams oversized generic files to disk when the store supports it', () => {
|
||||
const capabilities = {
|
||||
canStreamToDisk: true,
|
||||
canPersistSize: (bytes: number) => bytes <= 256 * 1024 * 1024
|
||||
};
|
||||
|
||||
expect(shouldStreamAttachmentReceiveToDisk({
|
||||
size: 200 * 1024 * 1024,
|
||||
mime: 'application/zip',
|
||||
filePath: undefined
|
||||
}, capabilities)).toBe(true);
|
||||
});
|
||||
|
||||
it('receives browser-sized files in memory when disk streaming is unavailable', () => {
|
||||
const browserCapabilities = {
|
||||
canStreamToDisk: false,
|
||||
canPersistSize: (bytes: number) => bytes <= 50 * 1024 * 1024
|
||||
};
|
||||
|
||||
expect(canReceiveAttachment({
|
||||
size: 20 * 1024 * 1024,
|
||||
mime: 'application/zip',
|
||||
filePath: undefined
|
||||
}, browserCapabilities)).toBe(true);
|
||||
|
||||
expect(canReceiveAttachment({
|
||||
size: 200 * 1024 * 1024,
|
||||
mime: 'application/zip',
|
||||
filePath: undefined
|
||||
}, browserCapabilities)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user