π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Impl and swap
Manav Rathi07420304d0b7
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex 68c6ced967..86424fca2b 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -48,6 +48,10 @@ import {import { CollectionSubType, type Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { UploaderNameInput } from "ente-new/albums/components/UploaderNameInput";+import {+ savedPublicCollectionUploaderName,+ savePublicCollectionUploaderName,+} from "ente-new/albums/services/public-albums-fdb";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";@@ -68,11 +72,6 @@ import React, {useRef,useState,} from "react";-import {- getPublicCollectionUID,- getPublicCollectionUploaderName,- savePublicCollectionUploaderName,-} from "services/publicCollectionService";import type {InProgressUpload,SegregatedFinishedUploads,@@ -523,10 +522,8 @@ export const Upload: React.FC<UploadProps> = ({(async () => {if (publicCollectionGalleryContext.credentials) {- const uploaderName = await getPublicCollectionUploaderName(- getPublicCollectionUID(- publicCollectionGalleryContext.credentials.accessToken,- ),+ const uploaderName = await savedPublicCollectionUploaderName(+ publicCollectionGalleryContext.credentials.accessToken,);uploaderNameRef.current = uploaderName ?? "";showUploaderNameInput();@@ -825,9 +822,7 @@ export const Upload: React.FC<UploadProps> = ({const handlePublicUpload = async (uploaderName: string) => {savePublicCollectionUploaderName(- getPublicCollectionUID(- publicCollectionGalleryContext.credentials.accessToken,- ),+ publicCollectionGalleryContext.credentials.accessToken,uploaderName,);diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsxindex 5d1826e407..23230f49ce 100644--- a/web/apps/photos/src/pages/shared-albums.tsx+++ b/web/apps/photos/src/pages/shared-albums.tsx@@ -51,7 +51,7 @@ import { sortFiles } from "ente-gallery/utils/file";import type { Collection } from "ente-media/collection";import { type EnteFile } from "ente-media/file";import {- savedLastPublicAlbumReferralCode,+ savedLastPublicCollectionReferralCode,savedPublicCollectionFiles,} from "ente-new/albums/services/public-albums-fdb";import { verifyPublicAlbumPassword } from "ente-new/albums/services/public-collection";@@ -223,7 +223,7 @@ export default function PublicCollectionGallery() {let accessTokenJWT: string | undefined;if (localCollection) {referralCode.current =- await savedLastPublicAlbumReferralCode();+ await savedLastPublicCollectionReferralCode();const sortAsc: boolean =localCollection?.pubMagicMetadata?.data.asc ?? false;setPublicCollection(localCollection);diff --git a/web/apps/photos/src/services/publicCollectionService.ts b/web/apps/photos/src/services/publicCollectionService.tsindex 5ce359785a..8ade970689 100644--- a/web/apps/photos/src/services/publicCollectionService.ts+++ b/web/apps/photos/src/services/publicCollectionService.ts@@ -11,7 +11,7 @@ import { decryptRemoteFile } from "ente-media/file";import {savedPublicCollectionFiles,savedPublicCollections,- saveLastPublicAlbumReferralCode,+ saveLastPublicCollectionReferralCode,savePublicCollectionFiles,} from "ente-new/albums/services/public-albums-fdb";import { CustomError, parseSharingErrorCodes } from "ente-shared/error";@@ -31,23 +31,6 @@ const getPublicCollectionLastSyncTimeKey = (collectionUID: string) =>const getPublicCollectionPasswordKey = (collectionUID: string) =>`public-${collectionUID}-passkey`;-const getPublicCollectionUploaderNameKey = (collectionUID: string) =>- `public-${collectionUID}-uploaderName`;--export const getPublicCollectionUploaderName = async (collectionUID: string) =>- await localForage.getItem<string>(- getPublicCollectionUploaderNameKey(collectionUID),- );--export const savePublicCollectionUploaderName = async (- collectionUID: string,- uploaderName: string,-) =>- await localForage.setItem(- getPublicCollectionUploaderNameKey(collectionUID),- uploaderName,- );-export interface LocalSavedPublicCollectionFiles {collectionUID: string;files: EnteFile[];@@ -311,7 +294,7 @@ export const getPublicCollection = async (pubMagicMetadata: collectionPublicMagicMetadata,};await savePublicCollection(collection);- await saveLastPublicAlbumReferralCode(referralCode);+ await saveLastPublicCollectionReferralCode(referralCode);return [collection, referralCode];} catch (e) {log.error("failed to get public collection", e);diff --git a/web/packages/new/albums/services/public-albums-fdb.ts b/web/packages/new/albums/services/public-albums-fdb.tsindex 8303faa795..7c25ff2502 100644--- a/web/packages/new/albums/services/public-albums-fdb.ts+++ b/web/packages/new/albums/services/public-albums-fdb.ts@@ -48,20 +48,24 @@ const LocalReferralCode = z.string().nullish().transform(nullToUndefined);* 1. The public albums app persists only the referral code for the latest* public album that was fetched.*- * 2. This saved value can be read by {@link savedLastPublicAlbumReferralCode}.+ * 2. This saved value can be read by+ * {@link savedLastPublicCollectionReferralCode}.** 3. It gets updated as part of {@link publicAlbumsRemotePull}, which writes- * out a new value using {@link saveLastPublicAlbumReferralCode}.+ * out a new value using {@link saveLastPublicCollectionReferralCode}.*/-export const savedLastPublicAlbumReferralCode = async () =>+export const savedLastPublicCollectionReferralCode = async () =>LocalReferralCode.parse(await localForage.getItem("public-referral-code"));/*** Update the referral code present in our local database.*- * This is the setter corresponding to {@link savedLastPublicAlbumReferralCode}.+ * This is the setter corresponding to+ * {@link savedLastPublicCollectionReferralCode}.*/-export const saveLastPublicAlbumReferralCode = async (referralCode: string) => {+export const saveLastPublicCollectionReferralCode = async (+ referralCode: string,+) => {await localForage.setItem("public-referral-code", referralCode);};@@ -120,3 +124,46 @@ export const savePublicCollectionFiles = async (...(entries ?? []).filter((e) => e.collectionUID != accessToken),]);};++const LocalUploaderName = z.string().nullish().transform(nullToUndefined);++/**+ * Return the previously saved uploader name, if any, present in our local+ * database corresponding to a public collection.+ *+ * Use {@link savePublicCollectionUploaderName} to update the persisted value.+ *+ * [Note: Public albums uploader name]+ *+ * Whenever there is an upload to a public album, we ask the person doing the+ * upload for their name. This uploader name is attached as part of the public+ * magic metadata of the file so that other people know who uploaded the file.+ *+ * The public albums app also saves this value, keyed by an identifier for the+ * public collection, in the local database so that it can prefill it the next+ * time there is an upload from the same client.+ *+ * @param accessToken The access token of the public album whose persisted+ * uploader name we we want.+ */+export const savedPublicCollectionUploaderName = async (accessToken: string) =>+ LocalUploaderName.parse(+ await localForage.getItem(`public-${accessToken}-uploaderName`),+ );++/**+ * Update the uploader name present in our local database corresponding to a+ * public collection.+ *+ * This is the setter corresponding to+ * {@link savedPublicCollectionUploaderName}.+ */+export const savePublicCollectionUploaderName = async (+ accessToken: string,+ uploaderName: string,+) => {+ await localForage.setItem(+ `public-${accessToken}-uploaderName`,+ uploaderName,+ );+};