MM-46252 : Gekidou - Settings - Fixes Advanced Settings (#6561)

* properly deletes data

* ts fix
This commit is contained in:
Avinash Lingaloo
2022-08-11 11:02:24 +04:00
committed by GitHub
parent c71b28a6a8
commit 5004baf9c6
2 changed files with 12 additions and 32 deletions

View File

@@ -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);