Skip to content

armgit / ente

Public Imported from GitHub
0

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

Notes and changes based on discussion

Manav Rathi24674f6da69a
diff --git a/web/apps/photos/src/services/deduplicationService.ts b/web/apps/photos/src/services/deduplicationService.ts
index bb36e1a7ba..fb2b9237b9 100644
--- a/web/apps/photos/src/services/deduplicationService.ts
+++ b/web/apps/photos/src/services/deduplicationService.ts
@@ -173,7 +173,10 @@ async function sortDuplicateFiles(
}
function areFileHashesSame(firstFile: Metadata, secondFile: Metadata) {
- if (firstFile.fileType === FileType.livePhoto) {
+ if (
+ firstFile.fileType === FileType.livePhoto &&
+ firstFile.hash === undefined
+ ) {
return (
firstFile.imageHash === secondFile.imageHash &&
firstFile.videoHash === secondFile.videoHash
diff --git a/web/apps/photos/src/services/upload/upload-service.ts b/web/apps/photos/src/services/upload/upload-service.ts
index 57da2c4a40..2ee52a83bc 100644
--- a/web/apps/photos/src/services/upload/upload-service.ts
+++ b/web/apps/photos/src/services/upload/upload-service.ts
@@ -968,16 +968,17 @@ const extractLivePhotoMetadata = async (
worker,
);
+ const imageHash = imageMetadata.hash;
const videoHash = await computeHash(livePhotoAssets.video, worker);
+ const hash = `${imageHash}:${videoHash}`;
+
return {
metadata: {
...imageMetadata,
title: uploadItemFileName(livePhotoAssets.image),
fileType: FileType.livePhoto,
- imageHash: imageMetadata.hash,
- videoHash: videoHash,
- hash: undefined,
+ hash,
},
publicMagicMetadata,
};
@@ -1148,7 +1149,10 @@ const areFilesSameHash = (f: Metadata, g: Metadata) => {
if (f.fileType !== g.fileType || f.title !== g.title) {
return false;
}
- if (f.fileType === FileType.livePhoto) {
+ if (
+ f.fileType === FileType.livePhoto &&
+ (f.hash === undefined || g.hash === undefined)
+ ) {
return f.imageHash === g.imageHash && f.videoHash === g.videoHash;
} else {
return f.hash === g.hash;
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index e31f482990..4f5fab3830 100644
--- a/web/packages/media/file-metadata.ts
+++ b/web/packages/media/file-metadata.ts
@@ -101,16 +101,37 @@ export interface Metadata {
/**
* A hash of the file's contents.
*
- * It is only valid for images and videos. For live photos, see
- * {@link imageHash} and {@link videoHash}.
+ * For images and videos this is the hash of the file's contents. For live
+ * photos, this is the image hash joined with video hash using a colon (i.e.
+ * `${imageHash}:{videoHash}`).
+ *
+ * Legacy compatibility:
+ *
+ * - The hash might not be present for files uploaded from ancient versions
+ * of Ente (Newer clients will always include it in the metadata).
+ *
+ * - For live photos, older version of the web and desktop client used to
+ * add two separate fields - {@link imageHash} and {@link videoHash} - to
+ * the file's metadata instead of setting the {@link hash}. This behaviour
+ * is deprecated, and if we now see a live photo without a {@link hash},
+ * we should reconstruct the hash locally from the image and video hashes
+ * by combining them as `${imageHash}:{videoHash}`.
*/
hash?: string;
/**
* The hash of the image component of a live photo.
+ *
+ * This is a legacy field, and should not be added by us anymore. It is
+ * retained to allow us to reconstruct the hash for live photos uploaded by
+ * older clients.
*/
imageHash?: string;
/**
* The hash of the video component of a live photo.
+ *
+ * This is a legacy field, and should not be added by us anymore. It is
+ * retained to allow us to reconstruct the hash for live photos uploaded by
+ * older clients.
*/
videoHash?: string;
hasStaticThumbnail?: boolean;
diff --git a/web/packages/media/file.ts b/web/packages/media/file.ts
index 44817ad08d..276f7de985 100644
--- a/web/packages/media/file.ts
+++ b/web/packages/media/file.ts
@@ -7,8 +7,22 @@ export interface MetadataFileAttributes {
decryptionHeader: string;
}
+/**
+ * Attributes about an object uploaded to S3.
+ *
+ * TODO: Split between fields needed during upload, and the fields we get back
+ * from remote in the /diff response.
+ */
export interface S3FileAttributes {
+ /**
+ * Upload only: This should be present during upload, but is not returned
+ * back from remote in the /diff response.
+ */
objectKey: string;
+ /**
+ * Upload and diff: This is present both during upload and also returned by
+ * remote in the /diff response.
+ */
decryptionHeader: string;
/**
* The size of the file, in bytes.
@@ -17,6 +31,9 @@ export interface S3FileAttributes {
* encrypted file (as per the client) while creating a new object on remote.
* This allows the server to validate that the size of the objects is same
* as what client is reporting.
+ *
+ * Upload only: This should be present during upload, but is not returned
+ * back from remote in the /diff response.
*/
size: number;
}
@@ -96,7 +113,9 @@ export interface EncryptedEnteFile {
* See: [Note: Metadatum].
*/
pubMagicMetadata: EncryptedMagicMetadata;
+ /* always present */
encryptedKey: string;
+ /* always present */
keyDecryptionNonce: string;
isDeleted: boolean;
updationTime: number;
diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.ts
index 0c8d771f5d..6d3b8260a1 100644
--- a/web/packages/new/photos/services/dedup.ts
+++ b/web/packages/new/photos/services/dedup.ts
@@ -58,7 +58,7 @@ export interface DuplicateGroup {
*
* Detecting duplicates:
*
- * 1. Identify and divide files into multiple groups based on (size + hash).
+ * 1. Identify and divide files into multiple groups based on hash.
*
* 2. By default select all group, with option to unselect individual groups or
* all groups.
@@ -79,14 +79,17 @@ export interface DuplicateGroup {
* 4. Delete the remaining files.
*/
export const deduceDuplicates = async () => {
+ // TODO: Ignore non-owned files.
const collectionFiles = await getLocalFiles();
const files = uniqueFilesByID(collectionFiles);
+ // TODO: Only do a hash comparison
+
const filesByHash = new Map<string, EnteFile[]>();
for (const file of files) {
let hash = file.metadata.hash;
if (!hash && file.metadata.imageHash && file.metadata.videoHash)
- hash = `${file.metadata.imageHash}_${file.metadata.hash}`;
+ hash = `${file.metadata.imageHash}_${file.metadata.videoHash}`;
if (!hash) {
// Some very old files uploaded by ancient versions of Ente might
// not have hashes. Ignore these.
@@ -146,5 +149,7 @@ export const removeSelectedDuplicateGroups = async (
duplicateGroups: DuplicateGroup[],
) => {
console.log(duplicateGroups);
+ for (const duplicateGroup of duplicateGroups) {
+ }
await wait(1000);
};
diff --git a/web/packages/new/photos/services/files.ts b/web/packages/new/photos/services/files.ts
index 8713a5d43f..112dc2ea52 100644
--- a/web/packages/new/photos/services/files.ts
+++ b/web/packages/new/photos/services/files.ts
@@ -179,7 +179,7 @@ export const clearCachedThumbnailsIfChanged = async (
// differ, which indicates that the change was in the file's contents,
// not the metadata itself, and thus we should refresh the thumbnail.
if (
- m1.fileType == FileType.livePhoto
+ m1.fileType == FileType.livePhoto && m1.imageHash
? m1.imageHash != m2.imageHash
: m1.hash != m2.hash
) {