From 88f643192cf6bf553498453d7f1c7f657de2d31a Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 10 Nov 2021 14:53:23 +0530 Subject: [PATCH] fix getExifData breaking for some files --- src/services/updateCreationTimeWithExif.ts | 6 ++++-- src/utils/file/index.ts | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/services/updateCreationTimeWithExif.ts b/src/services/updateCreationTimeWithExif.ts index ac9199b26..482718f72 100644 --- a/src/services/updateCreationTimeWithExif.ts +++ b/src/services/updateCreationTimeWithExif.ts @@ -1,6 +1,7 @@ import { SetProgressTracker } from 'components/FixLargeThumbnail'; import { changeFileCreationTime, + getFileFromURL, updateExistingFilePubMetadata, } from 'utils/file'; import { logError } from 'utils/sentry'; @@ -8,7 +9,7 @@ import localForage from 'utils/storage/localForage'; import downloadManager from './downloadManager'; import { getLocalFiles, File, updatePublicMagicMetadata } from './fileService'; import { getLocalTrash, getTrashedFiles } from './trashService'; -import { getExifDataFromURL } from './upload/exifService'; +import { getExifData } from './upload/exifService'; const CREATION_TIME_UPDATED_FILES_TABLE = 'creation-time-updated-file-table'; @@ -52,7 +53,8 @@ export async function updateCreationTimeWithExif( for (const [index, file] of filesToBeUpdated.entries()) { try { const fileURL = await downloadManager.getFile(file); - const exifData = await getExifDataFromURL(fileURL); + const fileObject = await getFileFromURL(fileURL); + const exifData = await getExifData(fileObject); if ( exifData?.creationTime && exifData?.creationTime !== file.metadata.creationTime diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index 5ea88f252..258984c94 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -438,3 +438,9 @@ export function updateExistingFilePubMetadata( existingFile.pubMagicMetadata = updatedFile.pubMagicMetadata; existingFile.metadata = mergeMetadata([existingFile])[0].metadata; } + +export async function getFileFromURL(fileURL: string) { + const fileBlob = await (await fetch(fileURL)).blob(); + const fileFile = new globalThis.File([fileBlob], 'temp'); + return fileFile; +}