Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[desktop] Write timestamps as string for GT consistency; Read either

Manav Rathie31d13285572
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 03f64d9c1c..527023a5cf 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -1401,11 +1401,11 @@ const getGoogleLikeMetadataFile = (
const result: Record<string, unknown> = {
title: fileExportName,
creationTime: {
- timestamp: creationTime,
+ timestamp: `${creationTime}`,
formatted: dateTimeFormatter.format(creationTime * 1000),
},
modificationTime: {
- timestamp: modificationTime,
+ timestamp: `${modificationTime}`,
formatted: dateTimeFormatter.format(modificationTime * 1000),
},
};
diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.ts
index 27d81cbea0..5ed59bae7d 100644
--- a/web/apps/photos/src/services/upload/takeout.ts
+++ b/web/apps/photos/src/services/upload/takeout.ts
@@ -7,7 +7,6 @@ import log from "ente-base/log";
import { type Location } from "ente-base/types";
import type { UploadItem } from "ente-gallery/services/upload";
import { readStream } from "ente-gallery/utils/native-stream";
-import { maybeParseInt } from "ente-utils/parse";
/**
* The data we read from the JSON metadata sidecar files.
@@ -190,14 +189,22 @@ const parseMetadataJSONText = (text: string) => {
* seems to be in UTC and doesn't have the time zone either.
*/
const parseGTTimestamp = (o: unknown): number | undefined => {
- if (
- o &&
- typeof o == "object" &&
- "timestamp" in o &&
- typeof o.timestamp == "string"
- ) {
- const timestamp = maybeParseInt(o.timestamp);
- if (timestamp) return timestamp * 1e6;
+ if (o && typeof o == "object" && "timestamp" in o) {
+ const ot = o.timestamp;
+ let timestamp: number | undefined;
+ if (typeof ot == "string") {
+ timestamp = parseInt(ot, 10);
+ } else if (typeof ot == "number") {
+ // Ente desktop 1.7.11 and earlier used to write out a number, which
+ // is the correct datatype, but that makes it inconsistent with the
+ // numbers-as-string that Google takeout writes.
+ //
+ // So now we write out strings, and read either.
+ timestamp = Math.floor(ot);
+ }
+ if (timestamp && !Number.isNaN(timestamp)) {
+ return timestamp * 1e6;
+ }
}
return undefined;
};
diff --git a/web/packages/utils/parse.ts b/web/packages/utils/parse.ts
deleted file mode 100644
index 31300a5c4d..0000000000
--- a/web/packages/utils/parse.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * A wrapper over parseInt that deals with its sheNaNigans.
- *
- * This function takes as an input a string nominally (though the implementation
- * is meant to work for arbitrary JavaScript values). It parses it into a base
- * 10 integer. If the result is NaN, it returns undefined, otherwise it returns
- * the parsed integer.
- *
- * From MDN:
- *
- * > To be sure that you are working with numbers, coerce the value to a number
- * > and use Number.isNaN() to test the result()
- * >
- * > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
- */
-export const maybeParseInt = (s: string): number | undefined => {
- const n = parseInt(s, 10);
- return Number.isNaN(n) ? undefined : n;
-};