fix: Bug - Local files should be remembered by client
This commit is contained in:
+58
-1
@@ -32,7 +32,9 @@ describe('AttachmentPersistenceService', () => {
|
||||
readFile: ReturnType<typeof vi.fn>;
|
||||
readFileChunk: ReturnType<typeof vi.fn>;
|
||||
getFileSize: ReturnType<typeof vi.fn>;
|
||||
getFileUrl: ReturnType<typeof vi.fn>;
|
||||
canReadFileChunks: ReturnType<typeof vi.fn>;
|
||||
providesInlineObjectUrl: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -60,7 +62,9 @@ describe('AttachmentPersistenceService', () => {
|
||||
readFile: vi.fn(() => Promise.resolve('QUJD')),
|
||||
readFileChunk: vi.fn(() => Promise.resolve('QUJD')),
|
||||
getFileSize: vi.fn(() => Promise.resolve(3)),
|
||||
canReadFileChunks: vi.fn(() => true)
|
||||
getFileUrl: vi.fn(() => Promise.resolve(null)),
|
||||
canReadFileChunks: vi.fn(() => true),
|
||||
providesInlineObjectUrl: vi.fn(() => false)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -112,4 +116,57 @@ describe('AttachmentPersistenceService', () => {
|
||||
expect(attachmentStorage.readFileChunk).toHaveBeenCalled();
|
||||
expect(attachmentStorage.readFile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('restores a blob from a whole-file read when the store cannot read chunks (browser store)', async () => {
|
||||
attachmentStorage.canReadFileChunks.mockReturnValue(false);
|
||||
|
||||
const service = createService();
|
||||
|
||||
await service.initFromDatabase();
|
||||
|
||||
const attachment = {
|
||||
id: 'att-1',
|
||||
messageId: 'msg-1',
|
||||
filename: 'photo.png',
|
||||
size: 3,
|
||||
mime: 'image/png',
|
||||
isImage: true,
|
||||
savedPath: '/appdata/photo.png',
|
||||
available: false
|
||||
};
|
||||
|
||||
await expect(service.ensureInlineDisplayObjectUrl(attachment)).resolves.toBe(true);
|
||||
expect(attachment.available).toBe(true);
|
||||
expect(attachment.objectUrl).toMatch(/^blob:/);
|
||||
expect(attachmentStorage.readFile).toHaveBeenCalledWith('/appdata/photo.png');
|
||||
expect(attachmentStorage.readFileChunk).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses a native webview URL without rebuilding a blob (capacitor store)', async () => {
|
||||
attachmentStorage.providesInlineObjectUrl.mockReturnValue(true);
|
||||
attachmentStorage.resolveExistingPath.mockResolvedValue('metoyou/server/room/video/clip.mp4');
|
||||
attachmentStorage.getFileUrl.mockResolvedValue('capacitor://localhost/_capacitor_file_/clip.mp4');
|
||||
|
||||
const service = createService();
|
||||
|
||||
await service.initFromDatabase();
|
||||
|
||||
const attachment = {
|
||||
id: 'att-1',
|
||||
messageId: 'msg-1',
|
||||
filename: 'clip.mp4',
|
||||
size: 1_024,
|
||||
mime: 'video/mp4',
|
||||
isImage: false,
|
||||
savedPath: 'metoyou/server/room/video/clip.mp4',
|
||||
available: false
|
||||
};
|
||||
|
||||
await expect(service.ensureInlineDisplayObjectUrl(attachment)).resolves.toBe(true);
|
||||
expect(attachment.available).toBe(true);
|
||||
expect(attachment.objectUrl).toBe('capacitor://localhost/_capacitor_file_/clip.mp4');
|
||||
expect(attachmentStorage.getFileUrl).toHaveBeenCalledWith('metoyou/server/room/video/clip.mp4');
|
||||
expect(attachmentStorage.readFile).not.toHaveBeenCalled();
|
||||
expect(attachmentStorage.readFileChunk).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user