💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Outline
Manav Rathi74c5b22927b9
diff --git a/web/packages/media/file.ts b/web/packages/media/file.tsindex c840500498..383be70d21 100644--- a/web/packages/media/file.ts+++ b/web/packages/media/file.ts@@ -2,3 +2,73 @@ import type { Metadata } from "./types/file";export const hasFileHash = (file: Metadata) =>!!file.hash || (!!file.imageHash && !!file.videoHash);++/**+ * [Note: Photos are always in local date/time]+ *+ * Photos out in the wild frequently do not have associated timezone offsets for+ * the datetime embedded in their metadata. This is a artifact of an era where+ * cameras didn't know often even know their date/time correctly, let alone the+ * UTC offset of their local data/time.+ *+ * This is beginning to change with smartphone cameras, and is even reflected in+ * the standards. e.g. Exif metadata now has auxillary "OffsetTime*" tags for+ * indicating the UTC offset of the local date/time in the existing Exif tags+ * (See: [Note: Exif dates]).+ *+ * So a photos app needs to deal with a mixture of photos whose dates may or may+ * not have UTC offsets. This is fact #1.+ *+ * Users expect to see the time they took the photo, not the time in the place+ * they are currently. People expect a New Year's Eve photo from a vacation to+ * show up as midnight, not as (e.g.) 19:30 IST. This is fact #2.+ *+ * Combine these two facts, and if you ponder a bit, you'll find that there is+ * only one way for a photos app to show / sort / label (as a day) – by using+ * the local datetime without the attached UTC offset **even if it is present**.+ *+ * The UTC offset is still useful though, and we don't want to lose that+ * information. The number of photos with a UTC offset will only increase. And+ * whenever it is present, it provides additional context for the user.+ *+ * So we keep both the local date/time string (an ISO8601 string guaranteed to+ * be without an associated UTC offset), and an (optional) UTC offset string.+ *+ * It is important to NOT think of the local date/time string as an instant of+ * time that can be converted to a UTC timestamp. It cannot be converted to a+ * UTC timestamp because while it itself might have the optional associated UTC+ * offset, its siblings photos might not. The only way to retain their+ * comparability is to treat them all the "time zone where the photo was taken".+ *+ * Finally, while this is all great, we still have existing code that deals with+ * UTC timestamps. So we also retain the existing `creationTime` UTC timestamp,+ * but this should be considered deprecated, and over time we should move+ * towards using the `dateTime` string.+ */+export interface ParsedMetadataDate {+ /**+ * A local date/time.+ *+ * This is a partial ISO8601 datetime string guaranteed not to have a+ * timezone offset. e.g. "2023-08-23T18:03:00.000"+ */+ dateTime: string;+ /**+ * An optional offset from UTC.+ *+ * This is an optional UTC offset string of the form "±HH:mm" or "Z",+ * specifying the timezone offset for {@link dateTime} when available.+ */+ offsetTime: string | undefined;+ /**+ * UTC epoch microseconds derived from {@link dateTime} and+ * {@link offsetTime}.+ *+ * When the {@link offsetTime} is present, this will accurately reflect a+ * UTC timestamp. When the {@link offsetTime} is not present, this is not+ * necessarily accurate, since it then assumes that the given+ * {@link dateTime} is in the local time where this code is running. This is+ * a good assumption but not always correct (e.g. vacation photos).+ */+ timestamp: number;+}diff --git a/web/packages/media/types/file.ts b/web/packages/media/types/file.tsindex 99bdd43638..ff91caee4f 100644--- a/web/packages/media/types/file.ts+++ b/web/packages/media/types/file.ts@@ -1,3 +1,4 @@+import type { ParsedMetadataDate } from "../file";import type { FileType } from "../file-type";/**@@ -116,6 +117,15 @@ export interface ParsedMetadata {width?: number;/** The height of the image, in pixels. */height?: number;+ /**+ * The date (and time) when this photo was taken.+ *+ * This in the local timezone of the place where the photo was taken, but it+ * also has additional fields we need.+ *+ * See: [Note: Photos are always in local date/time]+ */+ creationMetadataDate?: ParsedMetadataDate /** TODO: Exif */;/** The time when this photo was taken. */creationTime?: number;/** The GPS coordinates where the photo was taken. */diff --git a/web/packages/new/photos/services/exif.ts b/web/packages/new/photos/services/exif.tsindex 61ecbe7b8b..80fdb98083 100644--- a/web/packages/new/photos/services/exif.ts+++ b/web/packages/new/photos/services/exif.ts@@ -362,11 +362,12 @@ const parseIPTCDate = (// - There are currently no separate TypeScript types for the IPTC tags,// and instead they are listed as part of the ExifTags.//- // - For the date, ExifReader parses the raw data into a description of- // the form 'YYYY-MM-DD' (See `getCreationDate` in its source code).+ // - For the date, whenever possible ExifReader parses the raw data into a+ // description of the form 'YYYY-MM-DD' (See `getCreationDate` in its+ // source code).//- // - For the time, ExifReader parses the raw data into a description- // either of the form 'HH:mm:ss` or `HH:mm:ss±HH:mm` (See+ // - For the time, whenever possible ExifReader parses the raw data into a+ // description either of the form 'HH:mm:ss` or `HH:mm:ss±HH:mm` (See// `getCreationTime` in its source code).if (!dateTag) return undefined;let s = dateTag.description;