working uploads

This commit is contained in:
James
2020-05-06 13:36:54 -04:00
parent c5d96a1424
commit 60e9e148b0
9 changed files with 6 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@@ -18,7 +18,7 @@ function getOutputImage(sourceImage, size) {
};
}
module.exports = async function resizeAndSave(config, uploadConfig, savedFilename) {
module.exports = async function resizeAndSave(config, savedFilename) {
/**
* Resize images according to image desired width and height and return sizes
* @param config Object
@@ -27,11 +27,13 @@ module.exports = async function resizeAndSave(config, uploadConfig, savedFilenam
* @returns String[]
*/
const sourceImage = `${config.staticDir}/${savedFilename}`;
const { imageSizes, staticDir } = config.upload;
const sourceImage = `${staticDir}/${savedFilename}`;
let sizes;
try {
const dimensions = await sizeOf(sourceImage);
sizes = uploadConfig.imageSizes
sizes = imageSizes
.filter(desiredSize => desiredSize.width < dimensions.width)
.map(async (desiredSize) => {
const outputImage = getOutputImage(savedFilename, desiredSize);
@@ -41,7 +43,7 @@ module.exports = async function resizeAndSave(config, uploadConfig, savedFilenam
// would it make sense for this to be set by the uploader?
position: desiredSize.crop || 'centre',
})
.toFile(`${config.staticDir}/${imageNameWithDimensions}`);
.toFile(`${staticDir}/${imageNameWithDimensions}`);
return { ...desiredSize, filename: imageNameWithDimensions };
});
const savedSizes = await Promise.all(sizes);