-
Notifications
You must be signed in to change notification settings - Fork 29
Relax fileExtension requirement in attachmentQueue #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1d9655e
c6a93ae
aec2014
21d6427
606a5ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import 'package:path_provider/path_provider.dart'; | |
/// Storage adapter for local storage | ||
class LocalStorageAdapter { | ||
Future<File> saveFile(String fileUri, Uint8List data) async { | ||
await makeDir(fileUri); | ||
final file = File(fileUri); | ||
return await file.writeAsBytes(data); | ||
} | ||
|
@@ -30,12 +31,13 @@ class LocalStorageAdapter { | |
Future<void> makeDir(String fileUri) async { | ||
bool exists = await fileExists(fileUri); | ||
if (!exists) { | ||
Directory newDirectory = Directory(fileUri); | ||
await newDirectory.create(recursive: true); | ||
Directory parentDirectories = File(fileUri).parent; | ||
await parentDirectories.create(recursive: true); | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change necessary? Looking at how the method is called in I think creating nested directories automatically is the correct behavior, but then you could call |
||
} | ||
} | ||
|
||
Future<void> copyFile(String sourceUri, String targetUri) async { | ||
await makeDir(targetUri); | ||
File file = File(sourceUri); | ||
await file.copy(targetUri); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,11 +165,12 @@ class SyncingService { | |
} | ||
|
||
/// Process ID's to be included in the attachment queue. | ||
Future<void> processIds(List<String> ids, String fileExtension) async { | ||
Future<void> processIds(List<String> ids, String? fileExtension) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To follow up on Steven's suggestion, we could remove Then here, we could take the extension of each item or fall back to the default extension set on the |
||
List<Attachment> attachments = List.empty(growable: true); | ||
|
||
for (String id in ids) { | ||
String path = await getLocalUri('$id.$fileExtension'); | ||
String filename = fileExtension != null ? '$id.$fileExtension' : id; | ||
String path = await getLocalUri(filename); | ||
File file = File(path); | ||
bool fileExists = await file.exists(); | ||
|
||
|
@@ -180,7 +181,7 @@ class SyncingService { | |
log.info('Adding $id to queue'); | ||
attachments.add(Attachment( | ||
id: id, | ||
filename: '$id.$fileExtension', | ||
filename: filename, | ||
state: AttachmentState.queuedDownload.index)); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that this is already a breaking change, I wonder if we should just remove the parameter entirely and transfer the responsibility to include file extensions in the id instead of supporting both modes.
That would also involve removing the
fileExtension
parameter fromprocessIds
.