Files
bodyshop-media-server/util/heicQueueProcessor.ts
2024-09-06 16:16:47 -07:00

46 lines
1.9 KiB
TypeScript

// import { SandboxedJob } from "bullmq";
// import { logger } from "../server.js";
// import dotenv from "dotenv";
// import fs from "fs-extra";
// import path from "path";
// import { FolderPaths } from "./serverInit.js";
// import gm from "gm";
// const imageMagick = gm.subClass({ imageMagick: true });
// export default async function (job: SandboxedJob) {
// // Do something with job
// console.log("*** We're in the processing Queue")
// const { file, convertedFileName } = job.data;
// try {
// logger.log("debug", `Attempting to convert ${file.filename} image to JPEG from HEIC.`);
// await ConvertToJpeg(file.path, `${file.destination}/${convertedFileName}`);
// logger.log("debug", `Converted ${file.filename} image to JPEG from HEIC.`);
// await handleOriginalFile(file, 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)}`);
// }
// }
// async function handleOriginalFile(file: Express.Multer.File, convertedFileName: string) {
// 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.path);
// }
// }
// async function ConvertToJpeg(file: string, newPath: string) {
// const fileOnDisk: Buffer = await fs.readFile(file);
// return new Promise<string>((resolve, reject) => {
// imageMagick(fileOnDisk)
// .setFormat("jpg")
// .write(newPath, (error) => {
// if (error) reject(error.message);
// resolve(newPath);
// });
// });
// }