1
0
Fork 0
mirror of synced 2024-09-27 23:01:51 +12:00
budibase/packages/server/src/api/controllers/static/fileProcessor.js

24 lines
526 B
JavaScript
Raw Normal View History

2020-09-17 23:45:28 +12:00
const fs = require("fs");
const sharp = require("sharp");
const fsPromises = fs.promises;
const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
}
function processImage({ path, outputPath }) {
return sharp(path)
.resize(300)
.toFile(outputPath)
}
function process(file) {
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
return processImage(file);
}
// No processing required
return fsPromises.copyFile(file.path, file.outputPath)
}
exports.process = process