Package Updates
This commit is contained in:
@@ -13,36 +13,25 @@ var imageMagick = gm.subClass({ imageMagick: true });
|
||||
|
||||
//gm.subClass();
|
||||
dotenv.config({
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`),
|
||||
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||
});
|
||||
|
||||
export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
||||
for (const file of files) {
|
||||
const type: core.FileTypeResult | undefined = await ft.fromFile(file.path);
|
||||
const type: core.FileTypeResult | undefined = await ft.fileTypeFromFile(file.path);
|
||||
if (type?.mime === "image/heic") {
|
||||
logger.log(
|
||||
"debug",
|
||||
`Converting ${file.filename} image to JPEG from HEIC.`
|
||||
);
|
||||
logger.log("debug", `Converting ${file.filename} image to JPEG from HEIC.`);
|
||||
const convertedFileName = `${
|
||||
path.parse(path.basename(file.originalname)).name
|
||||
}-${Math.floor(Date.now() / 1000)}.jpeg`;
|
||||
try {
|
||||
await ConvertToJpeg(
|
||||
file.path,
|
||||
`${file.destination}/${convertedFileName}`
|
||||
);
|
||||
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.ensureDir(path.join(file.destination, FolderPaths.ConvertedOriginalSubDir));
|
||||
await fs.move(
|
||||
file.path,
|
||||
`${path.join(
|
||||
file.destination,
|
||||
FolderPaths.ConvertedOriginalSubDir
|
||||
)}/${file.filename}`
|
||||
`${path.join(file.destination, FolderPaths.ConvertedOriginalSubDir)}/${file.filename}`
|
||||
);
|
||||
} else {
|
||||
await fs.unlink(file.destination);
|
||||
@@ -53,12 +42,7 @@ export async function ConvertHeicFiles(files: Express.Multer.File[]) {
|
||||
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)}`
|
||||
);
|
||||
logger.log("error", `Error converting ${file.filename} image to JPEG from HEIC. ${JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user