Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Name

Manav Rathi76308cc9d088
diff --git a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
index f3000d9fc4..5a829e3998 100644
--- a/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
+++ b/web/apps/photos/src/components/PhotoViewer/ImageEditorOverlay.tsx
@@ -11,6 +11,7 @@ import { downloadAndRevokeObjectURL } from "@/base/utils/web";
import { downloadManager } from "@/gallery/services/download";
import { EnteFile } from "@/media/file";
import { photosDialogZIndex } from "@/new/photos/components/utils/z-index";
+import { getLocalCollections } from "@/new/photos/services/collection";
import { AppContext } from "@/new/photos/types/context";
import {
CenteredFlex,
@@ -52,7 +53,6 @@ import React, {
type MutableRefObject,
type Ref,
} from "react";
-import { getLocalCollections } from "services/collectionService";
import uploadManager from "services/upload/uploadManager";
interface ImageEditorOverlayProps {
diff --git a/web/apps/photos/src/pages/deduplicate.tsx b/web/apps/photos/src/pages/deduplicate.tsx
index ce4b3b045e..e5744910ac 100644
--- a/web/apps/photos/src/pages/deduplicate.tsx
+++ b/web/apps/photos/src/pages/deduplicate.tsx
@@ -2,7 +2,10 @@ import { stashRedirect } from "@/accounts/services/redirect";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { errorDialogAttributes } from "@/base/components/utils/dialog";
import log from "@/base/log";
-import { ALL_SECTION } from "@/new/photos/services/collection";
+import {
+ ALL_SECTION,
+ getLocalCollections,
+} from "@/new/photos/services/collection";
import { createFileCollectionIDs } from "@/new/photos/services/file";
import { getLocalFiles } from "@/new/photos/services/files";
import { useAppContext } from "@/new/photos/types/context";
@@ -19,10 +22,7 @@ import PhotoFrame from "components/PhotoFrame";
import { t } from "i18next";
import { default as Router, default as router } from "next/router";
import { createContext, useEffect, useState } from "react";
-import {
- getAllLatestCollections,
- getLocalCollections,
-} from "services/collectionService";
+import { getAllLatestCollections } from "services/collectionService";
import { Duplicate, getDuplicates } from "services/deduplicationService";
import { syncFiles, trashFiles } from "services/fileService";
import { syncTrash } from "services/trashService";
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 456b678a7f..2aa7d6308e 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -113,8 +113,8 @@ import {
createAlbum,
createUnCategorizedCollection,
getAllLatestCollections,
- getAllLocalCollections,
} from "services/collectionService";
+import { getAllLocalCollections } from "@/new/photos/services/collection";
import { syncFiles } from "services/fileService";
import { preFileInfoSync, sync } from "services/sync";
import { syncTrash } from "services/trashService";
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index a4eda9232c..d24195f02f 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -21,6 +21,8 @@ import {
import { EncryptedMagicMetadata, EnteFile } from "@/media/file";
import { ItemVisibility } from "@/media/file-metadata";
import {
+ getAllLocalCollections,
+ getLocalCollections,
isDefaultHiddenCollection,
isHiddenCollection,
} from "@/new/photos/services/collection";
@@ -42,8 +44,6 @@ import { getActualKey } from "@ente/shared/user";
import type { User } from "@ente/shared/user/types";
import {
changeCollectionSubType,
- getHiddenCollections,
- getNonHiddenCollections,
isQuickLinkCollection,
isValidMoveTarget,
} from "utils/collection";
@@ -51,6 +51,7 @@ import { UpdateMagicMetadataRequest } from "./fileService";
import { getPublicKey } from "./userService";
const COLLECTION_TABLE = "collections";
+
const COLLECTION_UPDATION_TIME = "collection-updation-time";
const HIDDEN_COLLECTION_IDS = "hidden-collection-ids";
@@ -192,21 +193,6 @@ const getCollections = async (
}
};
-export const getLocalCollections = async (
- type: "normal" | "hidden" = "normal",
-): Promise<Collection[]> => {
- const collections = await getAllLocalCollections();
- return type === "normal"
- ? getNonHiddenCollections(collections)
- : getHiddenCollections(collections);
-};
-
-export const getAllLocalCollections = async (): Promise<Collection[]> => {
- const collections: Collection[] =
- (await localForage.getItem(COLLECTION_TABLE)) ?? [];
- return collections;
-};
-
export const getCollectionUpdationTime = async (): Promise<number> =>
(await localForage.getItem<number>(COLLECTION_UPDATION_TIME)) ?? 0;
@@ -217,10 +203,11 @@ export const getLatestCollections = async (
type: "normal" | "hidden" = "normal",
): Promise<Collection[]> => {
const collections = await getAllLatestCollections();
- return type === "normal"
- ? getNonHiddenCollections(collections)
- : getHiddenCollections(collections);
+ return type == "normal"
+ ? collections.filter((c) => !isHiddenCollection(c))
+ : collections.filter((c) => isHiddenCollection(c));
};
+
export const getAllLatestCollections = async (): Promise<Collection[]> => {
const collections = await syncCollections();
return collections;
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 9254989709..83526c7eea 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -26,7 +26,7 @@ import { PromiseQueue } from "@/utils/promise";
import { CustomError } from "@ente/shared/error";
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
import i18n from "i18next";
-import { getAllLocalCollections } from "../collectionService";
+import { getAllLocalCollections } from "@/new/photos/services/collection";
import { migrateExport, type ExportRecord } from "./migration";
/** Name of the JSON file in which we keep the state of the export. */
diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.ts
index 32e96e012c..9f9b035c4b 100644
--- a/web/apps/photos/src/services/export/migration.ts
+++ b/web/apps/photos/src/services/export/migration.ts
@@ -6,6 +6,7 @@ import type { Collection } from "@/media/collection";
import { mergeMetadata, type EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import { decodeLivePhoto } from "@/media/live-photo";
+import { getLocalCollections } from "@/new/photos/services/collection";
import { exportMetadataDirectoryName } from "@/new/photos/services/export";
import { getAllLocalFiles } from "@/new/photos/services/files";
import {
@@ -16,7 +17,6 @@ import {
import { wait } from "@/utils/promise";
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import type { User } from "@ente/shared/user/types";
-import { getLocalCollections } from "services/collectionService";
import { getIDBasedSortedFiles, getPersonalFiles } from "utils/file";
import {
getCollectionIDFromFileUID,
diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.ts
index 04f64d2345..eb727e3b5c 100644
--- a/web/apps/photos/src/utils/collection.ts
+++ b/web/apps/photos/src/utils/collection.ts
@@ -14,6 +14,8 @@ import { ItemVisibility } from "@/media/file-metadata";
import {
DEFAULT_HIDDEN_COLLECTION_USER_FACING_NAME,
findDefaultHiddenCollectionIDs,
+ getAllLocalCollections,
+ getLocalCollections,
isHiddenCollection,
isIncomingShare,
} from "@/new/photos/services/collection";
@@ -26,8 +28,6 @@ import { t } from "i18next";
import {
addToCollection,
createAlbum,
- getAllLocalCollections,
- getLocalCollections,
moveToCollection,
removeFromCollection,
restoreToCollection,
@@ -343,16 +343,6 @@ export function getCollectionNameMap(
);
}
-export function getNonHiddenCollections(
- collections: Collection[],
-): Collection[] {
- return collections.filter((collection) => !isHiddenCollection(collection));
-}
-
-export function getHiddenCollections(collections: Collection[]): Collection[] {
- return collections.filter((collection) => isHiddenCollection(collection));
-}
-
export const getOrCreateAlbum = async (
albumName: string,
existingCollections: Collection[],
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 6ef2e4e6c2..6e5cfead6d 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -2,7 +2,7 @@
import { FileType } from "@/media/file-type";
import { groupFilesByCollectionID } from "@/new/photos/services/file";
import { getLocalFiles } from "@/new/photos/services/files";
-import { getLocalCollections } from "services/collectionService";
+import { getLocalCollections } from "@/new/photos/services/collection";
import { parseDateFromDigitGroups } from "services/upload/date";
import {
MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT,
diff --git a/web/packages/new/photos/services/collection/index.ts b/web/packages/new/photos/services/collection/index.ts
index 2f87512f6f..5e21366d1c 100644
--- a/web/packages/new/photos/services/collection/index.ts
+++ b/web/packages/new/photos/services/collection/index.ts
@@ -1,5 +1,6 @@
import { SUB_TYPE, type Collection } from "@/media/collection";
import { ItemVisibility } from "@/media/file-metadata";
+import localForage from "@ente/shared/storage/localForage";
import type { User } from "@ente/shared/user/types";
export const ARCHIVE_SECTION = -1;
@@ -8,6 +9,23 @@ export const DUMMY_UNCATEGORIZED_COLLECTION = -3;
export const HIDDEN_ITEMS_SECTION = -4;
export const ALL_SECTION = 0;
+const COLLECTION_TABLE = "collections";
+
+export const getLocalCollections = async (
+ type: "normal" | "hidden" = "normal",
+): Promise<Collection[]> => {
+ const collections = await getAllLocalCollections();
+ return type == "normal"
+ ? collections.filter((c) => !isHiddenCollection(c))
+ : collections.filter((c) => isHiddenCollection(c));
+};
+
+export const getAllLocalCollections = async (): Promise<Collection[]> => {
+ const collections: Collection[] =
+ (await localForage.getItem(COLLECTION_TABLE)) ?? [];
+ return collections;
+};
+
/**
* Return true if this is a default hidden collection.
*
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index 49f5132246..27f807ecf7 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -1,4 +1,5 @@
import type { EnteFile } from "@/media/file";
+import { getLocalCollections } from "./collection";
import { getLocalFiles, uniqueFilesByID } from "./files";
/**
@@ -82,6 +83,11 @@ export const deduceDuplicates = async () => {
filesByHash.set(hash, [...(filesByHash.get(hash) ?? []), file]);
}
+ const collections = await getLocalCollections();
+ const collectionNameByID = new Map<number, string>();
+ for (const collection of collections)
+ collectionNameByID.set(collection.id, collection.name);
+
const duplicateGroups: DuplicateGroup[] = [];
for (const potentialDuplicates of filesByHash.values()) {