Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

sk 3

Manav Rathid535cfc5a4e0
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index e0e568434f..82f7fc7521 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -1,6 +1,7 @@
import type { User } from "ente-accounts/services/user";
import { ensureLocalUser } from "ente-accounts/services/user";
import { encryptMetadataJSON, sharedCryptoWorker } from "ente-base/crypto";
+import { isDevBuild } from "ente-base/env";
import log from "ente-base/log";
import { apiURL } from "ente-base/origins";
import { ensureMasterKeyFromSession } from "ente-base/session";
@@ -23,6 +24,7 @@ import { EncryptedMagicMetadata, EnteFile } from "ente-media/file";
import { ItemVisibility } from "ente-media/file-metadata";
import {
addToCollection,
+ createCollection2,
isDefaultHiddenCollection,
moveToCollection,
} from "ente-new/photos/services/collection";
@@ -57,6 +59,9 @@ const FAVORITE_COLLECTION_NAME = "Favorites";
const REQUEST_BATCH_SIZE = 1000;
export const createAlbum = (albumName: string) => {
+ if (isDevBuild && process.env.NEXT_PUBLIC_ENTE_WIP_NEWIMPL) {
+ return createCollection2(albumName, "album");
+ }
return createCollection(albumName, "album");
};
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index 466a666c48..1a0ca9fd19 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -1,3 +1,4 @@
+import { decryptBox, decryptBoxBytes } from "ente-base/crypto";
import {
type EncryptedMagicMetadata,
type MagicMetadataCore,
@@ -5,7 +6,11 @@ import {
import { ItemVisibility } from "ente-media/file-metadata";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod/v4";
-import { RemoteMagicMetadataSchema } from "./magic-metadata";
+import {
+ decryptMagicMetadata,
+ RemoteMagicMetadataSchema,
+ type RemoteMagicMetadata,
+} from "./magic-metadata";
// TODO: Audit this file
@@ -140,8 +145,8 @@ export interface CollectionUser {
*/
export const RemoteCollectionUser = z.object({
id: z.number(),
- email: z.string().nullish(),
- role: z.string().nullish(),
+ email: z.string().nullish().transform(nullToUndefined),
+ role: z.string().nullish().transform(nullToUndefined),
});
type RemoteCollectionUser = z.infer<typeof RemoteCollectionUser>;
@@ -429,22 +434,55 @@ export const decryptRemoteCollection = (
* Decrypt a remote collection using the provided key.
*
* This is the lower level implementation of {@link decryptRemoteCollection} for
- * use by code that already has determined which key should be used for
+ * use by code that has already determined which key should be used for
* decrypting the collection.
*
- * @param remoteCollection The collection to decrypt.
+ * @param collection The collection to decrypt.
*
- * @param key The base64 encoded key to use for decrypting the various encrypted
- * fields in {@link remoteCollection}.
+ * @param decryptionKey The base64 encoded key to use for decrypting the various encrypted
+ * fields in {@link collection}.
*
* @returns A decrypted collection ({@link Collection2}).
*/
-export const decryptRemoteCollectionUsingKey = (
- remoteCollection: RemoteCollection,
- key: string,
+export const decryptRemoteCollectionUsingKey = async (
+ collection: RemoteCollection,
+ decryptionKey: string,
): Promise<Collection2> => {
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- throw new Error("TODO" + remoteCollection.toString() + key.toString());
+ const { id, owner, type, sharees, publicURLs, updationTime } = collection;
+ const { encryptedKey, keyDecryptionNonce } = collection;
+ const collectionKey = await decryptBox(
+ { encryptedData: encryptedKey, nonce: keyDecryptionNonce },
+ decryptionKey,
+ );
+
+ const name =
+ collection.name ??
+ new TextDecoder().decode(
+ await decryptBoxBytes(
+ {
+ encryptedData: collection.encryptedName!,
+ nonce: collection.nameDecryptionNonce!,
+ },
+ collectionKey,
+ ),
+ );
+
+ const decryptMM = async (mm: RemoteMagicMetadata | undefined) =>
+ mm ? await decryptMagicMetadata(mm, collectionKey) : undefined;
+
+ return {
+ id,
+ owner,
+ key: collectionKey,
+ name,
+ type,
+ sharees,
+ publicURLs,
+ updationTime,
+ magicMetadata: await decryptMM(collection.magicMetadata),
+ pubMagicMetadata: await decryptMM(collection.pubMagicMetadata),
+ sharedMagicMetadata: await decryptMM(collection.sharedMagicMetadata),
+ };
};
/**
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 2755369673..638d7750a6 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -10,7 +10,7 @@ import {
type Collection,
type Collection2,
type CollectionNewParticipantRole,
- type CollectionPrivateMagicMetadata,
+ type CollectionPrivateMagicMetadataData,
type CollectionType,
type RemoteCollection,
} from "ente-media/collection";
@@ -108,7 +108,7 @@ export const getCollectionUserFacingName = (collection: Collection) => {
export const createCollection2 = async (
name: string,
type: CollectionType,
- magicMetadataData?: CollectionPrivateMagicMetadata,
+ magicMetadataData?: CollectionPrivateMagicMetadataData,
): Promise<Collection2> => {
const masterKey = await ensureMasterKeyFromSession();
const collectionKey = await generateKey();
@@ -131,6 +131,7 @@ export const createCollection2 = async (
type,
...(magicMetadata ? { magicMetadata } : {}),
});
+
return decryptRemoteCollectionUsingKey(remoteCollection, masterKey);
};