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

fix: the download's key for files with the same filename #5534

Merged
merged 5 commits into from
Feb 22, 2024

Conversation

reinaldonetof
Copy link
Contributor

@reinaldonetof reinaldonetof commented Feb 2, 2024

Proposed changes

The error occurred when there were more than 1 file with the same filename, for example:

https://open.rocket.chat/file-upload/ChJDEKZhJHc359rm8/Screenshot%202024-02-14%20at%2019.54.07.png

https://open.rocket.chat/file-upload/4roCoCiHzsxzZzFXv/Screenshot%202024-02-14%20at%2019.54.07.png

The mediaDownloadKey function is responsible for determining the key related to the download object, but it was only capturing the filename from the URL. Thus, when there were 2 files with the same filename, the key was associated with only one, causing the download of the other to appear as if it was also in progress, when in fact, it was referencing the download of the first file. To fix this, I decided not to separate only the filename to use as the key for the object. Instead, I used the complete link as the object key, thus differentiating between each file.

Issue(s)

How to test or reproduce

  • Upload two different files with the same name
  • When them appears in the screen, you need to click one by one almost at the same time
  • Then after the download is done and you click to open the file, you will notice that you are opening the same file
  • One point to consider is: if you exit the channel and reopen it, you will notice that one of the files wasn't downloaded. The download icon will appear, and after clicking to download it, the file should be downloaded as expected.

Screenshots

Before

Screen.Recording.2024-02-01.at.22.21.43.mov

After

Screen.Recording.2024-02-01.at.22.20.32.mov

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

CORE-55

@reinaldonetof reinaldonetof self-assigned this Feb 2, 2024
Copy link
Member

@diegolmello diegolmello left a comment

Choose a reason for hiding this comment

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

I see sanitizeString makes an extra work for URLs, although the function doesn't imply that, and the change to sanitizeLikeString seems to just replace unwanted characters with _.

const sanitizeString = (value: string) => {

You might want to change serverUrlParsedAsPath to sanitizeLikeString as well, just for the sake of semantics

const serverUrlParsedAsPath = (serverURL: string) => `${sanitizeString(serverURL)}/`;

At least I can't see a reason to do that on serverUrl.

I'm also missing a clear description of why sanitizeLikeString is better than sanitizeString and a string as example of what was causing the issue.

@reinaldonetof
Copy link
Contributor Author

You might want to change serverUrlParsedAsPath to sanitizeLikeString as well, just for the sake of semantics

const serverUrlParsedAsPath = (serverURL: string) => `${sanitizeString(serverURL)}/`;

At least I can't see a reason to do that on serverUrl.
I'm also missing a clear description of why sanitizeLikeString is better than sanitizeString and a string as example of what was causing the issue.

The error occurred when there were more than 1 file with the same filename, for example:

https://open.rocket.chat/file-upload/ChJDEKZhJHc359rm8/Screenshot%202024-02-14%20at%2019.54.07.png

https://open.rocket.chat/file-upload/4roCoCiHzsxzZzFXv/Screenshot%202024-02-14%20at%2019.54.07.png

The mediaDownloadKey function is responsible for determining the key related to the download object, but it was only capturing the filename from the URL. Thus, when there were 2 files with the same filename, the key was associated with only one, causing the download of the other to appear as if it was also in progress, when in fact, it was referencing the download of the first file. To fix this, I decided not to separate only the filename to use as the key for the object. Instead, I used the complete link as the object key, thus differentiating between each file.

@diegolmello
Copy link
Member

You might want to change serverUrlParsedAsPath to sanitizeLikeString as well, just for the sake of semantics

const serverUrlParsedAsPath = (serverURL: string) => `${sanitizeString(serverURL)}/`;

At least I can't see a reason to do that on serverUrl.
I'm also missing a clear description of why sanitizeLikeString is better than sanitizeString and a string as example of what was causing the issue.

The error occurred when there were more than 1 file with the same filename, for example:

https://open.rocket.chat/file-upload/ChJDEKZhJHc359rm8/Screenshot%202024-02-14%20at%2019.54.07.png

https://open.rocket.chat/file-upload/4roCoCiHzsxzZzFXv/Screenshot%202024-02-14%20at%2019.54.07.png

The mediaDownloadKey function is responsible for determining the key related to the download object, but it was only capturing the filename from the URL. Thus, when there were 2 files with the same filename, the key was associated with only one, causing the download of the other to appear as if it was also in progress, when in fact, it was referencing the download of the first file. To fix this, I decided not to separate only the filename to use as the key for the object. Instead, I used the complete link as the object key, thus differentiating between each file.

I see now. You're calling the url to the attachment on backend serverUrl.
This naming is used on other places of the app as workspace url, like https://open.rocket.chat
https://github.com/search?q=repo%3ARocketChat%2FRocket.Chat.ReactNative%20serverurl&type=code

@GleidsonDaniel
Copy link
Contributor

GleidsonDaniel commented Feb 22, 2024

The solution is simple, the explanation was unnecessarily complex.
Previously, the sanitizeString function was used to get the name of the file (whoever has a name has nothing to do with what it actually does) and use that name as the download key... Files can have the same name ¯_(ツ)_/¯
With this change, using sanitizeLikeString takes the entire file url as the download key.

@GleidsonDaniel GleidsonDaniel merged commit 2389a27 into develop Feb 22, 2024
4 of 9 checks passed
@GleidsonDaniel GleidsonDaniel deleted the fix.download-same-filename branch February 22, 2024 19:56
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.

None yet

3 participants