From a6cc6f24d080ce824b7d87c90c5fdf55db63b668 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 6 Aug 2024 20:05:27 +0530 Subject: [PATCH] Use newer fields --- .../FileInfo/RenderCreationTime.tsx | 37 +++++-------------- web/packages/media/file-metadata.ts | 30 +++++++++++---- .../photos/components/PhotoDateTimePicker.tsx | 6 +-- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCreationTime.tsx b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCreationTime.tsx index 0bba0c6897..d7b0a21e80 100644 --- a/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCreationTime.tsx +++ b/web/apps/photos/src/components/PhotoViewer/FileInfo/RenderCreationTime.tsx @@ -10,10 +10,6 @@ import ComlinkCryptoWorker from "@ente/shared/crypto"; import { formatDate, formatTime } from "@ente/shared/time/format"; import CalendarTodayIcon from "@mui/icons-material/CalendarToday"; import { useState } from "react"; -import { - changeFileCreationTime, - updateExistingFilePubMetadata, -} from "utils/file"; import InfoItem from "./InfoItem"; export function RenderCreationTime({ @@ -36,35 +32,22 @@ export function RenderCreationTime({ try { setLoading(true); if (isInEditMode && file) { - const unixTimeInMicroSec = pickedTime.timestamp; - if (unixTimeInMicroSec === file?.metadata.creationTime) { + const { dateTime, dateTimeOffset, timestamp } = pickedTime; + if (timestamp == file?.metadata.creationTime) { + // Same as before. closeEditMode(); return; } - const editedTime = unixTimeInMicroSec; log.debug(() => ["before", file.pubMagicMetadata]); - /* TODO(MR): Exif */ - // eslint-disable-next-line no-constant-condition - if (true) { - const updatedFile = await changeFileCreationTime( - file, - editedTime, - ); - updateExistingFilePubMetadata(file, updatedFile); - } - // eslint-disable-next-line no-constant-condition - if (false) { - const cryptoWorker = - await ComlinkCryptoWorker.getInstance(); - await updateRemotePublicMagicMetadata( - file, - { editedTime }, - cryptoWorker.encryptMetadata, - cryptoWorker.decryptMetadata, - ); - } + const cryptoWorker = await ComlinkCryptoWorker.getInstance(); + await updateRemotePublicMagicMetadata( + file, + { dateTime, dateTimeOffset, editedTime: timestamp }, + cryptoWorker.encryptMetadata, + cryptoWorker.decryptMetadata, + ); log.debug(() => ["after", file.pubMagicMetadata]); diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts index ae689797d9..fc6464c874 100644 --- a/web/packages/media/file-metadata.ts +++ b/web/packages/media/file-metadata.ts @@ -157,6 +157,22 @@ export enum ItemVisibility { * Also see: [Note: Zod doesn't work with `exactOptionalPropertyTypes` yet]. */ export interface PublicMagicMetadata { + /** + * A ISO 8601 date time string without a timezone, indicating the local time + * where the photo was taken. + * + * e.g. "2022-01-26T13:08:20". + * + * See: [Note: Photos are always in local date/time]. + */ + dateTime?: string; + /** + * When available, a "±HH:mm" string indicating the UTC offset for + * {@link dateTime}. + * + * e.g. "+02:00". + */ + dateTimeOffset?: string; /** * Modified value of the date time associated with an {@link EnteFile}. * @@ -575,13 +591,13 @@ export interface ParsedMetadataDate { * 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; + offset: string | undefined; /** * UTC epoch microseconds derived from {@link dateTime} and - * {@link offsetTime}. + * {@link offset}. * - * When the {@link offsetTime} is present, this will accurately reflect a - * UTC timestamp. When the {@link offsetTime} is not present it convert to a + * When the {@link offset} is present, this will accurately reflect a + * UTC timestamp. When the {@link offset} is not present it convert to a * UTC timestamp by assuming 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). @@ -626,7 +642,7 @@ export const parseMetadataDate = ( // Now we try to massage s into two parts - the local date/time string, and // an UTC offset string. - let offsetTime: string | undefined; + let offset: string | undefined; let sWithoutOffset: string; // Check to see if there is a time-zone descriptor of the form "Z" or @@ -634,7 +650,7 @@ export const parseMetadataDate = ( const m = s.match(/Z|[+-]\d\d:?\d\d$/); if (m?.index) { sWithoutOffset = s.substring(0, m.index); - offsetTime = s.substring(m.index); + offset = s.substring(m.index); } else { sWithoutOffset = s; } @@ -674,7 +690,7 @@ export const parseMetadataDate = ( // any time zone descriptor. const dateTime = dropLast(date.toISOString()); - return { dateTime, offsetTime, timestamp }; + return { dateTime, offset, timestamp }; }; const dropLast = (s: string) => (s ? s.substring(0, s.length - 1) : s); diff --git a/web/packages/new/photos/components/PhotoDateTimePicker.tsx b/web/packages/new/photos/components/PhotoDateTimePicker.tsx index cab2a51ddd..86859a3672 100644 --- a/web/packages/new/photos/components/PhotoDateTimePicker.tsx +++ b/web/packages/new/photos/components/PhotoDateTimePicker.tsx @@ -147,14 +147,14 @@ const parseMetadataDateFromDayjs = (d: Dayjs): ParsedMetadataDate => { const s = d.format(); let dateTime: string; - let offsetTime: string | undefined; + let offset: string | undefined; // Check to see if there is a time-zone descriptor of the form "Z" or // "±05:30" or "±0530" at the end of s. const m = s.match(/Z|[+-]\d\d:?\d\d$/); if (m?.index) { dateTime = s.substring(0, m.index); - offsetTime = s.substring(m.index); + offset = s.substring(m.index); } else { throw new Error( `Dayjs.format returned a string "${s}" without a timezone offset`, @@ -163,5 +163,5 @@ const parseMetadataDateFromDayjs = (d: Dayjs): ParsedMetadataDate => { const timestamp = d.valueOf() * 1000; - return { dateTime, offsetTime, timestamp }; + return { dateTime, offset, timestamp }; };