Skip to content

Commit a0e74e6

Browse files
DominicGBauerDominicGBauer
andauthored
feat(attachments)!: cater for subdirectories in storage (#78)
* feat(attachments): cater for subdirectorires in storage * fix: changelog * chore: make mediaType configurable in example and demo --------- Co-authored-by: DominicGBauer <dominic@nomanini.com>
1 parent 49dd2c2 commit a0e74e6

File tree

10 files changed

+120
-115
lines changed

10 files changed

+120
-115
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class _TakePhotoWidgetState extends State<TakePhotoWidget> {
5858
int photoSize = await photo.length();
5959

6060
TodoItem.addPhoto(photoId, widget.todoId);
61-
attachmentQueue.savePhoto(photoId, photoSize);
61+
attachmentQueue.saveFile(photoId, photoSize);
6262
} catch (e) {
6363
log.info('Error taking photo: $e');
6464
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
3939
}
4040

4141
@override
42-
Future<Attachment> savePhoto(String photoId, int size) async {
43-
String filename = '$photoId.jpg';
42+
Future<Attachment> saveFile(String fileId, int size,
43+
{mediaType = 'image/jpeg'}) async {
44+
String filename = '$fileId.jpg';
45+
4446
Attachment photoAttachment = Attachment(
45-
id: photoId,
47+
id: fileId,
4648
filename: filename,
4749
state: AttachmentState.queuedUpload.index,
48-
mediaType: 'image/jpeg',
50+
mediaType: mediaType,
4951
localUri: getLocalFilePathSuffix(filename),
5052
size: size,
5153
);
@@ -54,10 +56,11 @@ class PhotoAttachmentQueue extends AbstractAttachmentQueue {
5456
}
5557

5658
@override
57-
Future<Attachment> deletePhoto(String photoId) async {
58-
String filename = '$photoId.jpg';
59+
Future<Attachment> deleteFile(String fileId) async {
60+
String filename = '$fileId.jpg';
61+
5962
Attachment photoAttachment = Attachment(
60-
id: photoId,
63+
id: fileId,
6164
filename: filename,
6265
state: AttachmentState.queuedDelete.index);
6366

demos/supabase-todolist/lib/widgets/todo_item_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TodoItemWidget extends StatelessWidget {
2323

2424
Future<void> deleteTodo(TodoItem todo) async {
2525
if (todo.photoId != null) {
26-
attachmentQueue.deletePhoto(todo.photoId!);
26+
attachmentQueue.deleteFile(todo.photoId!);
2727
}
2828
await todo.delete();
2929
}

0 commit comments

Comments
 (0)