瀏覽代碼

corrected metadataMap seeding function

Abhinav-grd 4 年之前
父節點
當前提交
ec3763997c
共有 1 個文件被更改,包括 25 次插入33 次删除
  1. 25 33
      src/services/uploadService.ts

+ 25 - 33
src/services/uploadService.ts

@@ -220,7 +220,6 @@ class UploadService {
                 recievedFile
             );
             const metadata = Object.assign(
-                this.metadataMap.get(recievedFile.name) ?? {},
                 {
                     title: recievedFile.name,
                     creationTime:
@@ -229,7 +228,8 @@ class UploadService {
                     latitude: location?.latitude,
                     longitude: location?.latitude,
                     fileType,
-                }
+                },
+                this.metadataMap.get(recievedFile.name)
             );
             return {
                 filedata,
@@ -237,7 +237,7 @@ class UploadService {
                 metadata,
             };
         } catch (e) {
-            console.log('error reading files ' + e);
+            console.log('error reading files ', e);
             throw e;
         }
     }
@@ -280,7 +280,7 @@ class UploadService {
             };
             return result;
         } catch (e) {
-            console.log('Error encrypting files ' + e);
+            console.log('Error encrypting files ', e);
             throw e;
         }
     }
@@ -306,7 +306,7 @@ class UploadService {
 
             return file;
         } catch (e) {
-            console.log('error uploading to bucket ' + e);
+            console.log('error uploading to bucket ', e);
             throw e;
         }
     }
@@ -336,7 +336,7 @@ class UploadService {
 
             return response.data;
         } catch (e) {
-            console.log('upload Files Failed ' + e);
+            console.log('upload Files Failed ', e);
             throw e;
         }
     }
@@ -356,38 +356,30 @@ class UploadService {
                     reader.readAsText(recievedFile);
                 }
             );
-            if (!this.metadataMap.has(metadataJSON['title'])) {
-                return;
-            }
 
-            const metaDataObject = this.metadataMap.get(metadataJSON['title']);
+            const metaDataObject = {};
             metaDataObject['creationTime'] =
                 metadataJSON['photoTakenTime']['timestamp'] * 1000000;
             metaDataObject['modificationTime'] =
                 metadataJSON['modificationTime']['timestamp'] * 1000000;
 
+            var locationData = null;
             if (
-                metaDataObject['latitude'] == null ||
-                (metaDataObject['latitude'] == 0.0 &&
-                    metaDataObject['longitude'] == 0.0)
+                metadataJSON['geoData']['latitude'] != 0.0 ||
+                metadataJSON['geoData']['longitude'] != 0.0
             ) {
-                var locationData = null;
-                if (
-                    metadataJSON['geoData']['latitude'] != 0.0 ||
-                    metadataJSON['geoData']['longitude'] != 0.0
-                ) {
-                    locationData = metadataJSON['geoData'];
-                } else if (
-                    metadataJSON['geoDataExif']['latitude'] != 0.0 ||
-                    metadataJSON['geoDataExif']['longitude'] != 0.0
-                ) {
-                    locationData = metadataJSON['geoDataExif'];
-                }
-                if (locationData != null) {
-                    metaDataObject['latitude'] = locationData['latitide'];
-                    metaDataObject['longitude'] = locationData['longitude'];
-                }
+                locationData = metadataJSON['geoData'];
+            } else if (
+                metadataJSON['geoDataExif']['latitude'] != 0.0 ||
+                metadataJSON['geoDataExif']['longitude'] != 0.0
+            ) {
+                locationData = metadataJSON['geoDataExif'];
+            }
+            if (locationData != null) {
+                metaDataObject['latitude'] = locationData['latitide'];
+                metaDataObject['longitude'] = locationData['longitude'];
             }
+            this.metadataMap.set(metadataJSON['title'], metaDataObject);
         } catch (e) {
             const error = new Error(
                 `Error reading metaDataFile ${recievedFile.name}`
@@ -479,7 +471,7 @@ class UploadService {
             const thumbnail = await this.getUint8ArrayView(thumbnailBlob);
             return thumbnail;
         } catch (e) {
-            console.log('Error generating thumbnail ' + e);
+            console.log('Error generating thumbnail ', e);
             throw e;
         }
     }
@@ -502,7 +494,7 @@ class UploadService {
                 reader.readAsArrayBuffer(file);
             });
         } catch (e) {
-            console.log('error readinf file to bytearray ' + e);
+            console.log('error readinf file to bytearray ', e);
             throw e;
         }
     }
@@ -534,7 +526,7 @@ class UploadService {
             }
             return this.uploadURLFetchInProgress;
         } catch (e) {
-            console.log('fetch upload-url failed ' + e);
+            console.log('fetch upload-url failed ', e);
             throw e;
         }
     }
@@ -550,7 +542,7 @@ class UploadService {
             });
             return fileUploadURL.objectKey;
         } catch (e) {
-            console.log('putFile to dataStore failed ' + e);
+            console.log('putFile to dataStore failed ', e);
             throw e;
         }
     }