[web] Handle NaN in the Exif locations
A customer sent us a sample file from the wild where this was the case.
This commit is contained in:
@@ -826,6 +826,7 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
|
||||
const longitude = nullToUndefined(file.metadata.longitude);
|
||||
|
||||
if (latitude === undefined || longitude === undefined) return undefined;
|
||||
if (Number.isNaN(latitude) || Number.isNaN(longitude)) return undefined;
|
||||
|
||||
return { latitude, longitude };
|
||||
};
|
||||
|
||||
@@ -51,13 +51,19 @@ export const parseExif = (tags: RawExifTags) => {
|
||||
|
||||
/**
|
||||
* Parse GPS location from the metadata embedded in the file.
|
||||
*
|
||||
* - If a location is returned, then both latitude and longitude will be
|
||||
* defined.
|
||||
* - NaNs are ignored, and treated as if they are not defined.
|
||||
*/
|
||||
const parseLocation = (tags: RawExifTags) => {
|
||||
const latitude = tags.gps?.Latitude;
|
||||
const longitude = tags.gps?.Longitude;
|
||||
return latitude !== undefined && longitude !== undefined
|
||||
? { latitude, longitude }
|
||||
: undefined;
|
||||
|
||||
if (latitude === undefined || longitude === undefined) return undefined;
|
||||
if (Number.isNaN(latitude) || Number.isNaN(longitude)) return undefined;
|
||||
|
||||
return { latitude, longitude };
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,10 +8,10 @@ export const ensureString = (v: unknown): string => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Throw an exception if the given value is not a number.
|
||||
* Throw an exception if the given value is not a number or if it is NaN.
|
||||
*/
|
||||
export const ensureNumber = (v: unknown): number => {
|
||||
if (typeof v != "number")
|
||||
if (typeof v != "number" || Number.isNaN(v))
|
||||
throw new Error(`Expected a number, instead found ${String(v)}`);
|
||||
return v;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user