Skip to content

armgit / ente

Public Imported from GitHub
0

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

Rename

Manav Rathifa00c06cf8fb
diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.ts
index 013830ff89..9c5d806b2b 100644
--- a/web/apps/photos/src/services/upload/takeout.ts
+++ b/web/apps/photos/src/services/upload/takeout.ts
@@ -34,7 +34,17 @@ export const MAX_FILE_NAME_LENGTH_GOOGLE_EXPORT = 46;
const EDITED_FILE_SUFFIX = "-edited";
const METADATA_SUFFIX = ".supplemental-metadata";
-export const getMetadataJSONMapKeyForJSON = (
+/**
+ * Derive a key for the given {@link jsonFileName} that should be used to index
+ * into the metadata JSON map.
+ *
+ * @param collectionID The collection to which we're uploading.
+ *
+ * @param jsonFileName The file name for the JSON file.
+ *
+ * @returns A key suitable for indexing into the {@link ParsedMetadataJSON} map.
+ */
+export const metadataJSONMapKeyForJSON = (
collectionID: number,
jsonFileName: string,
) => {
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index 3f0cd395a9..6e006797ac 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -34,7 +34,7 @@ import {
import watcher from "services/watch";
import { getUserOwnedFiles } from "utils/file";
import {
- getMetadataJSONMapKeyForJSON,
+ metadataJSONMapKeyForJSON,
tryParseTakeoutMetadataJSON,
type ParsedMetadataJSON,
} from "./takeout";
@@ -522,7 +522,7 @@ class UploadManager {
const metadataJSON = await tryParseTakeoutMetadataJSON(uploadItem!);
if (metadataJSON) {
this.parsedMetadataJSONMap.set(
- getMetadataJSONMapKeyForJSON(collectionID, fileName),
+ metadataJSONMapKeyForJSON(collectionID, fileName),
metadataJSON,
);
this.uiService.increaseFileUploaded();
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 0d79ce3999..5707634715 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -10,8 +10,8 @@ import {
getClippedMetadataJSONMapKeyForFile,
getFileNameComponents,
getMetadataJSONMapKeyForFile,
- getMetadataJSONMapKeyForJSON,
getSupplementaryMetadataJSONMapKeyForFile,
+ metadataJSONMapKeyForJSON,
} from "services/upload/takeout";
import { getUserDetailsV2 } from "services/userService";
@@ -427,32 +427,23 @@ function parseDateTimeFromFileNameTest() {
const fileNameToJSONMappingTests = () => {
fileNameToJSONMappingCases.forEach(({ filename, jsonFilename }) => {
- const jsonFileNameGeneratedKey = getMetadataJSONMapKeyForJSON(
- 0,
- jsonFilename,
- );
+ const jsonKey = metadataJSONMapKeyForJSON(0, jsonFilename);
// This duplicates somewhat the logic in takeout.ts:matchTakeoutMetadata()
const components = getFileNameComponents(filename);
- let fileNameGeneratedKey = getMetadataJSONMapKeyForFile(0, components);
- if (fileNameGeneratedKey !== jsonFileNameGeneratedKey) {
- fileNameGeneratedKey = getClippedMetadataJSONMapKeyForFile(
- 0,
- components,
- );
+ let fileKey = getMetadataJSONMapKeyForFile(0, components);
+ if (fileKey !== jsonKey) {
+ fileKey = getClippedMetadataJSONMapKeyForFile(0, components);
}
- if (fileNameGeneratedKey !== jsonFileNameGeneratedKey) {
- fileNameGeneratedKey = getSupplementaryMetadataJSONMapKeyForFile(
- 0,
- components,
- );
+ if (fileKey !== jsonKey) {
+ fileKey = getSupplementaryMetadataJSONMapKeyForFile(0, components);
}
- if (fileNameGeneratedKey !== jsonFileNameGeneratedKey) {
+ if (fileKey !== jsonKey) {
throw Error(
`mappingFileAndJSONFileCheck failed ❌ ,
for ${filename}
- expected: ${jsonFileNameGeneratedKey} got: ${fileNameGeneratedKey}`,
+ expected: ${jsonKey} got: ${fileKey}`,
);
}
});