refactor(share): make saveFile content nullable for path-based shares (#4424)
The book "Send" flow had to pass `new ArrayBuffer(0)` to saveFile purely to satisfy the type-checker: the content arg is ignored on the native share path when `options.filePath` points at an already-on-disk file. Widen saveFile's content parameter to `string | ArrayBuffer | null` across the AppService contract so callers can hand off a file by path without buffering it into memory, and pass `null` from the Send flow instead of a throwaway empty buffer. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -107,4 +107,25 @@ describe('NativeAppService.saveFile share gating', () => {
|
||||
expect(shareFileMock).not.toHaveBeenCalled();
|
||||
expect(saveDialogMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
// The book "Send" flow hands an already-on-disk file straight to the share
|
||||
// sheet via `filePath` and passes `null` content so nothing gets re-buffered
|
||||
// into memory. The file at `filePath` must be shared verbatim without any
|
||||
// write happening first.
|
||||
test('shares the file at filePath without buffering when content is null', async () => {
|
||||
const service = await loadServiceWithOS('macos');
|
||||
await service.saveFile('book.epub', null, {
|
||||
share: true,
|
||||
mimeType: 'application/epub+zip',
|
||||
filePath: '/abs/path/book.epub',
|
||||
});
|
||||
expect(shareFileMock).toHaveBeenCalledTimes(1);
|
||||
expect(shareFileMock).toHaveBeenCalledWith(
|
||||
'/abs/path/book.epub',
|
||||
expect.objectContaining({ mimeType: 'application/epub+zip' }),
|
||||
);
|
||||
expect(writeFileMock).not.toHaveBeenCalled();
|
||||
expect(writeTextFileMock).not.toHaveBeenCalled();
|
||||
expect(saveDialogMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user