Use newer fields

This commit is contained in:
Manav Rathi
2024-08-06 20:05:27 +05:30
parent af4064b97a
commit a6cc6f24d0
3 changed files with 36 additions and 37 deletions

View File

@@ -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]);

View File

@@ -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);

View File

@@ -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 };
};