Skip to content

armgit / ente

Public Imported from GitHub
0

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

update(metadata-json):existing-logic-takes-priority

Aswin Asok937c84a2975f
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 058a0afe6f..632de3ce6a 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -59,10 +59,22 @@ const metadataCases = [
"PXL_20241231_151646544.MP.jpg",
"PXL_20241231_151646544.MP.jpg.supplemental-met.json",
],
+ [
+ "PXL_20241231_151646544.MP.jpg",
+ "PXL_20241231_151646544.MP.jpg.supplemental-metadata.json",
+ ],
[
"PXL_20240827_094331806.PORTRAIT(1).jpg",
"PXL_20240827_094331806.PORTRAIT.jpg.supplement(1).json",
],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT.jpg.supplemental-metadata(1).json",
+ ],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT(1).jpg.supplemental-metadata.json",
+ ],
[
"PXL_20240506_142610305.LONG_EXPOSURE-01.COVER.jpg",
"PXL_20240506_142610305.LONG_EXPOSURE-01.COVER..json",
@@ -138,6 +150,65 @@ describe("upload filename metadata", () => {
expect(matchJSONMetadata(undefined, 0, fileName, map)).toBe(metadata);
});
+
+ test.each([
+ [
+ "PXL_20241231_151646544.MP.jpg",
+ "PXL_20241231_151646544.MP.jpg.supplemental-metadata.json",
+ "PXL_20241231_151646544.MP.jpg.supplemental-met.json",
+ ],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT.jpg.supplemental-metadata(1).json",
+ "PXL_20240827_094331806.PORTRAIT.jpg.supplement(1).json",
+ ],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT(1).jpg.supplemental-metadata.json",
+ "PXL_20240827_094331806.PORTRAIT(1).jpg.supplem.json",
+ ],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT.jpg.supplemental-metadata(1).json",
+ "PXL_20240827_094331806.PORTRAIT(1).jpg.supplem.json",
+ ],
+ [
+ "PXL_20240827_094331806.PORTRAIT(1).jpg",
+ "PXL_20240827_094331806.PORTRAIT(1).jpg.supplemental-metadata.json",
+ "PXL_20240827_094331806.PORTRAIT.jpg.supplement(1).json",
+ ],
+ ])(
+ "for %s uses %s only when %s is absent",
+ (fileName, fullJSONFileName, clippedJSONFileName) => {
+ const fullMetadata = { description: "full" };
+ const clippedMetadata = { description: "clipped" };
+ const map = new Map([
+ [
+ metadataJSONMapKeyForJSON(undefined, 0, fullJSONFileName),
+ fullMetadata,
+ ],
+ [
+ metadataJSONMapKeyForJSON(
+ undefined,
+ 0,
+ clippedJSONFileName,
+ ),
+ clippedMetadata,
+ ],
+ ]);
+
+ expect(matchJSONMetadata(undefined, 0, fileName, map)).toBe(
+ clippedMetadata,
+ );
+
+ map.delete(
+ metadataJSONMapKeyForJSON(undefined, 0, clippedJSONFileName),
+ );
+ expect(matchJSONMetadata(undefined, 0, fileName, map)).toBe(
+ fullMetadata,
+ );
+ },
+ );
});
describe("Apple Photos XMP sidecars", () => {
diff --git a/web/packages/gallery/services/upload/metadata-json.ts b/web/packages/gallery/services/upload/metadata-json.ts
index 4646ead2b2..0cf49d0c55 100644
--- a/web/packages/gallery/services/upload/metadata-json.ts
+++ b/web/packages/gallery/services/upload/metadata-json.ts
@@ -99,10 +99,6 @@ export const matchJSONMetadata = (
// Newer exports append this suffix, sometimes without clipping.
const supplSuffix = ".supplemental-metadata";
baseFileName = `${name}${extension}${supplSuffix}`;
- key = makeKey(`${baseFileName}${numberedSuffix}`);
- takeoutMetadata = parsedMetadataJSONMap.get(key);
- if (takeoutMetadata) return takeoutMetadata;
-
key = makeKey(
`${baseFileName.slice(0, maxGoogleFileNameLength)}${numberedSuffix}`,
);
@@ -113,11 +109,18 @@ export const matchJSONMetadata = (
// Some exports leave "(n)" before the extension.
if (numberedSuffix) {
const originalBaseFileName = `${originalName}${extension}${supplSuffix}`;
- key = makeKey(originalBaseFileName);
+ key = makeKey(originalBaseFileName.slice(0, maxGoogleFileNameLength));
takeoutMetadata = parsedMetadataJSONMap.get(key);
if (takeoutMetadata) return takeoutMetadata;
+ }
- key = makeKey(originalBaseFileName.slice(0, maxGoogleFileNameLength));
+ // Prefer existing clipped matches before trying untruncated sidecars.
+ key = makeKey(`${baseFileName}${numberedSuffix}`);
+ takeoutMetadata = parsedMetadataJSONMap.get(key);
+ if (takeoutMetadata) return takeoutMetadata;
+
+ if (numberedSuffix) {
+ key = makeKey(`${originalName}${extension}${supplSuffix}`);
takeoutMetadata = parsedMetadataJSONMap.get(key);
if (takeoutMetadata) return takeoutMetadata;
}