Skip to content

armgit / ente

Public Imported from GitHub
0

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

Comments

Manav Rathi8a217a292b8f
diff --git a/web/packages/media/file.ts b/web/packages/media/file.ts
index e44846ab54..44817ad08d 100644
--- a/web/packages/media/file.ts
+++ b/web/packages/media/file.ts
@@ -21,11 +21,17 @@ export interface S3FileAttributes {
size: number;
}
+/**
+ * Static information associated with a file.
+ */
export interface FileInfo {
/**
- * The size of the file, in bytes.
+ * The size of the file (in bytes).
*/
fileSize: number;
+ /**
+ * The size of the thumbnail associated with the file (in bytes).
+ */
thumbSize: number;
}
@@ -39,14 +45,56 @@ export interface MagicMetadataCore<T> {
export type EncryptedMagicMetadata = MagicMetadataCore<string>;
export interface EncryptedEnteFile {
+ /**
+ * The file's ID.
+ *
+ * The file's ID is a integer assigned by remote that is unique across all
+ * files stored by an Ente instance. That is, the file ID is a global unique
+ * identifier for this {@link EnteFile}.
+ */
id: number;
+ /**
+ * The ID of the collection with which this file as associated.
+ *
+ * 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].
+ */
collectionID: number;
+ /**
+ * The ID of the user who owns the file.
+ */
ownerID: number;
file: S3FileAttributes;
thumbnail: S3FileAttributes;
+ /**
+ * Static metadata associated with a file.
+ *
+ * See: [Note: Metadatum].
+ */
metadata: MetadataFileAttributes;
+ /**
+ * Static, remote visible, information associated with a file.
+ *
+ * This is information about storage used by the file and its metadata (in
+ * the future if needed). Unlike {@link metadata} which is E2EE, the
+ * {@link FileInfo} is remote visible for bookkeeping purposes.
+ *
+ * Files uploaded by very old versions of Ente might not have this structure
+ * present.
+ */
info: FileInfo | undefined;
+ /**
+ * Private mutable metadata associated with a file.
+ *
+ * See: [Note: Metadatum].
+ */
magicMetadata: EncryptedMagicMetadata;
+ /**
+ * Public mutable metadata associated with a file.
+ *
+ * See: [Note: Metadatum].
+ */
pubMagicMetadata: EncryptedMagicMetadata;
encryptedKey: string;
keyDecryptionNonce: string;
@@ -65,6 +113,11 @@ export interface EncryptedEnteFile {
* an Ente instance. Each file is also always associated with a collection, and
* has an owner (both of these linkages are stored as the corresponding numeric
* IDs within the EnteFile structure).
+ *
+ * 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 Files].
*/
export interface EnteFile
extends Omit<
diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts
index 240fbdfa67..8713a5d43f 100644
--- a/web/packages/new/photos/services/files.ts
+++ b/web/packages/new/photos/services/files.ts
@@ -66,6 +66,8 @@ export const sortFiles = (files: EnteFile[], sortAsc = false) => {
};
/**
+ * [Note: Collection Files]
+ *
* 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
@@ -76,8 +78,14 @@ export const sortFiles = (files: EnteFile[], sortAsc = false) => {
* have two "Collection File" entries for it, both with the same file ID, but
* with different collection IDs.
*
- * This function returns files such that only one of these entries (the newer
- * one in case of dupes) is returned.
+ * This function returns files such that only one of these entries is returned.
+ * The entry that is returned is arbitrary in general, this function just picks
+ * the first one for each unique file ID.
+ *
+ * If this function is invoked on a list on which {@link sortFiles} has already
+ * been called, which by default sorts such that the newest file is first, then
+ * this function's behaviour would be to return the newest file from among
+ * multiple files with the same ID but different collections.
*/
export const uniqueFilesByID = (files: EnteFile[]) => {
const seen = new Set<number>();