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

* 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 <gleidson10daniel@hotmail.com>
This commit is contained in:
Reinaldo Neto 2024-02-22 16:56:42 -03:00 committed by GitHub
parent 645b188df8
commit 2389a2790b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 8 deletions

View File

@ -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 = ({
@ -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)];