💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Outline
Manav Rathi870697daf837
diff --git a/web/packages/new/photos/services/exif-update.ts b/web/packages/new/photos/services/exif-update.tsindex ed7fc74ead..5df306e5c5 100644--- a/web/packages/new/photos/services/exif-update.ts+++ b/web/packages/new/photos/services/exif-update.ts@@ -120,54 +120,20 @@ const dataURLToBlob = (dataURI: string) =>* Convert the given {@link Date} to a format that is expected by Exif for the* DateTimeOriginal tag.*- * [Note: Exif dates]- *- * Summary:- *- * DateTimeOriginal is in local time, not UTC. Which local time? The- * OffsetTimeOriginal specifies the time zone. But support for it is limited.- *- * Details:- *- * Common Exif date time tags, an in particular "DateTimeOriginal", are- * specified in the form:- *- * yyyy:MM:DD HH:mm:ss- *- * These values thus do not have an associated UTC offset or TZ.- *- * The common convention is that these times are interpreted to be the local- * time where the photo was taken.- *- * > The reason (I assume) for this omission is because (prior to smartphones),- * > cameras did not have a good way of being aware of their time zone.- *- * Recently, there seems to be increasing support for the newly standardized- * "OffsetTimeOriginal" and siblings, which specify time zone for- * "DateTimeOriginal" (and related fields).- *- * However, support is still not universal, and there will anyways be older- * photos. So when the offset is missing, we stick with the common convention:- *- * - When reading, assume that the Exif date is in the local TZ when deriving- * a UTC timestamp from it.- *- * - When writing, convert the UTC timestamp to local time.- *- * These assumptions are fallible, because the local time where we're uploading- * or downloading the photo is not necessarily the same as the local time where- * the photo was taken.+ * See: [Note: Exif dates]*/const convertToExifDateFormat = (date: Date) => {// TODO: Exif - Handle offsettime if present- const yyyy = date.getFullYear();+ const YYYY = zeroPad(date.getFullYear(), 4);+ // JavaScript getMonth is zero-indexed, we want one-indexed.const MM = zeroPad(date.getMonth() + 1, 2);- const dd = zeroPad(date.getDate(), 2);+ // JavaScript getDate is NOT zero-indexed, it is already one-indexed.+ const DD = zeroPad(date.getDate(), 2);const HH = zeroPad(date.getHours(), 2);const mm = zeroPad(date.getMinutes(), 2);const ss = zeroPad(date.getSeconds(), 2);- return `${yyyy}:${MM}:${dd} ${HH}:${mm}:${ss}`;+ return `${YYYY}:${MM}:${DD} ${HH}:${mm}:${ss}`;};/** Zero pad the given number to {@link d} digits. */diff --git a/web/packages/new/photos/services/exif.ts b/web/packages/new/photos/services/exif.tsindex c522c7a6f1..b2b7b62cd7 100644--- a/web/packages/new/photos/services/exif.ts+++ b/web/packages/new/photos/services/exif.ts@@ -26,6 +26,75 @@ import type { EnteFile } from "../types/file";// eslint-disable-next-line @typescript-eslint/no-empty-functionexport const extractExif = () => {};+/**+ * Parse a date from an Exif date and offset tag combination.+ *+ * @param tags Metadata tags associated with a file.+ *+ * @param dateTag The name of the date tag to use.+ *+ * @param offsetTag The name of the offset tag corresponding to {@link dateTag}.+ *+ * @returns a {@link Date} (UTC epoch milliseconds).+ *+ * [Note: Exif dates]+ *+ * The most important bit we usually wish out of Exif is the date and time when+ * the photo was taken. The Exif specification has the following tags related to+ * photo's date:+ *+ * - DateTimeOriginal+ * - DateTime (aka "ModifyDate")+ * - DateTimeDigitized (aka "CreateDate")+ *+ * DateTimeOriginal is meant to signify best when the original image was taken,+ * and we use it as the photo's creation date whenever it is present. If not, we+ * fallback to DateTime or DateTimeDigitized (in that order).+ *+ * Each of these is a string of the format+ *+ * YYYY:MM:DD HH:mm:ss+ *+ * where+ *+ * YYYY 4 digit (zero padded) year+ * MM 2 digit (zero padded) month, with Jan as 01 and Dec as 12.+ * DD 2 digit (zero padded) day of the month (1 to 31)+ * HH 2 digit (zero padded) hours since midnight (00 to 23)+ * mm 2 digit (zero padded) minutes (00 to 59)+ * ss 2 digit (zero padded) seconds (00 to 59)+ *+ * These dates are all in the local time of the place where the photo was taken.+ * To convert these to UTC, we also need to know the offset from UTC of that+ * local time. This is provided by the three OffsetTime* tags (one for each of+ * the above):+ *+ * - OffsetTimeOriginal+ * - OffsetTime+ * - OffsetTimeDigitized+ *+ * Each of these is a string of the format+ *+ * ±HH:mm+ *+ * denoting the signed hour and minute offset from UTC.+ *+ * Note that these OffsetTime* tags are relatively new additions (prior to+ * smartphones, cameras did not have a good way of knowing their TZ), and most+ * old photos will not have this information. In such cases, we assume that+ * these photos are in the local time where this code is running. This is+ * manifestly going to be incorrect in some cases, but it is a better assumption+ * than assuming UTC, which, while deterministic, is going to incorrect in an+ * overwhelming majority of cases.+ */+const parseExifDate = (+ tags: ExifReader.ExpandedTags,+ dateTag: keyof ExifReader.ExifTags,+ offsetTag: keyof ExifReader.ExifTags,+) => {+ console.log(tags, dateTag, offsetTag);+};+/*** Index Exif in the given {@link EnteFile}.*