SyncingService
Internal
Orchestrates attachment synchronization between local and remote storage. Handles uploads, downloads, deletions, and state transitions.
Constructors
new SyncingService()
new SyncingService(
attachmentService,
localStorage,
remoteStorage,
logger,
errorHandler?): SyncingService
Parameters
| Parameter | Type |
|---|---|
attachmentService | AttachmentService |
localStorage | LocalStorageAdapter |
remoteStorage | RemoteStorageAdapter |
logger | ILogger |
errorHandler? | AttachmentErrorHandler |
Returns
Methods
deleteArchivedAttachments()
deleteArchivedAttachments(context): Promise<boolean>
Performs cleanup of archived attachments by removing their local files and records. Errors during local file deletion are logged but do not prevent record deletion.
Parameters
| Parameter | Type |
|---|---|
context | AttachmentContext |
Returns
Promise<boolean>
deleteAttachment()
deleteAttachment(attachment): Promise<AttachmentRecord>
Deletes an attachment from both remote and local storage. Removes the remote file, local file (if exists), and the attachment record. On failure, defers to error handler or archives.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment record to delete |
Returns
Promise<AttachmentRecord>
Updated attachment record
downloadAttachment()
downloadAttachment(attachment): Promise<AttachmentRecord>
Downloads an attachment from remote storage to local storage. Retrieves the file, converts to base64, and saves locally. On success, marks as SYNCED. On failure, defers to error handler or archives.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment record to download |
Returns
Promise<AttachmentRecord>
Updated attachment record with local URI and new state
processAttachments()
processAttachments(attachments, context): Promise<void>
Processes attachments based on their state (upload, download, or delete). All updates are saved in a single batch after processing.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachments | AttachmentRecord[] | Array of attachment records to process |
context | AttachmentContext | Attachment context for database operations |
Returns
Promise<void>
Promise that resolves when all attachments have been processed and saved
uploadAttachment()
uploadAttachment(attachment): Promise<AttachmentRecord>
Uploads an attachment from local storage to remote storage. On success, marks as SYNCED. On failure, defers to error handler or archives.
Parameters
| Parameter | Type | Description |
|---|---|---|
attachment | AttachmentRecord | The attachment record to upload |
Returns
Promise<AttachmentRecord>
Updated attachment record with new state
Throws
Error if the attachment has no localUri