fix: Bug - Files lose host on reload
Persist large uploads under app data on publish and restore, and re-announce hosted attachments after reload so peers can download again. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
getWatchedAttachmentRoomIdFromUrl,
|
||||
isDirectMessageAttachmentRoomId,
|
||||
shouldCopyUploaderMediaToAppData,
|
||||
shouldCopyLargeUploaderFileToAppData,
|
||||
shouldStreamAttachmentReceiveToDisk,
|
||||
canReceiveAttachment
|
||||
} from './attachment.logic';
|
||||
@@ -35,6 +36,16 @@ describe('attachment logic', () => {
|
||||
}, '/home/ludde/video.mp4', true)).toBe(true);
|
||||
});
|
||||
|
||||
it('copies any oversized upload with a source path into app data', () => {
|
||||
expect(shouldCopyLargeUploaderFileToAppData({
|
||||
size: 628 * 1024 * 1024
|
||||
}, '/home/ludde/setup.exe', true)).toBe(true);
|
||||
|
||||
expect(shouldCopyLargeUploaderFileToAppData({
|
||||
size: 1024
|
||||
}, '/home/ludde/setup.exe', true)).toBe(false);
|
||||
});
|
||||
|
||||
it('skips app-data copy for small uploads and missing source paths', () => {
|
||||
expect(shouldCopyUploaderMediaToAppData({
|
||||
size: 1024,
|
||||
|
||||
@@ -26,10 +26,18 @@ export function shouldCopyUploaderMediaToAppData(
|
||||
attachment: Pick<Attachment, 'size' | 'mime'>,
|
||||
sourcePath?: string | null,
|
||||
canCopyFiles = false
|
||||
): boolean {
|
||||
return shouldCopyLargeUploaderFileToAppData(attachment, sourcePath, canCopyFiles) &&
|
||||
(attachment.mime.startsWith('video/') || attachment.mime.startsWith('audio/'));
|
||||
}
|
||||
|
||||
export function shouldCopyLargeUploaderFileToAppData(
|
||||
attachment: Pick<Attachment, 'size'>,
|
||||
sourcePath?: string | null,
|
||||
canCopyFiles = false
|
||||
): boolean {
|
||||
return canCopyFiles &&
|
||||
!!sourcePath &&
|
||||
(attachment.mime.startsWith('video/') || attachment.mime.startsWith('audio/')) &&
|
||||
!!sourcePath?.trim() &&
|
||||
attachment.size > MAX_AUTO_SAVE_SIZE_BYTES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user