Manav Rathi 1 năm trước cách đây
mục cha
commit
c8542211b4

+ 15 - 6
web/apps/photos/src/services/upload/uploadService.ts

@@ -656,13 +656,22 @@ async function tryExtractImageMetadata(
     fileTypeInfo: FileTypeInfo,
     fileTypeInfo: FileTypeInfo,
     lastModifiedMs: number,
     lastModifiedMs: number,
 ): Promise<ParsedExtractedMetadata> {
 ): Promise<ParsedExtractedMetadata> {
+    let file: File;
+    if (fileOrPath instanceof File) {
+        file = fileOrPath;
+    } else {
+        const path = fileOrPath;
+        // The library we use for extracting EXIF from images, exifr, doesn't
+        // support streams. But unlike videos, for images it is reasonable to
+        // read the entire stream into memory here.
+        const { response } = await readStream(ensureElectron(), path);
+        file = new File([await response.arrayBuffer()], basename(path), {
+            lastModified: lastModifiedMs,
+        });
+    }
+
     try {
     try {
-        if (!(fileOrPath instanceof File)) {
-            fileOrPath = new File([await fileOrPath.blob()], fileOrPath.name, {
-                lastModified: lastModifiedMs,
-            });
-        }
-        return await parseImageMetadata(fileOrPath, fileTypeInfo);
+        return await parseImageMetadata(file, fileTypeInfo);
     } catch (e) {
     } catch (e) {
         log.error(`Failed to extract image metadata for ${fileOrPath}`, e);
         log.error(`Failed to extract image metadata for ${fileOrPath}`, e);
         return undefined;
         return undefined;