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