From 239db5ed2467781e6443974a6af11ab0d3282708 Mon Sep 17 00:00:00 2001 From: Hein Date: Thu, 21 Nov 2024 09:50:06 +0200 Subject: [PATCH] Added option to download attachments --- .changeset/green-waves-rescue.md | 5 +++++ packages/attachments/src/AbstractAttachmentQueue.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/green-waves-rescue.md diff --git a/.changeset/green-waves-rescue.md b/.changeset/green-waves-rescue.md new file mode 100644 index 00000000..a1742c83 --- /dev/null +++ b/.changeset/green-waves-rescue.md @@ -0,0 +1,5 @@ +--- +'@powersync/attachments': minor +--- + +Added option to download attachments diff --git a/packages/attachments/src/AbstractAttachmentQueue.ts b/packages/attachments/src/AbstractAttachmentQueue.ts index 3c3cca02..c6daf866 100644 --- a/packages/attachments/src/AbstractAttachmentQueue.ts +++ b/packages/attachments/src/AbstractAttachmentQueue.ts @@ -21,6 +21,10 @@ export interface AttachmentQueueOptions { * Whether to mark the initial watched attachment IDs to be synced */ performInitialSync?: boolean; + /** + * Should attachments be downloaded + */ + downloadAttachments?: boolean; /** * How to handle download errors, return { retry: false } to ignore the download */ @@ -35,7 +39,8 @@ export const DEFAULT_ATTACHMENT_QUEUE_OPTIONS: Partial = attachmentDirectoryName: 'attachments', syncInterval: 30_000, cacheLimit: 100, - performInitialSync: true + performInitialSync: true, + downloadAttachments: true }; export abstract class AbstractAttachmentQueue { @@ -426,6 +431,9 @@ export abstract class AbstractAttachmentQueue { ids.map((id) => this.downloadQueue.add(id)); // 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