π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline
Manav Rathic2b6bfa1ed37
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex 2b68bc93d0..68c6ced967 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -45,14 +45,18 @@ import {storageLimitExceededErrorMessage,subscriptionExpiredErrorMessage,} from "ente-gallery/services/upload/upload-service";-import type { Collection } from "ente-media/collection";+import { CollectionSubType, type Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { UploaderNameInput } from "ente-new/albums/components/UploaderNameInput";import { CollectionMappingChoice } from "ente-new/photos/components/CollectionMappingChoice";import type { CollectionSelectorAttributes } from "ente-new/photos/components/CollectionSelector";import type { RemotePullOpts } from "ente-new/photos/components/gallery";import { downloadAppDialogAttributes } from "ente-new/photos/components/utils/download";-import { savedNormalCollections } from "ente-new/photos/services/collection";+import {+ createAlbum,+ isHiddenCollection,+ savedNormalCollections,+} from "ente-new/photos/services/collection";import { redirectToCustomerPortal } from "ente-new/photos/services/user-details";import { usePhotosAppContext } from "ente-new/photos/types/context";import { firstNonEmpty } from "ente-utils/array";@@ -79,7 +83,6 @@ import type {import { uploadManager } from "services/upload-manager";import watcher from "services/watch";import { SetLoading } from "types/gallery";-import { getOrCreateAlbum } from "utils/collection";import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";import { UploadProgress } from "./UploadProgress";@@ -643,8 +646,9 @@ export const Upload: React.FC<UploadProps> = ({collectionName,uploadItems,] of collectionNameToUploadItems) {- const collection = await getOrCreateAlbum(+ const collection = await matchExistingOrCreateAlbum(collectionName,+ user!,existingCollections,);collections.push(collection);@@ -1023,6 +1027,39 @@ const deriveImportSuggestion = (};};+const matchExistingOrCreateAlbum = async (+ albumName: string,+ user: LocalUser,+ existingCollections: Collection[],+) => {+ for (const collection of existingCollections) {+ if (+ // Name matches+ collection.name == albumName &&+ // Valid types+ (collection.type == "album" ||+ collection.type == "folder" ||+ collection.type == "uncategorized") &&+ // Not hidden+ !isHiddenCollection(collection) &&+ // Not a quicklink+ collection.magicMetadata?.data.subType !=+ CollectionSubType.quicklink &&+ // Owned by user+ collection.owner.id == user.id+ ) {+ log.info(+ `Found existing album ${albumName} with id ${collection.id}`,+ );+ return collection;+ }+ }++ const collection = await createAlbum(albumName);+ log.info(`Created new album ${albumName} with id ${collection.id}`);+ return collection;+};+const setPendingUploads = async (electron: Electron,collections: Collection[],diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.tsindex aa201832dc..8be190369b 100644--- a/web/apps/photos/src/utils/collection.ts+++ b/web/apps/photos/src/utils/collection.ts@@ -1,15 +1,11 @@-import type { User } from "ente-accounts/services/user";import { ensureElectron } from "ente-base/electron";import { joinPath } from "ente-base/file-name";import log from "ente-base/log";import { uniqueFilesByID } from "ente-gallery/utils/file";-import { type Collection, CollectionSubType } from "ente-media/collection";import { EnteFile } from "ente-media/file";import {- createAlbum,defaultHiddenCollectionUserFacingName,findDefaultHiddenCollectionIDs,- isHiddenCollection,} from "ente-new/photos/services/collection";import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";import {@@ -17,7 +13,6 @@ import {savedCollections,} from "ente-new/photos/services/photos-fdb";import { safeDirectoryName } from "ente-new/photos/utils/native-fs";-import { getData } from "ente-shared/storage/localStorage";import {SetFilesDownloadProgressAttributes,type SetFilesDownloadProgressAttributesCreator,@@ -124,48 +119,3 @@ async function createCollectionDownloadFolder(await fs.mkdirIfNeeded(collectionDownloadPath);return collectionDownloadPath;}--const isQuickLinkCollection = (collection: Collection) =>- collection.magicMetadata?.data.subType == CollectionSubType.quicklink;--export function isIncomingViewerShare(collection: Collection, user: User) {- const sharee = collection.sharees?.find((sharee) => sharee.id === user.id);- return sharee?.role == "VIEWER";-}--export function isValidReplacementAlbum(- collection: Collection,- user: User,- wantedCollectionName: string,-) {- return (- collection.name === wantedCollectionName &&- (collection.type == "album" ||- collection.type == "folder" ||- collection.type == "uncategorized") &&- !isHiddenCollection(collection) &&- !isQuickLinkCollection(collection) &&- collection.owner.id == user.id- );-}--export const getOrCreateAlbum = async (- albumName: string,- existingCollections: Collection[],-) => {- const user: User = getData("user");- if (!user?.id) {- throw Error("user missing");- }- for (const collection of existingCollections) {- if (isValidReplacementAlbum(collection, user, albumName)) {- log.info(- `Found existing album ${albumName} with id ${collection.id}`,- );- return collection;- }- }- const album = await createAlbum(albumName);- log.info(`Created new album ${albumName} with id ${album.id}`);- return album;-};