Skip to content

Commit 239db5e

Browse files
author
Hein
committed
Added option to download attachments
1 parent 7e23d65 commit 239db5e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/green-waves-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/attachments': minor
3+
---
4+
5+
Added option to download attachments

packages/attachments/src/AbstractAttachmentQueue.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface AttachmentQueueOptions {
2121
* Whether to mark the initial watched attachment IDs to be synced
2222
*/
2323
performInitialSync?: boolean;
24+
/**
25+
* Should attachments be downloaded
26+
*/
27+
downloadAttachments?: boolean;
2428
/**
2529
* How to handle download errors, return { retry: false } to ignore the download
2630
*/
@@ -35,7 +39,8 @@ export const DEFAULT_ATTACHMENT_QUEUE_OPTIONS: Partial<AttachmentQueueOptions> =
3539
attachmentDirectoryName: 'attachments',
3640
syncInterval: 30_000,
3741
cacheLimit: 100,
38-
performInitialSync: true
42+
performInitialSync: true,
43+
downloadAttachments: true
3944
};
4045

4146
export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions = AttachmentQueueOptions> {
@@ -426,6 +431,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
426431
}
427432

428433
watchDownloads() {
434+
if (this.options.downloadAttachments) {
435+
return;
436+
}
429437
this.idsToDownload(async (ids) => {
430438
ids.map((id) => this.downloadQueue.add(id));
431439
// No need to await this, the lock will ensure only one loop is running at a time
@@ -434,6 +442,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
434442
}
435443

436444
private async downloadRecords() {
445+
if (this.options.downloadAttachments) {
446+
return;
447+
}
437448
if (this.downloading) {
438449
return;
439450
}

0 commit comments

Comments
 (0)