Add try catch to heic conversion.
This commit is contained in:
@@ -27,31 +27,39 @@ export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
||||
const convertedFileName = `${
|
||||
path.parse(path.basename(file.originalname)).name
|
||||
}-${Math.floor(Date.now() / 1000)}.jpeg`;
|
||||
|
||||
await ConvertToJpeg(
|
||||
file.path,
|
||||
`${file.destination}/${convertedFileName}`
|
||||
);
|
||||
//Move the HEIC.
|
||||
if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||
await fs.ensureDir(
|
||||
path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)
|
||||
);
|
||||
await fs.move(
|
||||
try {
|
||||
await ConvertToJpeg(
|
||||
file.path,
|
||||
`${path.join(
|
||||
file.destination,
|
||||
FolderPaths.ConvertedOriginalSubDir
|
||||
)}/${file.filename}`
|
||||
`${file.destination}/${convertedFileName}`
|
||||
);
|
||||
} else {
|
||||
await fs.unlink(file.destination);
|
||||
}
|
||||
//Update the multer file entry.
|
||||
//Move the HEIC.
|
||||
if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||
await fs.ensureDir(
|
||||
path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)
|
||||
);
|
||||
await fs.move(
|
||||
file.path,
|
||||
`${path.join(
|
||||
file.destination,
|
||||
FolderPaths.ConvertedOriginalSubDir
|
||||
)}/${file.filename}`
|
||||
);
|
||||
} else {
|
||||
await fs.unlink(file.destination);
|
||||
}
|
||||
//Update the multer file entry.
|
||||
|
||||
file.filename = convertedFileName;
|
||||
file.mimetype = "image/jpeg";
|
||||
file.path = `${file.destination}/${convertedFileName}`;
|
||||
file.filename = convertedFileName;
|
||||
file.mimetype = "image/jpeg";
|
||||
file.path = `${file.destination}/${convertedFileName}`;
|
||||
} catch (error) {
|
||||
logger.log(
|
||||
"error",
|
||||
`Error converting ${
|
||||
file.filename
|
||||
} image to JPEG from HEIC. ${JSON.stringify(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user