π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle NaNs
Manav Rathidd53cf4e58d9
diff --git a/web/apps/photos/src/services/upload/takeout.ts b/web/apps/photos/src/services/upload/takeout.tsindex de0f475b65..02bff3cd25 100644--- a/web/apps/photos/src/services/upload/takeout.ts+++ b/web/apps/photos/src/services/upload/takeout.ts@@ -6,6 +6,7 @@ import log from "@/base/log";import { type Location } from "@/base/types";import type { UploadItem } from "@/new/photos/services/upload/types";import { readStream } from "@/new/photos/utils/native-stream";+import { maybeParseInt } from "@/utils/parse";/*** The data we read from the JSON metadata sidecar files.@@ -144,8 +145,8 @@ const parseGTTimestamp = (o: unknown): number | undefined => {"timestamp" in o &&typeof o.timestamp == "string") {- const { timestamp } = o;- if (timestamp) return parseInt(timestamp, 10) * 1e6;+ const timestamp = maybeParseInt(o.timestamp);+ if (timestamp) return timestamp * 1e6;}return undefined;};diff --git a/web/packages/utils/parse.ts b/web/packages/utils/parse.tsnew file mode 100644index 0000000000..5e0f3c0739--- /dev/null+++ b/web/packages/utils/parse.ts@@ -0,0 +1,19 @@+/**+ * 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) => {+ const n = parseInt(s, 10);+ return Number.isNaN(n) ? undefined : n;+};