Skip to content

Commit

Permalink
remove unecessary images from localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahad-patel committed Oct 17, 2024
1 parent 8ceff03 commit bd9be43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,24 @@ class DocumentCoverState extends State<DocumentCover> {
}

Future<void> onCoverChanged(CoverType type, String? details) async {
if (type == CoverType.file && details != null && !isURL(details)) {
bool isFileType(CoverType type, String? details) =>
type == CoverType.file && details != null && !isURL(details);

if (isFileType(type, details)) {
if (_isLocalMode()) {
details = await saveImageToLocalStorage(details);
final previousType =
widget.node.attributes[DocumentHeaderBlockKeys.coverType];
final previousDetails =
widget.node.attributes[DocumentHeaderBlockKeys.coverDetails];

if (isFileType(previousType, previousDetails)) {
await deleteImageFromLocalStorage(previousDetails);
}

details = await saveImageToLocalStorage(details!);
} else {
// else we should save the image to cloud storage
(details, _) = await saveImageToCloudStorage(details, widget.view.id);
(details, _) = await saveImageToCloudStorage(details!, widget.view.id);
}
}
widget.onChangeCover(type, details);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ Future<List<ImageBlockData>> extractAndUploadImages(

return images;
}

Future<void> deleteImageFromLocalStorage(String localImagePath) async {
await File(localImagePath).delete();
}

0 comments on commit bd9be43

Please sign in to comment.