added error handling for updateFileModifyDateInEXIF
This commit is contained in:
parent
9a3aa75d1e
commit
6a482c937e
|
@ -1,5 +1,6 @@
|
||||||
import exifr from 'exifr';
|
import exifr from 'exifr';
|
||||||
import piexif from 'piexifjs';
|
import piexif from 'piexifjs';
|
||||||
|
import { logError } from 'utils/sentry';
|
||||||
import { NULL_LOCATION, Location } from './metadataService';
|
import { NULL_LOCATION, Location } from './metadataService';
|
||||||
|
|
||||||
const EXIF_TAGS_NEEDED = [
|
const EXIF_TAGS_NEEDED = [
|
||||||
|
@ -34,21 +35,26 @@ export async function updateFileModifyDateInEXIF(
|
||||||
fileBlob: Blob,
|
fileBlob: Blob,
|
||||||
updatedDate: Date
|
updatedDate: Date
|
||||||
) {
|
) {
|
||||||
const fileURL = URL.createObjectURL(fileBlob);
|
try {
|
||||||
let imageDataURL = await convertImageToDataURL(fileURL);
|
const fileURL = URL.createObjectURL(fileBlob);
|
||||||
imageDataURL =
|
let imageDataURL = await convertImageToDataURL(fileURL);
|
||||||
'data:image/jpeg;base64' +
|
imageDataURL =
|
||||||
imageDataURL.slice(imageDataURL.indexOf(','));
|
'data:image/jpeg;base64' +
|
||||||
const exifObj = piexif.load(imageDataURL);
|
imageDataURL.slice(imageDataURL.indexOf(','));
|
||||||
if (!exifObj['0th']) {
|
const exifObj = piexif.load(imageDataURL);
|
||||||
exifObj['0th'] = {};
|
if (!exifObj['0th']) {
|
||||||
}
|
exifObj['0th'] = {};
|
||||||
exifObj['0th'][piexif.ImageIFD.DateTime] =
|
}
|
||||||
convertToExifDateFormat(updatedDate);
|
exifObj['0th'][piexif.ImageIFD.DateTime] =
|
||||||
|
convertToExifDateFormat(updatedDate);
|
||||||
|
|
||||||
const exifBytes = piexif.dump(exifObj);
|
const exifBytes = piexif.dump(exifObj);
|
||||||
const exifInsertedFile = piexif.insert(exifBytes, imageDataURL);
|
const exifInsertedFile = piexif.insert(exifBytes, imageDataURL);
|
||||||
return dataURIToBlob(exifInsertedFile);
|
return dataURIToBlob(exifInsertedFile);
|
||||||
|
} catch (e) {
|
||||||
|
logError(e, 'updateFileModifyDateInEXIF failed');
|
||||||
|
return fileBlob;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function convertImageToDataURL(url: string) {
|
export async function convertImageToDataURL(url: string) {
|
||||||
|
|
Loading…
Reference in a new issue