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 = `${
|
const convertedFileName = `${
|
||||||
path.parse(path.basename(file.originalname)).name
|
path.parse(path.basename(file.originalname)).name
|
||||||
}-${Math.floor(Date.now() / 1000)}.jpeg`;
|
}-${Math.floor(Date.now() / 1000)}.jpeg`;
|
||||||
|
try {
|
||||||
await ConvertToJpeg(
|
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(
|
|
||||||
file.path,
|
file.path,
|
||||||
`${path.join(
|
`${file.destination}/${convertedFileName}`
|
||||||
file.destination,
|
|
||||||
FolderPaths.ConvertedOriginalSubDir
|
|
||||||
)}/${file.filename}`
|
|
||||||
);
|
);
|
||||||
} else {
|
//Move the HEIC.
|
||||||
await fs.unlink(file.destination);
|
if (process.env.KEEP_CONVERTED_ORIGINALS) {
|
||||||
}
|
await fs.ensureDir(
|
||||||
//Update the multer file entry.
|
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.filename = convertedFileName;
|
||||||
file.mimetype = "image/jpeg";
|
file.mimetype = "image/jpeg";
|
||||||
file.path = `${file.destination}/${convertedFileName}`;
|
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