Skip to content

Commit

Permalink
fix: the download's key for files with the same filename (#5534)
Browse files Browse the repository at this point in the history
* fix: the download's key for files with the same filename

* refactor the functions to sanitize the strings

* chore: remove useless change

---------

Co-authored-by: GleidsonDaniel <[email protected]>
  • Loading branch information
reinaldonetof and dnlsilva authored Feb 22, 2024
1 parent 645b188 commit 2389a27
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions app/lib/methods/handleMediaDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ const defaultType = {

export const LOCAL_DOCUMENT_DIRECTORY = FileSystem.documentDirectory;

const sanitizeString = (value: string) => {
const urlWithoutQueryString = value.split('?')[0];
return sanitizeLikeString(urlWithoutQueryString.substring(urlWithoutQueryString.lastIndexOf('/') + 1));
};

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

const sanitizeFileName = (value: string) => {
const extension = value.substring(value.lastIndexOf('.') + 1);
const toSanitize = value.substring(0, value.lastIndexOf('.'));
return `${sanitizeString(toSanitize)}.${extension}`;
return `${sanitizeLikeString(toSanitize)}.${extension}`;
};

export const getFilename = ({
Expand Down Expand Up @@ -181,7 +176,7 @@ export const deleteMediaFiles = async (serverUrl: string): Promise<void> => {

const downloadQueue: { [index: string]: FileSystem.DownloadResumable } = {};

export const mediaDownloadKey = (messageUrl: string) => `${sanitizeString(messageUrl)}`;
export const mediaDownloadKey = (messageUrl: string) => `${sanitizeLikeString(messageUrl)}`;

export function isDownloadActive(messageUrl: string): boolean {
return !!downloadQueue[mediaDownloadKey(messageUrl)];
Expand Down

0 comments on commit 2389a27

Please sign in to comment.