Skip to content

Commit 7ea7b91

Browse files
committed
Restore web support
1 parent c0e5584 commit 7ea7b91

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:path_provider/path_provider.dart';
2+
import 'package:powersync_core/attachments/attachments.dart';
3+
import 'package:powersync_core/attachments/io.dart';
4+
5+
Future<LocalStorage> localAttachmentStorage() async {
6+
final appDocDir = await getApplicationDocumentsDirectory();
7+
return IOLocalStorage(appDocDir);
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:powersync_core/attachments/attachments.dart';
2+
3+
Future<LocalStorage> localAttachmentStorage() async {
4+
// This file is imported on the web, where we don't currently have a
5+
// persistent local storage implementation.
6+
return LocalStorage.inMemory();
7+
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import 'dart:async';
2-
import 'dart:io';
32

43
import 'package:logging/logging.dart';
5-
import 'package:path_provider/path_provider.dart';
64
import 'package:powersync/powersync.dart';
75
import 'package:powersync_core/attachments/attachments.dart';
8-
import 'package:powersync_core/attachments/io.dart';
96

107
import 'package:powersync_flutter_demo/attachments/remote_storage_adapter.dart';
118

9+
import 'local_storage_unsupported.dart'
10+
if (dart.library.io) 'local_storage_native.dart';
11+
1212
late AttachmentQueue attachmentQueue;
1313
final remoteStorage = SupabaseStorageAdapter();
1414
final logger = Logger('AttachmentQueue');
1515

1616
Future<void> initializeAttachmentQueue(PowerSyncDatabase db) async {
17-
// Use the app's document directory for local storage
18-
final Directory appDocDir = await getApplicationDocumentsDirectory();
19-
2017
attachmentQueue = AttachmentQueue(
2118
db: db,
2219
remoteStorage: remoteStorage,
2320
logger: logger,
24-
localStorage: IOLocalStorage(appDocDir),
21+
localStorage: await localAttachmentStorage(),
2522
watchAttachments: () => db.watch('''
2623
SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL
2724
''').map(

packages/powersync_core/test/attachments/attachment_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ void main() {
2424
.map(
2525
(rs) => [
2626
for (final row in rs)
27-
WatchedAttachmentItem(id: row[0] as String, fileExtension: 'jpg')
27+
WatchedAttachmentItem(
28+
id: row['photo_id'] as String, fileExtension: 'jpg')
2829
],
2930
);
3031
}

0 commit comments

Comments
 (0)