Manav Rathi 1 jaar geleden
bovenliggende
commit
c2c5267e9b
2 gewijzigde bestanden met toevoegingen van 20 en 46 verwijderingen
  1. 19 43
      web/apps/photos/src/services/upload/uploadManager.ts
  2. 1 3
      web/apps/photos/src/utils/upload/index.ts

+ 19 - 43
web/apps/photos/src/services/upload/uploadManager.ts

@@ -364,15 +364,14 @@ class UploadManager {
         uploaderName?: string,
         uploaderName?: string,
     ) {
     ) {
         try {
         try {
-            if (this.uploadInProgress) {
-                throw Error("can't run multiple uploads at once");
-            }
+            if (this.uploadInProgress)
+                throw new Error("Cannot run multiple uploads at once");
+
+            log.info(`Uploading ${filesWithCollectionToUploadIn.length} files`);
             this.uploadInProgress = true;
             this.uploadInProgress = true;
             await this.updateExistingFilesAndCollections(collections);
             await this.updateExistingFilesAndCollections(collections);
             this.uploaderName = uploaderName;
             this.uploaderName = uploaderName;
-            log.info(
-                `received ${filesWithCollectionToUploadIn.length} files to upload`,
-            );
+
             this.uiService.setFilenames(
             this.uiService.setFilenames(
                 new Map<number, string>(
                 new Map<number, string>(
                     filesWithCollectionToUploadIn.map((mediaFile) => [
                     filesWithCollectionToUploadIn.map((mediaFile) => [
@@ -381,10 +380,10 @@ class UploadManager {
                     ]),
                     ]),
                 ),
                 ),
             );
             );
+
             const { metadataJSONFiles, mediaFiles } =
             const { metadataJSONFiles, mediaFiles } =
                 segregateMetadataAndMediaFiles(filesWithCollectionToUploadIn);
                 segregateMetadataAndMediaFiles(filesWithCollectionToUploadIn);
-            log.info(`has ${metadataJSONFiles.length} metadata json files`);
-            log.info(`has ${mediaFiles.length} media files`);
+
             if (metadataJSONFiles.length) {
             if (metadataJSONFiles.length) {
                 this.uiService.setUploadStage(
                 this.uiService.setUploadStage(
                     UPLOAD_STAGES.READING_GOOGLE_METADATA_FILES,
                     UPLOAD_STAGES.READING_GOOGLE_METADATA_FILES,
@@ -458,44 +457,21 @@ class UploadManager {
     };
     };
 
 
     private async parseMetadataJSONFiles(metadataFiles: FileWithCollection2[]) {
     private async parseMetadataJSONFiles(metadataFiles: FileWithCollection2[]) {
-        try {
-            log.info(`parseMetadataJSONFiles function executed `);
+        this.uiService.reset(metadataFiles.length);
 
 
-            this.uiService.reset(metadataFiles.length);
+        for (const { file, collectionID } of metadataFiles) {
+            this.abortIfCancelled();
 
 
-            for (const { file, collectionID } of metadataFiles) {
-                this.abortIfCancelled();
-                const name = getFileName(file);
-                try {
-                    log.info(`parsing metadata json file ${name}`);
-
-                    const metadataJSON =
-                        await tryParseTakeoutMetadataJSON(file);
-                    if (metadataJSON) {
-                        this.parsedMetadataJSONMap.set(
-                            getMetadataJSONMapKeyForJSON(collectionID, name),
-                            metadataJSON && { ...metadataJSON },
-                        );
-                        this.uiService.increaseFileUploaded();
-                    }
-                    log.info(`successfully parsed metadata json file ${name}`);
-                } catch (e) {
-                    if (e.message === CustomError.UPLOAD_CANCELLED) {
-                        throw e;
-                    } else {
-                        // and don't break for subsequent files just log and move on
-                        log.error("parsing failed for a file", e);
-                        log.info(
-                            `failed to parse metadata json file ${name} error: ${e.message}`,
-                        );
-                    }
-                }
-            }
-        } catch (e) {
-            if (e.message !== CustomError.UPLOAD_CANCELLED) {
-                log.error("error seeding MetadataMap", e);
+            const fileName = getFileName(file);
+            log.info(`Parsing metadata JSON ${fileName}`);
+            const metadataJSON = await tryParseTakeoutMetadataJSON(file);
+            if (metadataJSON) {
+                this.parsedMetadataJSONMap.set(
+                    getMetadataJSONMapKeyForJSON(collectionID, fileName),
+                    metadataJSON,
+                );
+                this.uiService.increaseFileUploaded();
             }
             }
-            throw e;
         }
         }
     }
     }
 
 

+ 1 - 3
web/apps/photos/src/utils/upload/index.ts

@@ -6,8 +6,6 @@ import isElectron from "is-electron";
 import { exportMetadataDirectoryName } from "services/export";
 import { exportMetadataDirectoryName } from "services/export";
 import { FileWithCollection, type FileWithCollection2 } from "types/upload";
 import { FileWithCollection, type FileWithCollection2 } from "types/upload";
 
 
-const TYPE_JSON = "json";
-
 export const hasFileHash = (file: Metadata) =>
 export const hasFileHash = (file: Metadata) =>
     file.hash || (file.imageHash && file.videoHash);
     file.hash || (file.imageHash && file.videoHash);
 
 
@@ -18,7 +16,7 @@ export function segregateMetadataAndMediaFiles(
     const mediaFiles: FileWithCollection[] = [];
     const mediaFiles: FileWithCollection[] = [];
     filesWithCollectionToUpload.forEach((fileWithCollection) => {
     filesWithCollectionToUpload.forEach((fileWithCollection) => {
         const file = fileWithCollection.file;
         const file = fileWithCollection.file;
-        if (file.name.toLowerCase().endsWith(TYPE_JSON)) {
+        if (file.name.toLowerCase().endsWith("json")) {
             metadataJSONFiles.push(fileWithCollection);
             metadataJSONFiles.push(fileWithCollection);
         } else {
         } else {
             mediaFiles.push(fileWithCollection);
             mediaFiles.push(fileWithCollection);