1
0
Fork 0
mirror of synced 2024-06-30 03:50:37 +12:00
budibase/packages/server/src/utilities/fileProcessor.js
2020-10-21 13:00:23 +01:00

27 lines
577 B
JavaScript

const fs = require("fs")
const jimp = require("jimp")
const fsPromises = fs.promises
const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
}
function processImage(file) {
return jimp.read(file.path).then(img => {
return img.resize(300, jimp.AUTO).write(file.outputPath)
})
}
async function process(file) {
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
await processImage(file)
return file
}
// No processing required
await fsPromises.copyFile(file.path, file.outputPath)
return file
}
exports.process = process