forked from Ivasoft/mattermost-mobile
MM-46252 : Gekidou - Settings - Fixes Advanced Settings (#6561)
* properly deletes data * ts fix
This commit is contained in:
@@ -14,8 +14,6 @@ import {Asset} from 'react-native-image-picker';
|
||||
import Permissions, {PERMISSIONS} from 'react-native-permissions';
|
||||
|
||||
import {Files} from '@constants';
|
||||
import DatabaseManager from '@database/manager';
|
||||
import {queryAllServers} from '@queries/app/servers';
|
||||
import {generateId} from '@utils/general';
|
||||
import keyMirror from '@utils/key_mirror';
|
||||
import {logError} from '@utils/log';
|
||||
@@ -502,30 +500,17 @@ export const hasWriteStoragePermission = async (intl: IntlShape) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getAllFilesInCachesDirectory = async () => {
|
||||
export const getAllFilesInCachesDirectory = async (serverUrl: string) => {
|
||||
try {
|
||||
const appDatabase = DatabaseManager.appDatabase;
|
||||
const servers = await queryAllServers(appDatabase!.database);
|
||||
if (!servers.length) {
|
||||
return {error: 'No servers'};
|
||||
}
|
||||
|
||||
const serverUrls = [];
|
||||
const files: FileSystem.ReadDirItem[][] = [];
|
||||
|
||||
for await (const server of servers) {
|
||||
const directoryFiles = await FileSystem.readDir(`${FileSystem.CachesDirectoryPath}/${hashCode(server.url)}`);
|
||||
files.push(directoryFiles);
|
||||
serverUrls.push(server.url);
|
||||
}
|
||||
|
||||
const directoryFiles = await FileSystem.readDir(`${FileSystem.CachesDirectoryPath}/${hashCode(serverUrl)}`);
|
||||
files.push(directoryFiles);
|
||||
const flattenedFiles = files.flat();
|
||||
const totalSize = flattenedFiles.reduce((acc, file) => acc + file.size, 0);
|
||||
|
||||
return {
|
||||
files: flattenedFiles,
|
||||
totalSize,
|
||||
serverUrls,
|
||||
};
|
||||
} catch (error) {
|
||||
logError('Failed getAllFilesInCachesDirectory', error);
|
||||
|
||||
Reference in New Issue
Block a user