From 6a482c937eb0503ce955d08240534fdf38b57fd4 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 11 Nov 2021 13:11:16 +0530 Subject: [PATCH] added error handling for updateFileModifyDateInEXIF --- src/services/upload/exifService.ts | 34 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/services/upload/exifService.ts b/src/services/upload/exifService.ts index ec30f7560..d14538e7a 100644 --- a/src/services/upload/exifService.ts +++ b/src/services/upload/exifService.ts @@ -1,5 +1,6 @@ import exifr from 'exifr'; import piexif from 'piexifjs'; +import { logError } from 'utils/sentry'; import { NULL_LOCATION, Location } from './metadataService'; const EXIF_TAGS_NEEDED = [ @@ -34,21 +35,26 @@ export async function updateFileModifyDateInEXIF( fileBlob: Blob, updatedDate: Date ) { - const fileURL = URL.createObjectURL(fileBlob); - let imageDataURL = await convertImageToDataURL(fileURL); - imageDataURL = - 'data:image/jpeg;base64' + - imageDataURL.slice(imageDataURL.indexOf(',')); - const exifObj = piexif.load(imageDataURL); - if (!exifObj['0th']) { - exifObj['0th'] = {}; - } - exifObj['0th'][piexif.ImageIFD.DateTime] = - convertToExifDateFormat(updatedDate); + try { + const fileURL = URL.createObjectURL(fileBlob); + let imageDataURL = await convertImageToDataURL(fileURL); + imageDataURL = + 'data:image/jpeg;base64' + + imageDataURL.slice(imageDataURL.indexOf(',')); + const exifObj = piexif.load(imageDataURL); + if (!exifObj['0th']) { + exifObj['0th'] = {}; + } + exifObj['0th'][piexif.ImageIFD.DateTime] = + convertToExifDateFormat(updatedDate); - const exifBytes = piexif.dump(exifObj); - const exifInsertedFile = piexif.insert(exifBytes, imageDataURL); - return dataURIToBlob(exifInsertedFile); + const exifBytes = piexif.dump(exifObj); + const exifInsertedFile = piexif.insert(exifBytes, imageDataURL); + return dataURIToBlob(exifInsertedFile); + } catch (e) { + logError(e, 'updateFileModifyDateInEXIF failed'); + return fileBlob; + } } export async function convertImageToDataURL(url: string) {