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:
parent
645b188df8
commit
2389a2790b
|
@ -18,17 +18,12 @@ const defaultType = {
|
||||||
|
|
||||||
export const LOCAL_DOCUMENT_DIRECTORY = FileSystem.documentDirectory;
|
export const LOCAL_DOCUMENT_DIRECTORY = FileSystem.documentDirectory;
|
||||||
|
|
||||||
const sanitizeString = (value: string) => {
|
const serverUrlParsedAsPath = (serverURL: string) => `${sanitizeLikeString(serverURL)}/`;
|
||||||
const urlWithoutQueryString = value.split('?')[0];
|
|
||||||
return sanitizeLikeString(urlWithoutQueryString.substring(urlWithoutQueryString.lastIndexOf('/') + 1));
|
|
||||||
};
|
|
||||||
|
|
||||||
const serverUrlParsedAsPath = (serverURL: string) => `${sanitizeString(serverURL)}/`;
|
|
||||||
|
|
||||||
const sanitizeFileName = (value: string) => {
|
const sanitizeFileName = (value: string) => {
|
||||||
const extension = value.substring(value.lastIndexOf('.') + 1);
|
const extension = value.substring(value.lastIndexOf('.') + 1);
|
||||||
const toSanitize = value.substring(0, value.lastIndexOf('.'));
|
const toSanitize = value.substring(0, value.lastIndexOf('.'));
|
||||||
return `${sanitizeString(toSanitize)}.${extension}`;
|
return `${sanitizeLikeString(toSanitize)}.${extension}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFilename = ({
|
export const getFilename = ({
|
||||||
|
@ -181,7 +176,7 @@ export const deleteMediaFiles = async (serverUrl: string): Promise<void> => {
|
||||||
|
|
||||||
const downloadQueue: { [index: string]: FileSystem.DownloadResumable } = {};
|
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 {
|
export function isDownloadActive(messageUrl: string): boolean {
|
||||||
return !!downloadQueue[mediaDownloadKey(messageUrl)];
|
return !!downloadQueue[mediaDownloadKey(messageUrl)];
|
||||||
|
|
Loading…
Reference in New Issue