huridocs / uwazi

Uwazi is a web-based, open-source solution for building and sharing document collections
http://www.uwazi.io
MIT License
242 stars 80 forks source link

Public form with media fields not doing cleanup #6986

Closed Zasa-san closed 4 months ago

Zasa-san commented 4 months ago

Public forms are not removing locally stored media files after successfully finishing a submit. We are using object urls https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static to show new media files in the form fields (like we do for the metadata form). After a submission is done we should remove these objects from memory to avoid problems with the browsers' storage.

The public form is calling the cleanup method with the incorrect parameter (it should be the object url itself) at the incorrect time (it's calling it before submitting, so if the submission fails due to an incorrect captcha it would remove the object url causing problems for the next submit attempt).

https://github.com/huridocs/uwazi/blob/b014e7ae462a9abd204030cd83d582d5c684809a/app/react/Metadata/helpers/wrapper.js#L39

Currently this is not breaking the public forms since we are not really deleting the object URL, so even if the user enters the wrong captcha, the object will remain in memory for the next submission attempt. But to fix the cleanup process we also need to delete these objects at the correct time (likely once the submission has successfully completed)

mfacar commented 4 months ago

6990 revokes the resource from URL, as part of resetting the form after a successful submit