π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
New
Manav Rathi1c2e81353d0d
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsxindex 91e9204c92..f8106e6004 100644--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx@@ -42,19 +42,23 @@ import {} from "ente-base/components/utils/modal";import { useBaseContext } from "ente-base/context";import { deriveInteractiveKey } from "ente-base/crypto";-import { isHTTP4xxError } from "ente-base/http";+import { isHTTPErrorWithStatus } from "ente-base/http";import { formattedDateTime } from "ente-base/i18n-date";import log from "ente-base/log";import { appendCollectionKeyToShareURL } from "ente-gallery/services/share";import type {Collection,+ CollectionNewParticipantRole,PublicURL,UpdatePublicURL,} from "ente-media/collection";import { type CollectionUser } from "ente-media/collection";import { PublicLinkCreated } from "ente-new/photos/components/share/PublicLinkCreated";import { avatarTextColor } from "ente-new/photos/services/avatar";-import { deleteShareURL } from "ente-new/photos/services/collection";+import {+ deleteShareURL,+ shareCollection,+} from "ente-new/photos/services/collection";import type { CollectionSummary } from "ente-new/photos/services/collection/ui";import { usePhotosAppContext } from "ente-new/photos/types/context";import { CustomError, parseSharingErrorCodes } from "ente-shared/error";@@ -66,7 +70,6 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from "react";import { Trans } from "react-i18next";import {createShareableURL,- shareCollection,unshareCollection,updateShareableURL,} from "services/collectionService";@@ -318,23 +321,23 @@ interface EmailShareProps {const EmailShare: React.FC<EmailShareProps> = ({ collection, onRootClose }) => {const [addParticipantView, setAddParticipantView] = useState(false);const [manageEmailShareView, setManageEmailShareView] = useState(false);+ const [participantRole, setParticipantRole] = useState<+ CollectionNewParticipantRole | undefined+ >(undefined);const closeAddParticipant = () => setAddParticipantView(false);- const openAddParticipant = () => setAddParticipantView(true);const closeManageEmailShare = () => setManageEmailShareView(false);const openManageEmailShare = () => setManageEmailShareView(true);- const participantType = useRef<"COLLABORATOR" | "VIEWER">(undefined);-- const openAddCollab = () => {- participantType.current = "COLLABORATOR";- openAddParticipant();+ const openAddViewer = () => {+ setParticipantRole("VIEWER");+ setAddParticipantView(true);};- const openAddViewer = () => {- participantType.current = "VIEWER";- openAddParticipant();+ const openAddCollaborator = () => {+ setParticipantRole("COLLABORATOR");+ setAddParticipantView(true);};return (@@ -372,7 +375,7 @@ const EmailShare: React.FC<EmailShareProps> = ({ collection, onRootClose }) => {<RowButtonDivider /><RowButtonstartIcon={<AddIcon />}- onClick={openAddCollab}+ onClick={openAddCollaborator}label={t("add_collaborators")}/></RowButtonGroup>@@ -382,7 +385,7 @@ const EmailShare: React.FC<EmailShareProps> = ({ collection, onRootClose }) => {onClose={closeAddParticipant}onRootClose={onRootClose}collection={collection}- type={participantType.current}+ role={participantRole}/><ManageEmailSharepeopleCount={collection.sharees.length}@@ -447,7 +450,7 @@ interface AddParticipantProps {open: boolean;onClose: () => void;onRootClose: () => void;- type: "VIEWER" | "COLLABORATOR";+ role: CollectionNewParticipantRole;}const AddParticipant: React.FC<AddParticipantProps> = ({@@ -455,7 +458,7 @@ const AddParticipant: React.FC<AddParticipantProps> = ({collection,onClose,onRootClose,- type,+ role,}) => {const { user, syncWithRemote, emailList } = useContext(GalleryContext);@@ -474,7 +477,7 @@ const AddParticipant: React.FC<AddParticipantProps> = ({onRootClose();};- const title = type == "VIEWER" ? t("add_viewers") : t("add_collaborators");+ const title = role == "VIEWER" ? t("add_viewers") : t("add_collaborators");const collectionShare: AddParticipantFormProps["onSubmit"] = async (emailOrEmails,@@ -496,7 +499,6 @@ const AddParticipant: React.FC<AddParticipantProps> = ({);return;}- // Looks valid. Use it as if were a selection.emails = [email];} else {emails = emailOrEmails;@@ -504,18 +506,19 @@ const AddParticipant: React.FC<AddParticipantProps> = ({for (const email of emails) {try {- await shareCollection(collection, email, type);+ await shareCollection(collection, email, role);} catch (e) {- if (isHTTP4xxError(e)) {+ if (isHTTPErrorWithStatus(e, 404)) {setEmailFieldError(t("sharing_user_does_not_exist"));return;}+ // TODO(RE):setEmailFieldError(handleSharingErrors(e));return;}}- if (emails.length > 1) {+ if (emails.length) {await syncWithRemote(false, true);}onClose();@@ -834,7 +837,7 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({{...addParticipantVisibilityProps}onRootClose={onRootClose}collection={collection}- type={participantType.current}+ role={participantType.current}/><ManageParticipant{...manageParticipantVisibilityProps}diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.tsindex c85a1a3eed..7209db5cc1 100644--- a/web/apps/photos/src/services/collectionService.ts+++ b/web/apps/photos/src/services/collectionService.ts@@ -40,7 +40,6 @@ import {groupFilesByCollectionID,sortFiles,} from "ente-new/photos/services/files";-import { getPublicKey } from "ente-new/photos/services/user";import HTTPService from "ente-shared/network/HTTPService";import { getData } from "ente-shared/storage/localStorage";import { getToken } from "ente-shared/storage/localStorage/helpers";@@ -497,37 +496,6 @@ export const renameCollection = async ();};-export const shareCollection = async (- collection: Collection,- withUserEmail: string,- role: string,-) => {- try {- const cryptoWorker = await sharedCryptoWorker();- const token = getToken();- const publicKey: string = await getPublicKey(withUserEmail);- const encryptedKey = await cryptoWorker.boxSeal(- collection.key,- publicKey,- );- const shareCollectionRequest = {- collectionID: collection.id,- email: withUserEmail,- role: role,- encryptedKey,- };- await HTTPService.post(- await apiURL("/collections/share"),- shareCollectionRequest,- null,- { "X-Auth-Token": token },- );- } catch (e) {- log.error("share collection failed ", e);- throw e;- }-};-export const unshareCollection = async (collection: Collection,withUserEmail: string,diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.tsindex 5581cac124..ad096b3cbb 100644--- a/web/packages/media/collection.ts+++ b/web/packages/media/collection.ts@@ -68,12 +68,18 @@ export type CollectionType = "album" | "folder" | "favorites" | "uncategorized";* It is guaranteed that a there will be exactly one participant of type OWNER,* and their user ID will be the same as the collection `owner.id`.*/-export type CollectionUserRole =+export type CollectionParticipantRole =| "VIEWER"| "COLLABORATOR"| "OWNER"| "UNKNOWN";+/**+ * A subset of {@link CollectionParticipantRole} that are applicable when+ * sharing a collection with another Ente user.+ */+export type CollectionNewParticipantRole = "VIEWER" | "COLLABORATOR";+/*** Information about the user associated with a collection, either as an owner,* or as someone with whom the collection has been shared with.@@ -100,7 +106,7 @@ export interface CollectionUser {* {@link sharees}.* - Remote uses a blank string to indicate absent values.*/- role?: CollectionUserRole;+ role?: CollectionParticipantRole;}export interface EncryptedCollection {diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex d809f05d59..17bdf640bc 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -1,11 +1,16 @@import type { User } from "ente-accounts/services/user";-import { encryptBox } from "ente-base/crypto";+import { boxSeal, encryptBox } from "ente-base/crypto";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";-import { CollectionSubType, type Collection } from "ente-media/collection";+import {+ CollectionSubType,+ type Collection,+ type CollectionNewParticipantRole,+} from "ente-media/collection";import { type EnteFile } from "ente-media/file";import { ItemVisibility } from "ente-media/file-metadata";import { batch } from "ente-utils/array";+import { getPublicKey } from "./user";/*** An reasonable but otherwise arbitrary number of items (e.g. files) to include@@ -264,6 +269,38 @@ export const deleteFromTrash = async (fileIDs: number[]) => {}};+/**+ * Share the provided collection with another Ente user.+ *+ * Remote only, does not modify local state.+ *+ * @param collection The {@link Collection} to share.+ *+ * @param withUserEmail The email of the Ente user with whom to share it.+ *+ * @param role The desired role for the new participant.+ */+export const shareCollection = async (+ collection: Collection,+ withUserEmail: string,+ role: CollectionNewParticipantRole,+) => {+ const publicKey = await getPublicKey(withUserEmail);+ const encryptedKey = await boxSeal(collection.key, publicKey);++ const res = await fetch(await apiURL("/collections/share"), {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ body: JSON.stringify({+ collectionID: collection.id,+ email: withUserEmail,+ role: role,+ encryptedKey,+ }),+ });+ ensureOk(res);+};+/*** Delete the public link for the collection with given {@link collectionID}.*