Skip to content

armgit / ente

Public Imported from GitHub
0

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

MM type

Manav Rathi7ee222925d14
diff --git a/web/apps/photos/src/components/UploadProgress.tsx b/web/apps/photos/src/components/UploadProgress.tsx
index 20a862ff37..4af28ab8e0 100644
--- a/web/apps/photos/src/components/UploadProgress.tsx
+++ b/web/apps/photos/src/components/UploadProgress.tsx
@@ -594,7 +594,7 @@ const createItemData: <T>(
items,
}));
-// @ts-expect-error "TODO(MR): Understand and fix the type error here"
+// @ts-expect-error "TODO: Understand and fix the type error here"
const Row: <T>({
index,
style,
diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsx
index 447b4be15d..c55a7b6117 100644
--- a/web/packages/accounts/pages/passkeys/finish.tsx
+++ b/web/packages/accounts/pages/passkeys/finish.tsx
@@ -81,7 +81,8 @@ const saveCredentialsAndNavigateTo = async (
// - The plaintext "token" will be passed during fresh signups, where we
// don't yet have keys to encrypt it, the account itself is being created
// as we go through this flow.
- // TODO(MR): Conceptually this cannot happen. During a _real_ fresh signup
+ //
+ // TODO: Conceptually this cannot happen. During a _real_ fresh signup
// we'll never enter the passkey verification flow. Remove this code after
// making sure that it doesn't get triggered in cases where an existing
// user goes through the new user flow.
diff --git a/web/packages/gallery/services/magic-metadata.ts b/web/packages/gallery/services/magic-metadata.ts
index cb3469738e..fc3998351c 100644
--- a/web/packages/gallery/services/magic-metadata.ts
+++ b/web/packages/gallery/services/magic-metadata.ts
@@ -49,7 +49,7 @@ export async function updateMagicMetadata<T>(
if (typeof originalMagicMetadata?.data == "string") {
// TODO: When converting this (and other parses of magic metadata) to
- // use zod, remember to use looseObject.
+ // use Zod, remember to use looseObject.
//
// See: [Note: Use looseObject for metadata Zod schemas]
// @ts-expect-error TODO: Need to use zod here.
diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.ts
index 7348ad028d..93c5e9fc63 100644
--- a/web/packages/gallery/services/video.ts
+++ b/web/packages/gallery/services/video.ts
@@ -519,10 +519,10 @@ const blobToDataURL = (blob: Blob) =>
* an array.
*/
const savedProcessedVideoFileIDs = () =>
- // [Note: Avoiding zod parsing overhead for DB arrays]
+ // [Note: Avoiding Zod parsing overhead for DB arrays]
//
// Validating that the value we read from the DB is indeed the same as the
- // type we expect can be done using zod, but for potentially very large
+ // type we expect can be done using Zod, but for potentially very large
// arrays, this has an overhead that is perhaps not justified when dealing
// with DB entries we ourselves wrote.
//
@@ -538,7 +538,7 @@ const savedProcessedVideoFileIDs = () =>
* @see also {@link savedProcessedVideoFileIDs}.
*/
const savedFailedVideoFileIDs = () =>
- // See: [Note: Avoiding zod parsing overhead for DB arrays]
+ // See: [Note: Avoiding Zod parsing overhead for DB arrays]
getKV("videoPreviewFailedFileIDs").then((v) => new Set(v as number[]));
/**
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index 46772c3caa..24e86b3282 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -6,7 +6,11 @@ import {
import { ItemVisibility } from "ente-media/file-metadata";
import { nullishToEmpty, nullToUndefined } from "ente-utils/transform";
import { z } from "zod/v4";
-import { decryptMagicMetadata, RemoteMagicMetadata } from "./magic-metadata";
+import {
+ decryptMagicMetadata,
+ RemoteMagicMetadata,
+ type MagicMetadata,
+} from "./magic-metadata";
/**
* The type of a collection.
@@ -234,9 +238,9 @@ export interface Collection
/**
* A collection, as used and persisted locally by the client.
*
- * A collection is roughly equivalent to an "album", though there can be special
- * type of collections (like "favorites") which have special behaviours attached
- * to them.
+ * A collection is, well, a collection of files. It is roughly equivalent to an
+ * "album" (which is also the term we use in the UI), bute there can also be
+ * special type of collections like "favorites" which have special behaviour.
*
* A collection contains zero or more files ({@link EnteFile}).
*
@@ -314,7 +318,7 @@ export interface Collection2 {
*
* See: [Note: Metadatum]
*/
- magicMetadata?: unknown; //CollectionMagicMetadata;
+ magicMetadata?: MagicMetadata<CollectionPrivateMagicMetadataData>;
/**
* Public mutable metadata associated with the collection that is visible to
* all users with whom the collection has been shared.
@@ -377,8 +381,15 @@ export const decryptRemoteCollection = async (
),
);
- const decryptMM = async (mm: RemoteMagicMetadata | undefined) =>
- mm ? await decryptMagicMetadata(mm, collectionKey) : undefined;
+ let magicMetadata: Collection2["magicMetadata"];
+ if (collection.magicMetadata) {
+ const genericMM = await decryptMagicMetadata(
+ collection.magicMetadata,
+ collectionKey,
+ );
+ const data = CollectionPrivateMagicMetadataData.parse(genericMM.data);
+ magicMetadata = { ...genericMM, data };
+ }
return {
id,
@@ -389,9 +400,10 @@ export const decryptRemoteCollection = async (
sharees,
publicURLs,
updationTime,
- magicMetadata: await decryptMM(collection.magicMetadata),
- pubMagicMetadata: await decryptMM(collection.pubMagicMetadata),
- sharedMagicMetadata: await decryptMM(collection.sharedMagicMetadata),
+ magicMetadata,
+ // TODO(RE):
+ // pubMagicMetadata: await decryptMM(collection.pubMagicMetadata),
+ // sharedMagicMetadata: await decryptMM(collection.sharedMagicMetadata),
};
};
@@ -400,8 +412,18 @@ export const decryptRemoteCollection = async (
* augment the {@link type} associated with a {@link Collection}.
*/
export const CollectionSubType = {
+ /**
+ * The default / normal value. No special semantics.
+ */
default: 0,
+ /**
+ * The user's default hidden collection, which contains the individually
+ * hidden files.
+ */
defaultHidden: 1,
+ /**
+ * A collection created for sharing selected files.
+ */
quicklink: 2,
} as const;
@@ -420,14 +442,23 @@ export interface CollectionPrivateMagicMetadataData {
/**
* The (owner specific) visibility of the collection.
*
+ * The file's visibility is user specific attribute, and thus we keep it in
+ * the private magic metadata. This allows the file's owner to share a file
* and independently edit its visibility without revealing their visibility
* preference to the other people with whom they have shared the file.
+ *
+ * Expected to be one of {@link ItemVisibility}.
+ *
+ * See: [Note: Enums in remote objects] for why we keep it as a number
+ * instead of the expected enum.
*/
- visibility?: ItemVisibility;
+ visibility?: number;
/**
- * The {@link CollectionSubType}, if applicable.
+ * The subtype of the collection type (if applicable).
+ *
+ * Expected to be one of {@link CollectionSubType}.
*/
- subType?: CollectionSubType;
+ subType?: number;
/**
* An overrride to the sort ordering used for the collection.
*
@@ -440,6 +471,17 @@ export interface CollectionPrivateMagicMetadataData {
order?: number;
}
+/**
+ * Zod schema for {@link CollectionPrivateMagicMetadataData}.
+ *
+ * See: [Note: Use looseObject for metadata Zod schemas]
+ */
+const CollectionPrivateMagicMetadataData = z.looseObject({
+ visibility: z.number().nullish().transform(nullToUndefined),
+ subType: z.number().nullish().transform(nullToUndefined),
+ order: z.number().nullish().transform(nullToUndefined),
+});
+
export interface UpdatePublicURL {
collectionID: number;
disablePassword?: boolean;
diff --git a/web/packages/media/magic-metadata.ts b/web/packages/media/magic-metadata.ts
index 17ed4d7ca7..5d9ed2c1c7 100644
--- a/web/packages/media/magic-metadata.ts
+++ b/web/packages/media/magic-metadata.ts
@@ -190,7 +190,7 @@ export const createMagicMetadata = (data: unknown) => {
export const decryptMagicMetadata = async (
remoteMagicMetadata: RemoteMagicMetadata,
key: string,
-): Promise<MagicMetadata | undefined> => {
+): Promise<MagicMetadata> => {
const {
version,
count,