π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Latlng
Manav Rathi9e48010ee6bf
diff --git a/web/packages/base/types/index.ts b/web/packages/base/types/index.tsnew file mode 100644index 0000000000..10dc83fa67--- /dev/null+++ b/web/packages/base/types/index.ts@@ -0,0 +1,7 @@+/**+ * A location, represented as a (latitude, longitude) pair.+ */+export interface Location {+ latitude: number;+ longitude: number;+}diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.tsindex 011200ff95..2e0d95d430 100644--- a/web/packages/media/file-metadata.ts+++ b/web/packages/media/file-metadata.ts@@ -1,12 +1,14 @@import { decryptMetadataJSON, encryptMetadataJSON } from "@/base/crypto";import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { apiURL } from "@/base/origins";+import type { Location } from "@/base/types";import {type EnteFile,type FilePublicMagicMetadata,} from "@/new/photos/types/file";import { mergeMetadata1 } from "@/new/photos/utils/file";import { ensure } from "@/utils/ensure";+import { nullToUndefined } from "@/utils/transform";import { z } from "zod";import { FileType } from "./file-type";@@ -559,7 +561,7 @@ export interface ParsedMetadata {*/creationDate?: ParsedMetadataDate;/** The GPS coordinates where the photo was taken. */- location?: { latitude: number; longitude: number };+ location?: Location;}/**@@ -760,3 +762,22 @@ export const toUIDate = (dateLike: ParsedMetadataDate | string | number) => {return new Date(dateLike / 1000);}};++/**+ * Return the GPS coordinates (if any) present in the given {@link EnteFile}.+ */+export const fileLocation = (enteFile: EnteFile): Location | undefined => {+ // TODO: EnteFile types. Need to verify that metadata itself, and+ // metadata.lat/lng can not be null (I think they likely can, if so need to+ // update the types). Need to supress the linter meanwhile.++ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition+ if (!enteFile.metadata) return undefined;++ const latitude = nullToUndefined(enteFile.metadata.latitude);+ const longitude = nullToUndefined(enteFile.metadata.longitude);++ if (latitude === undefined || longitude === undefined) return undefined;++ return { latitude, longitude };+};diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.tsindex a80799ab0e..ab1ee935e4 100644--- a/web/packages/new/photos/services/search/types.ts+++ b/web/packages/new/photos/services/search/types.ts@@ -58,7 +58,7 @@ export interface SearchPerson {// TODO-cgroup: Audit below-export interface Location {+export interface LocationOld {latitude: number | null;longitude: number | null;}@@ -68,7 +68,7 @@ export interface LocationTagData {radius: number;aSquare: number;bSquare: number;- centerPoint: Location;+ centerPoint: LocationOld;}export interface City {diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.tsindex 50ab41a870..7e0800ae36 100644--- a/web/packages/new/photos/services/search/worker.ts+++ b/web/packages/new/photos/services/search/worker.ts@@ -13,7 +13,7 @@ import { expose } from "comlink";import type {City,DateSearchResult,- Location,+ LocationOld,LocationTagData,SearchDateComponents,SearchQuery,@@ -166,10 +166,13 @@ const isMatch = (file: EnteFile, query: SearchQuery) => {getUICreationDate(file, getPublicMagicMetadataSync(file)),);}++ const [latitude, longitude] = [file.metadata.latitude, file.metadata.longitude];+ if (latitude !== undefined && longitude !== undefined )if (query?.location) {return isInsideLocationTag({- latitude: file.metadata.latitude ?? null,+ latitude: ?? null,longitude: file.metadata.longitude ?? null,},query.location,@@ -221,11 +224,11 @@ const defaultCityRadius = 10;const kmsPerDegree = 111.16;const isInsideLocationTag = (- location: Location,+ location: LocationOld,locationTag: LocationTagData,) => isWithinRadius(location, locationTag.centerPoint, locationTag.radius);-const isInsideCity = (location: Location, city: City) =>+const isInsideCity = (location: LocationOld, city: City) =>isWithinRadius({ latitude: city.lat, longitude: city.lng },location,@@ -233,8 +236,8 @@ const isInsideCity = (location: Location, city: City) =>);const isWithinRadius = (- centerPoint: Location,- location: Location,+ centerPoint: LocationOld,+ location: LocationOld,radius: number,) => {const a =