Manav Rathi 1 vuosi sitten
vanhempi
commit
9103dadc6f

+ 9 - 8
web/apps/photos/src/services/upload/takeout.ts

@@ -74,9 +74,10 @@ function getFileOriginalName(fileName: string) {
     return originalName;
 }
 
-export async function parseMetadataJSON(
+/** Try to parse the contents of a metadata JSON file in a Google Takeout. */
+export const tryParseTakeoutMetadataJSON = async (
     receivedFile: File | ElectronFile | string,
-) {
+): Promise<ParsedMetadataJSON | undefined> => {
     try {
         let text: string;
         if (typeof receivedFile == "string") {
@@ -93,8 +94,8 @@ export async function parseMetadataJSON(
 
         return parseMetadataJSONText(text);
     } catch (e) {
-        log.error("parseMetadataJSON failed", e);
-        // ignore
+        log.error("Failed to parse takeout metadata JSON", e);
+        return undefined;
     }
 }
 
@@ -105,14 +106,14 @@ const NULL_PARSED_METADATA_JSON: ParsedMetadataJSON = {
     ...NULL_LOCATION,
 };
 
-export async function parseMetadataJSONText(text: string) {
+const parseMetadataJSONText = (text: string) => {
     const metadataJSON: object = JSON.parse(text);
-
-    const parsedMetadataJSON: ParsedMetadataJSON = NULL_PARSED_METADATA_JSON;
     if (!metadataJSON) {
-        return;
+        return undefined;
     }
 
+    const parsedMetadataJSON: ParsedMetadataJSON = NULL_PARSED_METADATA_JSON;
+
     if (
         metadataJSON["photoTakenTime"] &&
         metadataJSON["photoTakenTime"]["timestamp"]

+ 8 - 7
web/apps/photos/src/services/upload/uploadManager.ts

@@ -43,12 +43,12 @@ import {
     segregateMetadataAndMediaFiles2,
 } from "utils/upload";
 import { getLocalFiles } from "../fileService";
+import { clusterLivePhotoFiles } from "./metadataService";
 import {
-    clusterLivePhotoFiles,
     getMetadataJSONMapKeyForJSON,
-    parseMetadataJSON,
-} from "./metadataService";
-import type { ParsedMetadataJSON } from "./takeout";
+    tryParseTakeoutMetadataJSON,
+    type ParsedMetadataJSON,
+} from "./takeout";
 import uploadCancelService from "./uploadCancelService";
 import UploadService, {
     assetName,
@@ -523,11 +523,12 @@ class UploadManager {
 
                     log.info(`parsing metadata json file ${name}`);
 
-                    const parsedMetadataJSON = await parseMetadataJSON(file);
-                    if (parsedMetadataJSON) {
+                    const metadataJSON =
+                        await tryParseTakeoutMetadataJSON(file);
+                    if (metadataJSON) {
                         this.parsedMetadataJSONMap.set(
                             getMetadataJSONMapKeyForJSON(collectionID, name),
-                            parsedMetadataJSON && { ...parsedMetadataJSON },
+                            metadataJSON && { ...metadataJSON },
                         );
                         this.uiService.increaseFileUploaded();
                     }