π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Pass collection ID in join album redirect URL to avoid public API call
Anand Baburajana53b4ce6d832
diff --git a/web/apps/photos/src/hooks/useJoinAlbum.ts b/web/apps/photos/src/hooks/useJoinAlbum.tsindex e6c3e3ec12..3b42291629 100644--- a/web/apps/photos/src/hooks/useJoinAlbum.ts+++ b/web/apps/photos/src/hooks/useJoinAlbum.ts@@ -23,12 +23,13 @@ export interface UseJoinAlbumReturn {*/const buildWebRedirectURL = (accessToken: string,+ collectionId: number,currentHash: string,jwtToken?: string,): string => {const webAppURL = photosAppOrigin();const jwtParam = jwtToken ? `&jwt=${encodeURIComponent(jwtToken)}` : "";- return `${webAppURL}/?joinAlbum=${accessToken}${jwtParam}#${currentHash}`;+ return `${webAppURL}/?joinAlbum=${accessToken}&collectionId=${collectionId}${jwtParam}#${currentHash}`;};/**@@ -37,13 +38,19 @@ const buildWebRedirectURL = (*/const handleWebFallback = (accessToken: string,+ collectionId: number,currentHash: string,jwtToken?: string,): void => {// Redirect to web app with joinAlbum parameter- // The URL contains all necessary context (token, JWT, hash) which will be+ // The URL contains all necessary context (token, collectionId, JWT, hash) which will be// stored on web.ente.io after the domain transition- const redirectURL = buildWebRedirectURL(accessToken, currentHash, jwtToken);+ const redirectURL = buildWebRedirectURL(+ accessToken,+ collectionId,+ currentHash,+ jwtToken,+ );window.location.href = redirectURL;};@@ -113,10 +120,11 @@ export const useJoinAlbum = ({// Get the original hash directly from the current URLconst currentHash = window.location.hash.slice(1);const jwtToken = credentials?.current?.accessTokenJWT;+ const collectionId = publicCollection.id;// Create fallback function for mobile deep linkingconst fallbackToWeb = () => {- handleWebFallback(accessToken, currentHash, jwtToken);+ handleWebFallback(accessToken, collectionId, currentHash, jwtToken);};// Check if on Android and try deep link with custom scheme with action=join parameter.@@ -130,7 +138,7 @@ export const useJoinAlbum = ({tryDeepLinkWithFallback(deepLinkURL, fallbackToWeb);} else {// Desktop and iOS: use the standard web flow directly- handleWebFallback(accessToken, currentHash, jwtToken);+ handleWebFallback(accessToken, collectionId, currentHash, jwtToken);}};diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsxindex 2994330472..d990a5d273 100644--- a/web/apps/photos/src/pages/index.tsx+++ b/web/apps/photos/src/pages/index.tsx@@ -64,12 +64,14 @@ const Page: React.FC = () => {const joinAlbumParam = currentURL.searchParams.get("joinAlbum");if (joinAlbumParam && joinAlbumParam !== "true") {try {- // Format: joinAlbum?=accessToken&jwt=<jwtToken>#collectionKeyHash+ // Format: ?joinAlbum=accessToken&collectionId=123&jwt=<jwtToken>#collectionKeyHashconst accessToken = joinAlbumParam;+ const collectionIdParam =+ currentURL.searchParams.get("collectionId");const collectionKeyHash = currentURL.hash.slice(1);const jwtFromURL = currentURL.searchParams.get("jwt");- if (accessToken && collectionKeyHash) {+ if (accessToken && collectionKeyHash && collectionIdParam) {// Import the necessary functions to convert the collection keyconst { extractCollectionKeyFromShareURL } =await import("ente-gallery/services/share");@@ -85,7 +87,7 @@ const Page: React.FC = () => {accessToken,collectionKey,collectionKeyHash,- collectionID: 0,+ collectionID: parseInt(collectionIdParam, 10),...(jwtFromURL && { accessTokenJWT: jwtFromURL }),};diff --git a/web/packages/new/albums/services/join-album.ts b/web/packages/new/albums/services/join-album.tsindex ada19ff72a..86336ca536 100644--- a/web/packages/new/albums/services/join-album.ts+++ b/web/packages/new/albums/services/join-album.ts@@ -1,10 +1,8 @@import { savedKeyAttributes } from "ente-accounts/services/accounts-db";-import { ensureLocalUser } from "ente-accounts/services/user";import { boxSeal } from "ente-base/crypto";import { authenticatedRequestHeaders } from "ente-base/http";import log from "ente-base/log";import { apiURL } from "ente-base/origins";-import type { Collection } from "ente-media/collection";/*** Service for handling the join album flow for public collections.@@ -115,41 +113,7 @@ export const processPendingAlbumJoin = async (): Promise<number | null> => {}try {- // If collectionID is 0 (placeholder), we need to fetch the actual collection first- let collectionID = context.collectionID;- let collection: Collection | undefined;- if (collectionID === 0) {- // Import the pullCollection function dynamically from the correct module- const { pullCollection } = await import("./public-collection");- const result = await pullCollection(- context.accessToken,- context.collectionKey,- );- collection = result.collection;- collectionID = collection.id;-- // Update the context with the actual collection ID- const updatedContext = { ...context, collectionID };- sessionStorage.setItem(- JOIN_ALBUM_CONTEXT_KEY,- JSON.stringify(updatedContext),- );- } else {- // Fetch the collection to check ownership- const { pullCollection } = await import("./public-collection");- const result = await pullCollection(- context.accessToken,- context.collectionKey,- );- collection = result.collection;- }-- // Check if the user is the owner of the album- const currentUser = ensureLocalUser();- if (collection.owner.id === currentUser.id) {- clearJoinAlbumContext();- return null;- }+ const collectionID = context.collectionID;// Get user's key attributes from local storageconst keyAttributes = savedKeyAttributes();@@ -166,6 +130,7 @@ export const processPendingAlbumJoin = async (): Promise<number | null> => {const encryptedKey = await boxSeal(context.collectionKey, publicKey);// Join the album (include JWT token if present for password-protected albums)+ // Server validates ownership and returns error if user is the album ownerawait joinPublicAlbum(context.accessToken,collectionID,