forked from Ivasoft/mattermost-mobile
Fix MM-46309 (#6567)
* Fix MM-46309 * Address feedback * Update dbPath and rename server databas instead of deleting * ios fixes Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local>
This commit is contained in:
committed by
GitHub
parent
63e6290c76
commit
ea595f1ced
@@ -18,7 +18,7 @@ import {generateId} from '@utils/general';
|
||||
import keyMirror from '@utils/key_mirror';
|
||||
import {logError} from '@utils/log';
|
||||
import {deleteEntititesFile, getIOSAppGroupDetails} from '@utils/mattermost_managed';
|
||||
import {hashCode} from '@utils/security';
|
||||
import {hashCode_DEPRECATED, urlSafeBase64Encode} from '@utils/security';
|
||||
|
||||
import type FileModel from '@typings/database/models/servers/file';
|
||||
|
||||
@@ -165,8 +165,17 @@ export async function deleteV1Data() {
|
||||
}
|
||||
|
||||
export async function deleteFileCache(serverUrl: string) {
|
||||
const serverDir = hashCode(serverUrl);
|
||||
const cacheDir = `${FileSystem.CachesDirectoryPath}/${serverDir}`;
|
||||
const serverDir = urlSafeBase64Encode(serverUrl);
|
||||
deleteFileCacheByDir(serverDir);
|
||||
}
|
||||
|
||||
export async function deleteLegacyFileCache(serverUrl: string) {
|
||||
const serverDir = hashCode_DEPRECATED(serverUrl);
|
||||
deleteFileCacheByDir(serverDir);
|
||||
}
|
||||
|
||||
async function deleteFileCacheByDir(dir: string) {
|
||||
const cacheDir = `${FileSystem.CachesDirectoryPath}/${dir}`;
|
||||
if (cacheDir) {
|
||||
const cacheDirInfo = await FileSystem.exists(cacheDir);
|
||||
if (cacheDirInfo) {
|
||||
@@ -340,9 +349,10 @@ export function getFileType(file: FileInfo): string {
|
||||
}
|
||||
|
||||
export function getLocalFilePathFromFile(serverUrl: string, file: FileInfo | FileModel) {
|
||||
const fileIdPath = file.id?.replace(/[^0-9a-z]/g, '');
|
||||
if (serverUrl) {
|
||||
const server = hashCode(serverUrl);
|
||||
if (file?.name) {
|
||||
const server = urlSafeBase64Encode(serverUrl);
|
||||
if (file?.name && !file.name.includes('/')) {
|
||||
let extension: string | undefined = file.extension;
|
||||
let filename = file.name;
|
||||
|
||||
@@ -362,9 +372,9 @@ export function getLocalFilePathFromFile(serverUrl: string, file: FileInfo | Fil
|
||||
}
|
||||
}
|
||||
|
||||
return `${FileSystem.CachesDirectoryPath}/${server}/${filename}-${hashCode(file.id!)}.${extension}`;
|
||||
return `${FileSystem.CachesDirectoryPath}/${server}/${filename}-${fileIdPath}.${extension}`;
|
||||
} else if (file?.id && file?.extension) {
|
||||
return `${FileSystem.CachesDirectoryPath}/${server}/${file.id}.${file.extension}`;
|
||||
return `${FileSystem.CachesDirectoryPath}/${server}/${fileIdPath}.${file.extension}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,8 +514,9 @@ export const getAllFilesInCachesDirectory = async (serverUrl: string) => {
|
||||
try {
|
||||
const files: FileSystem.ReadDirItem[][] = [];
|
||||
|
||||
const directoryFiles = await FileSystem.readDir(`${FileSystem.CachesDirectoryPath}/${hashCode(serverUrl)}`);
|
||||
const directoryFiles = await FileSystem.readDir(`${FileSystem.CachesDirectoryPath}/${urlSafeBase64Encode(serverUrl)}`);
|
||||
files.push(directoryFiles);
|
||||
|
||||
const flattenedFiles = files.flat();
|
||||
const totalSize = flattenedFiles.reduce((acc, file) => acc + file.size, 0);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user