mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Fixed error when requesting resize of a blank image
closes https://github.com/TryGhost/Team/issues/819 - adds guard for an empty buffer when reading file from storage for resizing, if a blank image is loaded then redirect to the original file
This commit is contained in:
parent
d36ee59dbe
commit
54b537deba
1 changed files with 8 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const {GhostError} = require('@tryghost/errors');
|
||||||
const imageTransform = require('@tryghost/image-transform');
|
const imageTransform = require('@tryghost/image-transform');
|
||||||
const storage = require('../../../adapters/storage');
|
const storage = require('../../../adapters/storage');
|
||||||
const activeTheme = require('../../../../frontend/services/themes/active');
|
const activeTheme = require('../../../../frontend/services/themes/active');
|
||||||
|
@ -100,6 +101,12 @@ module.exports = function (req, res, next) {
|
||||||
return storageInstance.read({path: storagePath});
|
return storageInstance.read({path: storagePath});
|
||||||
})
|
})
|
||||||
.then((originalImageBuffer) => {
|
.then((originalImageBuffer) => {
|
||||||
|
if (originalImageBuffer.length <= 0) {
|
||||||
|
throw new GhostError({
|
||||||
|
errorType: 'NoContentError',
|
||||||
|
statusCode: 204
|
||||||
|
});
|
||||||
|
}
|
||||||
return imageTransform.resizeFromBuffer(originalImageBuffer, imageDimensionConfig);
|
return imageTransform.resizeFromBuffer(originalImageBuffer, imageDimensionConfig);
|
||||||
})
|
})
|
||||||
.then((resizedImageBuffer) => {
|
.then((resizedImageBuffer) => {
|
||||||
|
@ -108,7 +115,7 @@ module.exports = function (req, res, next) {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
next();
|
next();
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
if (err.code === 'SHARP_INSTALLATION') {
|
if (err.code === 'SHARP_INSTALLATION' || err.errorType === 'NoContentError') {
|
||||||
return redirectToOriginal();
|
return redirectToOriginal();
|
||||||
}
|
}
|
||||||
next(err);
|
next(err);
|
||||||
|
|
Loading…
Reference in a new issue