Skip to content
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

delete previous image on cover change #6368

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Ahad-patel
Copy link
Contributor

@Ahad-patel Ahad-patel commented Sep 20, 2024

Feature Preview

Closes: #5145

I have created two methods for deletePreviousImageFromCloudStorage and deleteFile in DocumentSevce Class
when ever the user changes cover image the this method will check if there the previous image was file, If so then it will delete the previous image.

I have a question ther is a an method DocumentEventDeleteFile which takes DownloadFilePB payload which has two params localFilePath and url, the url can be obtained from coverDetails but localFilepath is not stored any where how do i delete it from the local storage? @Xazin

PR Checklist

  • My code adheres to AppFlowy's Conventions
  • I've listed at least one issue that this PR fixes in the description above.
  • I've added a test(s) to validate changes in this PR, or this PR only contains semantic changes.
  • All existing tests are passing.

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

@Ahad-patel Ahad-patel changed the title delete previous image on cover change #5145 delete previous image on cover change Sep 20, 2024
@Ahad-patel Ahad-patel marked this pull request as draft September 20, 2024 16:04
@Ahad-patel
Copy link
Contributor Author

Hey @LucasXu0, Is my approach to this issue is correct?

@Ahad-patel Ahad-patel marked this pull request as ready for review October 21, 2024 16:42
@Ahad-patel
Copy link
Contributor Author

@LucasXu0 I also noticed that the local image case was not handled in migrateAttributes so I added it. I am working on test cases now. Please let me know if my approach is correct.

@@ -763,6 +763,7 @@ class DocumentCoverState extends State<DocumentCover> {
}

Future<void> onCoverChanged(CoverType type, String? details) async {
await deletePreviousImageIfNecessary();
Copy link
Collaborator

@Xazin Xazin Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can perform this after changing the cover. (Since it's an asynchronous operation)

@@ -117,3 +117,7 @@ Future<List<ImageBlockData>> extractAndUploadImages(

return images;
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we wrap this in try-catch and at least log errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Xazin Xazin requested a review from LucasXu0 October 21, 2024 19:49
@Ahad-patel
Copy link
Contributor Author

Hey @Xazin, I was trying to add test case in this file => https://github.com/Ahad-patel/AppFlowy/blob/delete-unecessary-images/frontend/appflowy_flutter/integration_test/desktop/document/document_with_cover_image_test.dart#L8-L9, but stuck on how should I approach the local file upload case, Because the file will be present in my machine but might not be availaible in some one else machine, Is there any similar code shoud I look into?

@Ahad-patel
Copy link
Contributor Author

hey @LucasXu0 , @Xazin any updates here?

@LucasXu0
Copy link
Collaborator

@Ahad-patel In my opinion, the deletion seems unable to be mocked in the test. A workaounrd is to add the flag for the test to detect when the delete function is called while changing the cover image. If the function is called, we can assume the deletion takes effect.

@Ahad-patel
Copy link
Contributor Author

Ahad-patel commented Oct 31, 2024

@LucasXu0 , I have added test case for local image upload and added a variable deleteImageTestCounter to test if deleteImageFromLocalStorage function is being called when we remove/change cover image.

@Ahad-patel
Copy link
Contributor Author

@LucasXu0 , please let me know if any more changes required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Delete Unnecessary images from the "Image" folder.
4 participants