π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Document and use
Manav Rathib854a603af24
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.tsindex a9cc3b2345..1c08d1fb7d 100644--- a/web/apps/photos/src/services/collectionService.ts+++ b/web/apps/photos/src/services/collectionService.ts@@ -1,15 +1,10 @@-import type { User } from "ente-accounts/services/user";-import { isDevBuild } from "ente-base/env";import log from "ente-base/log";import { apiURL } from "ente-base/origins";-import { groupFilesByCollectionID, sortFiles } from "ente-gallery/utils/file";+import { sortFiles } from "ente-gallery/utils/file";import { EnteFile } from "ente-media/file";import {addToFavorites,- createUncategorizedCollection,- moveFromCollection,- removeFromCollection2,- removeNonUserFilesFromCollection,+ removeFromCollection,savedUserFavoritesCollection,} from "ente-new/photos/services/collection";import type { CollectionSummary } from "ente-new/photos/services/collection-summary";@@ -17,14 +12,9 @@ import {CollectionSummaryOrder,CollectionsSortBy,} from "ente-new/photos/services/collection-summary";-import {- savedCollectionFiles,- savedCollections,-} from "ente-new/photos/services/photos-fdb";+import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";import HTTPService from "ente-shared/network/HTTPService";-import { getData } from "ente-shared/storage/localStorage";import { getToken } from "ente-shared/storage/localStorage/helpers";-import { isValidMoveTarget } from "utils/collection";export const addToFavorites1 = async (file: EnteFile) => {await addToFavorites([file]);@@ -38,106 +28,6 @@ export const removeFromFavorites1 = async (file: EnteFile) => {await removeFromCollection(favCollection.id, [file]);};-export const removeFromCollection = async (- collectionID: number,- toRemoveFiles: EnteFile[],-) => {- // TODO(RE):- if (isDevBuild && process.env.NEXT_PUBLIC_ENTE_WIP_MOVE)- return removeFromCollection2(collectionID, toRemoveFiles);-- try {- const user: User = getData("user");- const nonUserFiles = [];- const userFiles = [];- for (const file of toRemoveFiles) {- if (file.ownerID === user.id) {- userFiles.push(file);- } else {- nonUserFiles.push(file);- }- }-- if (nonUserFiles.length > 0) {- await removeNonUserFilesFromCollection(- collectionID,- nonUserFiles.map((f) => f.id),- );- }- if (userFiles.length > 0) {- await removeUserFiles(collectionID, userFiles);- }- } catch (e) {- log.error("remove from collection failed ", e);- throw e;- }-};--const removeUserFiles = async (- sourceCollectionID: number,- toRemoveFiles: EnteFile[],-) => {- try {- const allFiles = await savedCollectionFiles();-- const toRemoveFilesIds = new Set(toRemoveFiles.map((f) => f.id));- const toRemoveFilesCopiesInOtherCollections = allFiles.filter((f) => {- return toRemoveFilesIds.has(f.id);- });- const groupedFiles = groupFilesByCollectionID(- toRemoveFilesCopiesInOtherCollections,- );-- const collections = await savedCollections();- const collectionsMap = new Map(collections.map((c) => [c.id, c]));- const user: User = getData("user");-- for (const [targetCollectionID, files] of groupedFiles.entries()) {- const targetCollection = collectionsMap.get(targetCollectionID);- if (- !isValidMoveTarget(sourceCollectionID, targetCollection, user)- ) {- continue;- }- const toMoveFiles = files.filter((f) => {- if (toRemoveFilesIds.has(f.id)) {- toRemoveFilesIds.delete(f.id);- return true;- }- return false;- });- if (toMoveFiles.length === 0) {- continue;- }- await moveFromCollection(- sourceCollectionID,- targetCollection,- toMoveFiles,- );- }- const leftFiles = toRemoveFiles.filter((f) =>- toRemoveFilesIds.has(f.id),- );-- if (leftFiles.length === 0) {- return;- }-- const uncategorizedCollection =- collections.find((c) => c.type == "uncategorized") ??- (await createUncategorizedCollection());-- await moveFromCollection(- sourceCollectionID,- uncategorizedCollection,- leftFiles,- );- } catch (e) {- log.error("remove user files failed ", e);- throw e;- }-};-export const deleteCollection = async (collectionID: number,keepFiles: boolean,diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.tsindex 42f2fd7cca..da7ce4ec94 100644--- a/web/apps/photos/src/services/watch.ts+++ b/web/apps/photos/src/services/watch.ts@@ -16,9 +16,9 @@ import { type UploadResult } from "ente-gallery/services/upload";import type { UploadAsset } from "ente-gallery/services/upload/upload-service";import { groupFilesByCollectionID } from "ente-gallery/utils/file";import type { EnteFile } from "ente-media/file";+import { removeFromCollection } from "ente-new/photos/services/collection";import { computeNormalCollectionFilesFromSaved } from "ente-new/photos/services/file";import { ensureString } from "ente-utils/ensure";-import { removeFromCollection } from "./collectionService";import { type UploadItemWithCollection, uploadManager } from "./upload-manager";/**diff --git a/web/apps/photos/src/utils/collection.ts b/web/apps/photos/src/utils/collection.tsindex 3551a5f45d..756fcff471 100644--- a/web/apps/photos/src/utils/collection.ts+++ b/web/apps/photos/src/utils/collection.ts@@ -11,9 +11,9 @@ import {defaultHiddenCollectionUserFacingName,findDefaultHiddenCollectionIDs,isHiddenCollection,- isIncomingShare,moveFromCollection,moveToCollection,+ removeFromCollection,restoreToCollection,} from "ente-new/photos/services/collection";import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";@@ -23,7 +23,6 @@ import {} from "ente-new/photos/services/photos-fdb";import { safeDirectoryName } from "ente-new/photos/utils/native-fs";import { getData } from "ente-shared/storage/localStorage";-import { removeFromCollection } from "services/collectionService";import {SetFilesDownloadProgressAttributes,type SetFilesDownloadProgressAttributesCreator,@@ -185,19 +184,6 @@ export function isIncomingViewerShare(collection: Collection, user: User) {return sharee?.role == "VIEWER";}-export function isValidMoveTarget(- sourceCollectionID: number,- targetCollection: Collection,- user: User,-) {- return (- sourceCollectionID !== targetCollection.id &&- !isHiddenCollection(targetCollection) &&- !isQuickLinkCollection(targetCollection) &&- !isIncomingShare(targetCollection, user)- );-}-export function isValidReplacementAlbum(collection: Collection,user: User,@@ -210,7 +196,7 @@ export function isValidReplacementAlbum(collection.type == "uncategorized") &&!isHiddenCollection(collection) &&!isQuickLinkCollection(collection) &&- !isIncomingShare(collection, user)+ collection.owner.id == user.id);}diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex eb6a9a8c44..73267f1a30 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -27,7 +27,6 @@ import React, { useReducer } from "react";import {findDefaultHiddenCollectionIDs,isDefaultHiddenCollection,- isIncomingShare,} from "../../services/collection";import {PseudoCollectionID,@@ -1372,7 +1371,7 @@ const createCollectionSummaries = (: "album";let type: CollectionSummaryType;- if (isIncomingShare(collection, user)) {+ if (collection.owner.id != user.id) {if (isIncomingCollabShare(collection, user)) {type = "incomingShareCollaborator";} else {@@ -1415,7 +1414,7 @@ const createCollectionSummaries = (// This block of code duplicates the above. Such duplication is needed// until type is completely replaced by attributes.const attributes: CollectionSummaryType[] = [];- if (isIncomingShare(collection, user)) {+ if (collection.owner.id != user.id) {if (isIncomingCollabShare(collection, user)) {attributes.push("incomingShareCollaborator");} else {diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex ffb3dd0409..307a312f2c 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -1,4 +1,4 @@-import { ensureLocalUser, type User } from "ente-accounts/services/user";+import { ensureLocalUser } from "ente-accounts/services/user";import { blobCache } from "ente-base/blob-cache";import {boxSeal,@@ -679,30 +679,49 @@ export const deleteFromTrash = async (fileIDs: number[]) =>);/**- * Remove the given files from the specified collection.+ * Remove the given files from the specified collection owned by the user.** Reads local state but does not modify it. The effects are on remote.** [Note: Removing files from a collection]*- * The "remove from collection" primitive operates differently depending on- * whether or not the user owns the files that they're trying to remove.+ * There are three scenarios*- * 1. If the user owns the file, then move it from this collection to a- * different user owned collection in which it already exists (such a move- * acts as a remove). If it doesn't exist in any other user owned collection,- * then move it to the user's "Uncategorized" collection.+ * own file shared file+ * own collection M R+ * others collection R not supported*- * 1. If the user does not own the file, then it should be removed from the- * collection using POST "/collections/v3/remove-files".+ * M (move) when both collection and file belongs to user+ * R (remove) when only one of them belongs to the user*- * The "remove from collection" primitive is provided to the user both as a UI- * action (on selecting files in a collection), and also internally used when- * deleting a collection if the user chose the option to keep files.+ * The move operation is not supported across ownership boundaries. The remove+ * operation is only supported across ownership boundaries, but the user should+ * have owner ship of either the file or collection (not both).+ *+ * In more detail, the above three scenarios can be described this way.+ *+ * 1. Move: If the user owns both the collection and the file they're trying to+ * remove from the collection, then instead of a remove the client needs to+ * move it to a different user owned collection in which it already exists+ * (such a move acts as a remove). If it doesn't exist in any other user+ * owned collection, then move it to the user's "Uncategorized" collection.+ * The intent is that a "remove from collection" should not remove the last+ * copy of a file (thus deleting it).+ *+ * 2. Remove: If the user does not own the file being removed, or owns the file+ * being removed but does not own the collection from which it is being+ * removed, they can remove it from the collection using the POST+ * "/collections/v3/remove-files".*- * See: [Note: Deleting a collection].+ * 3. Not supported: Currently the possibility of removing a file the user does+ * not own from a collection that the user does not own, even if they are a+ * collaborator, is not supported.+ *+ * The "remove from collection" primitive is provided to the user both as a UI+ * action (on selecting files in a collection), and as an implicit action if the+ * user chooses the option to "keep files" when deleting a collection.*/-export const removeFromCollection2 = async (+export const removeFromCollection = async (collectionID: number,files: EnteFile[],) => {@@ -712,24 +731,24 @@ export const removeFromCollection2 = async ((f) => f.ownerID == userID,);if (userFiles.length) {- await removeUserFilesFromCollection(collectionID, userFiles);+ await removeUserFilesFromUserCollection(collectionID, userFiles);}if (nonUserFiles.length) {- await removeNonUserFilesFromCollection(collectionID, nonUserFiles);+ await postRemoveFilesFromCollection(collectionID, nonUserFiles);}};/**- * Remove the given user owned files from the given collection, ensuring that at- * least one user owned instance is retained for them (either in a user owned- * collection in which they already existed, or in the user's "Uncategorized"- * collection as a fallback).+ * Remove the given user owned files from the given collection also owned by the+ * user, ensuring that at least one user owned instance is retained for them+ * (either in a different user owned collection in which they already existed,+ * or in the user's "Uncategorized" collection as a fallback).** Reads local state but does not modify it. The effects are on remote.** This is used as a subroutine of [Note: Removing files from a collection].*/-export const removeUserFilesFromCollection = async (+export const removeUserFilesFromUserCollection = async (collectionID: number,filesToRemove: EnteFile[],) => {@@ -757,10 +776,6 @@ export const removeUserFilesFromCollection = async (// We'll move to uncategorized after the loop (if they still remain).if (targetCollection.type == "uncategorized") continue;- // TODO(RE): More conditions?- // !isHiddenCollection(targetCollection) &&- // !isQuickLinkCollection(targetCollection) &&-const filesInCollectionToRemove =filesInCollection.filter(pendingRemove);if (!filesInCollectionToRemove.length) continue;@@ -794,13 +809,20 @@ export const removeUserFilesFromCollection = async (};/**- * Remove the provided files (none of which are owned by the user) from the- * provided collection on remote.+ * Remove the provided files from the provided collection on remote.** Only files which do not belong to the collection owner can be removed from- * the collection. If the collection owner wants to remove files owned by them,- * then their client should first move those files first to other collections- * owned by the collection owner.+ * the collection using this endpoint. That is,+ *+ * - Either the user owns the collection and the all files being removed are+ * owned by somebody else, or+ *+ * - The user owns all the files being removed, but the collection belongs to+ * somebody else.+ *+ * If the collection owner wants to remove files owned by them, then their+ * client should first move those files first to other collections owned by the+ * collection owner.** Remote only, does not modify local state.*@@ -811,7 +833,7 @@ export const removeUserFilesFromCollection = async (* @param files A list of files which do not belong to the user, and which we* the user wants to remove from the given collection.*/-export const removeNonUserFilesFromCollection = async (+export const postRemoveFilesFromCollection = async (collectionID: number,files: EnteFile[],) =>@@ -1176,12 +1198,6 @@ export const isHiddenCollection = (collection: Collection) =>export const hideFiles = async (files: EnteFile[]) =>moveToCollection(await savedOrCreateDefaultHiddenCollection(), files);-/**- * Return true if this is a collection that the user doesn't own.- */-export const isIncomingShare = (collection: Collection, user: User) =>- collection.owner.id !== user.id;-/*** Share the provided collection with another Ente user.*