Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(metadata-json):fix-XMP-location-parsing-issue

Aswin Asokefeb857e59f8
diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.ts
index 24260568b2..058a0afe6f 100644
--- a/web/apps/photos/tests/upload.test.ts
+++ b/web/apps/photos/tests/upload.test.ts
@@ -206,6 +206,32 @@ describe("Apple Photos XMP sidecars", () => {
).toEqual({ latitude, longitude });
});
+ test.each([
+ [
+ "8.5683539130357",
+ "N",
+ "76.873247987321",
+ "E",
+ 8.5683539130357,
+ 76.873247987321,
+ ],
+ ["33.448889", "S", "70.669265", "W", -33.448889, -70.669265],
+ ])(
+ "parses decimal GPS coordinates with separate %s/%s references",
+ (lat, latRef, long, longRef, latitude, longitude) => {
+ expect(
+ parseXMPSidecarTags({
+ xmp: {
+ GPSLatitude: xmpTag(lat),
+ GPSLatitudeRef: xmpTag(latRef),
+ GPSLongitude: xmpTag(long),
+ GPSLongitudeRef: xmpTag(longRef),
+ },
+ })?.location,
+ ).toEqual({ latitude, longitude });
+ },
+ );
+
test("omits a location with only one GPS axis", () => {
expect(
parseXMPSidecarTags({ xmp: { GPSLatitude: xmpTag("12.97236N") } }),
diff --git a/web/packages/gallery/services/upload/metadata-json.ts b/web/packages/gallery/services/upload/metadata-json.ts
index efca3d768f..5f6ad1dc5b 100644
--- a/web/packages/gallery/services/upload/metadata-json.ts
+++ b/web/packages/gallery/services/upload/metadata-json.ts
@@ -122,17 +122,29 @@ export const parseXMPSidecarTags = (
tags: RawExifTags,
): ParsedMetadataJSON | undefined => {
const { creationDate, description } = parseExif(tags);
- const parseCoordinate = (value: string | undefined) => {
- const match = /^(\d+(?:\.\d+)?)(?:,(\d+(?:\.\d+)?))?([NSEW])$/.exec(
+ const parseCoordinate = (
+ value: string | undefined,
+ reference: string | undefined,
+ ) => {
+ const match = /^(\d+(?:\.\d+)?)(?:,(\d+(?:\.\d+)?))?([NSEW])?$/.exec(
value ?? "",
);
if (!match) return undefined;
+ const direction = match[3] ?? reference?.trim().toUpperCase();
+ if (!direction || !/^[NSEW]$/.test(direction)) return undefined;
+
const coordinate = Number(match[1]) + Number(match[2] ?? 0) / 60;
- return match[3] == "S" || match[3] == "W" ? -coordinate : coordinate;
+ return direction == "S" || direction == "W" ? -coordinate : coordinate;
};
- const latitude = parseCoordinate(tags.xmp?.GPSLatitude?.description);
- const longitude = parseCoordinate(tags.xmp?.GPSLongitude?.description);
+ const latitude = parseCoordinate(
+ tags.xmp?.GPSLatitude?.description,
+ tags.xmp?.GPSLatitudeRef?.description,
+ );
+ const longitude = parseCoordinate(
+ tags.xmp?.GPSLongitude?.description,
+ tags.xmp?.GPSLongitudeRef?.description,
+ );
const location =
latitude != undefined && longitude != undefined
? { latitude, longitude }