Skip to content

armgit / ente

Public Imported from GitHub
0

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

C2

Manav Rathi228bf55a8d67
diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.ts
index cac7c3f25c..a59141214a 100644
--- a/web/packages/media/collection.ts
+++ b/web/packages/media/collection.ts
@@ -43,7 +43,7 @@ import { RemoteMagicMetadataSchema } from "./magic-metadata";
*
* In the remote schema, each item ({@link EnteFile}) is always associated
* with a collection. The same item may belong to multiple collections (See:
- * [Note: Collection File]), but it must belong to at least one collection.
+ * [Note: Collection file]), but it must belong to at least one collection.
*
* In some scenarios, e.g. when deleting the last collection to which a file
* belongs, the file would thus get orphaned and violate the schema
@@ -231,6 +231,57 @@ export const RemoteCollectionSchema = z.object({
export type RemoteCollection = z.infer<typeof RemoteCollectionSchema>;
export interface EncryptedCollection {
+ id: number;
+ owner: CollectionUser;
+ encryptedKey: string;
+ keyDecryptionNonce: string;
+ name?: string;
+ encryptedName: string;
+ nameDecryptionNonce: string;
+ type: CollectionType;
+ sharees: CollectionUser[];
+ publicURLs?: PublicURL[];
+ updationTime: number;
+ isDeleted: boolean;
+ magicMetadata: EncryptedMagicMetadata;
+ pubMagicMetadata: EncryptedMagicMetadata;
+ sharedMagicMetadata: EncryptedMagicMetadata;
+}
+
+export interface Collection
+ extends Omit<
+ EncryptedCollection,
+ | "encryptedKey"
+ | "keyDecryptionNonce"
+ | "encryptedName"
+ | "nameDecryptionNonce"
+ | "magicMetadata"
+ | "pubMagicMetadata"
+ | "sharedMagicMetadata"
+ > {
+ key: string;
+ name: string;
+ magicMetadata: CollectionMagicMetadata;
+ pubMagicMetadata: CollectionPublicMagicMetadata;
+ sharedMagicMetadata: CollectionShareeMagicMetadata;
+}
+
+/**
+ * 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 contains zero or more files ({@link EnteFile}).
+ *
+ * A collection can be owned by the user (in whose context this code is
+ * running), or might be a collection that is shared with them.
+ *
+ * TODO: This type supercedes {@link Collection}. Once migration is done, rename
+ * this to drop the "2" suffix.
+ */
+export interface Collection2 {
/**
* The collection's globally unique ID.
*
@@ -253,34 +304,36 @@ export interface EncryptedCollection {
* - {@link role} will be blank.
*/
owner: CollectionUser;
- encryptedKey: string;
- keyDecryptionNonce: string;
- name?: string;
- encryptedName: string;
- nameDecryptionNonce: string;
/**
- * The type of the collection.
+ * The "collection key" (base64 encoded).
*
- * See the documentation of {@link CollectionType} for more details.
+ * The collection key is used to encrypt and decrypt that files that are
+ * associated with the collection. See: [Note: Collection file].
*/
- type: CollectionType;
+ key: string;
/**
- * TODO(RE): Remove me?
+ * The name of the collection.
+ */
+ name: string;
+ /**
+ * The type of the collection.
+ *
+ * Expected to be one of {@link CollectionType}.
*/
- attributes: collectionAttributes;
+ type: string; // CollectionType;
/**
* The other Ente users with whom the collection has been shared with.
*
* Within the {@link CollectionUser} instances of the {@link sharee} field:
*
* - {@link email} will be set.
- * - {@link role} will be one of "VIEWER" or "COLLABORATOR".
+ * - {@link role} is expected to be one of "VIEWER" or "COLLABORATOR".
*/
- sharees: CollectionUser[];
+ sharees?: CollectionUser[];
/**
- * Public links for the collection.
+ * Public links that can be used to access and update the collection.
*/
- publicURLs?: PublicURL[];
+ publicURLs?: unknown; // PublicURL[];
/**
* The last time the collection was updated (epoch microseconds).
*
@@ -290,45 +343,20 @@ export interface EncryptedCollection {
* - When the collection's own fields are modified.
*/
updationTime: number;
- isDeleted: boolean;
- magicMetadata: EncryptedMagicMetadata;
- pubMagicMetadata: EncryptedMagicMetadata;
- sharedMagicMetadata: EncryptedMagicMetadata;
-}
-
-export interface Collection
- extends Omit<
- EncryptedCollection,
- | "encryptedKey"
- | "keyDecryptionNonce"
- | "encryptedName"
- | "nameDecryptionNonce"
- | "magicMetadata"
- | "pubMagicMetadata"
- | "sharedMagicMetadata"
- > {
- /**
- * The "collection key" (base64 encoded).
- */
- key: string;
- /**
- * The name of the collection.
- */
- name: string;
/**
* Mutable metadata associated with the collection that is only visible to
* the owner of the collection.
*
* See: [Note: Metadatum]
*/
- magicMetadata: CollectionMagicMetadata;
+ magicMetadata?: unknown; //CollectionMagicMetadata;
/**
* Public mutable metadata associated with the collection that is visible to
* all users with whom the collection has been shared.
*
* See: [Note: Metadatum]
*/
- pubMagicMetadata: CollectionPublicMagicMetadata;
+ pubMagicMetadata?: unknown; //CollectionPublicMagicMetadata;
/**
* Private mutable metadata associated with the collection that is only
* visible to the current user, if they're not the owner.
@@ -341,7 +369,7 @@ export interface Collection
*
* See: [Note: Metadatum]
*/
- sharedMagicMetadata: CollectionShareeMagicMetadata;
+ sharedMagicMetadata?: unknown; // CollectionShareeMagicMetadata;
}
export interface PublicURL {
@@ -394,7 +422,7 @@ interface CollectionDecryptionUser {
export const decryptRemoteCollection = (
remoteCollection: RemoteCollection,
user: CollectionDecryptionUser,
-) => {};
+): Promise<Collection> => {};
export interface UpdatePublicURL {
collectionID: number;
@@ -415,11 +443,6 @@ export interface CreatePublicAccessTokenRequest {
deviceLimit?: number;
}
-export interface collectionAttributes {
- encryptedPath?: string;
- pathDecryptionNonce?: string;
-}
-
export interface RemoveFromCollectionRequest {
collectionID: number;
fileIDs: number[];
diff --git a/web/packages/media/file.ts b/web/packages/media/file.ts
index c5d8937e58..9315ce233d 100644
--- a/web/packages/media/file.ts
+++ b/web/packages/media/file.ts
@@ -79,7 +79,7 @@ export interface EncryptedEnteFile {
*
* The same file (ID) may be associated with multiple collectionID, in which
* case there will be multiple {@link EnteFile} entries for each
- * ({@link id}, {@link collectionID}) pair. See: [Note: Collection File].
+ * ({@link id}, {@link collectionID}) pair. See: [Note: Collection file].
*/
collectionID: number;
/**
@@ -152,7 +152,7 @@ export interface EncryptedEnteFile {
* While the file ID is unique, we'd can still have multiple entries for each
* file ID in our local state, one per collection IDs to which the file belongs.
* That is, the uniqueness is across the (fileID, collectionID) pairs. See
- * [Note: Collection File].
+ * [Note: Collection file].
*/
export interface EnteFile
extends Omit<
diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts
index 56752ee480..fadbb67c9a 100644
--- a/web/packages/new/photos/services/files.ts
+++ b/web/packages/new/photos/services/files.ts
@@ -188,13 +188,14 @@ export const sortFiles = (files: EnteFile[], sortAsc = false) => {
};
/**
- * [Note: Collection File]
+ * [Note: Collection file]
*
* File IDs themselves are unique across all the files for the user (in fact,
- * they're unique across all the files in an Ente instance). However, we still
- * can have multiple entries for the same file ID in our local database because
- * the unit of account is not actually a file, but a "Collection File": a
- * collection and file pair.
+ * they're unique across all the files in an Ente instance).
+ *
+ * However, we can have multiple entries for the same file ID in our local
+ * database and/or remote responses because the unit of account is not file, but
+ * a "Collection File" – a collection and file pair.
*
* For example, if the same file is symlinked into two collections, then we will
* have two "Collection File" entries for it, both with the same file ID, but