From 8f7714b07f41c156a7d5c172ebbf3940e23f3335 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 1 Sep 2022 13:43:11 +0530 Subject: [PATCH] filter non user and trashed files from existing files --- src/services/upload/uploadManager.ts | 3 ++- src/utils/file/index.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/upload/uploadManager.ts b/src/services/upload/uploadManager.ts index dc0e20323..a8deae1b9 100644 --- a/src/services/upload/uploadManager.ts +++ b/src/services/upload/uploadManager.ts @@ -6,6 +6,7 @@ import { sortFiles, preservePhotoswipeProps, decryptFile, + getUserOwnedNonTrashedFiles, } from 'utils/file'; import { logError } from 'utils/sentry'; import { getMetadataJSONMapKey, parseMetadataJSON } from './metadataService'; @@ -82,7 +83,7 @@ class UploadManager { } async updateExistingFilesAndCollections(collections: Collection[]) { - this.existingFiles = await getLocalFiles(); + this.existingFiles = getUserOwnedNonTrashedFiles(await getLocalFiles()); this.collectionToExistingFilesMap = groupFilesBasedOnCollectionID( this.existingFiles ); diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index 70fa4dc34..e55ea3a56 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -508,3 +508,11 @@ export const createTypedObjectURL = async (blob: Blob, fileName: string) => { const type = await getFileType(new File([blob], fileName)); return URL.createObjectURL(new Blob([blob], { type: type.mimeType })); }; + +export const getUserOwnedNonTrashedFiles = (files: EnteFile[]) => { + const user: User = getData(LS_KEYS.USER); + if (!user?.id) { + throw Error('user missing'); + } + return files.filter((file) => file.isTrashed || file.ownerID !== user.id); +};