Skip to content

Commit ff62ed2

Browse files
committed
feat(attachments): allow watchIds without fileExtension
1 parent 12d6188 commit ff62ed2

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

demos/supabase-todolist-drift/lib/attachments/queue.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
6868
}
6969

7070
@override
71-
StreamSubscription<void> watchIds({String fileExtension = 'jpg'}) {
71+
StreamSubscription<void> watchIds({String? fileExtension}) {
7272
log.info('Watching photos in $todosTable...');
7373
return db.watch('''
7474
SELECT photo_id FROM $todosTable

demos/supabase-todolist/lib/attachments/queue.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
6868
}
6969

7070
@override
71-
StreamSubscription<void> watchIds({String fileExtension = 'jpg'}) {
71+
StreamSubscription<void> watchIds({String? fileExtension}) {
7272
log.info('Watching photos in $todosTable...');
7373
return db.watch('''
7474
SELECT photo_id FROM $todosTable

packages/powersync_attachments_helper/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
6262
// This watcher will handle adding items to the queue based on
6363
// a users table element receiving a photoId
6464
@override
65-
StreamSubscription<void> watchIds({String fileExtension = 'jpg'}) {
65+
StreamSubscription<void> watchIds({String? fileExtension}) {
6666
return db.watch('''
6767
SELECT photo_id FROM users
6868
WHERE photo_id IS NOT NULL

packages/powersync_attachments_helper/example/getting_started.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
4646
}
4747

4848
@override
49-
StreamSubscription<void> watchIds({String fileExtension = 'jpg'}) {
49+
StreamSubscription<void> watchIds({String? fileExtension}) {
5050
return db.watch('''
5151
SELECT photo_id FROM users
5252
WHERE photo_id IS NOT NULL

packages/powersync_attachments_helper/lib/src/attachments_queue.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class AbstractAttachmentQueue {
5959

6060
/// Create watcher to get list of ID's from a table to be used for syncing in the attachment queue.
6161
/// Set the file extension if you are using a different file type
62-
StreamSubscription<void> watchIds({String fileExtension = 'jpg'});
62+
StreamSubscription<void> watchIds({String? fileExtension});
6363

6464
/// Create a function to save files using the attachment queue
6565
Future<Attachment> saveFile(String fileId, int size);
@@ -82,7 +82,7 @@ abstract class AbstractAttachmentQueue {
8282
}
8383
}
8484

85-
watchIds();
85+
watchIds(fileExtension: 'jpg');
8686
syncingService.watchAttachments();
8787
syncingService.startPeriodicSync(intervalInMinutes);
8888

packages/powersync_attachments_helper/lib/src/syncing_service.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ class SyncingService {
165165
}
166166

167167
/// Process ID's to be included in the attachment queue.
168-
Future<void> processIds(List<String> ids, String fileExtension) async {
168+
Future<void> processIds(List<String> ids, String? fileExtension) async {
169169
List<Attachment> attachments = List.empty(growable: true);
170170

171171
for (String id in ids) {
172-
String path = await getLocalUri('$id.$fileExtension');
172+
String filename = fileExtension != null ? '$id.$fileExtension' : id;
173+
String path = await getLocalUri(filename);
173174
File file = File(path);
174175
bool fileExists = await file.exists();
175176

@@ -180,7 +181,7 @@ class SyncingService {
180181
log.info('Adding $id to queue');
181182
attachments.add(Attachment(
182183
id: id,
183-
filename: '$id.$fileExtension',
184+
filename: filename,
184185
state: AttachmentState.queuedDownload.index));
185186
}
186187

0 commit comments

Comments
 (0)