mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-09-22 02:19:59 +03:00
Updated probe-image-size
options to reflect underlying change
refs https://github.com/nodeca/probe-image-size/blob/master/CHANGELOG.md#changed-1 - version 6 of `probe-image-size` switched from using `request` to `needle` - this means we need to update our options to reflect the changes - we still use request in this file so I've duplicated the options for now - also adds a few extra error codes to the catches because needle reports different codes to request
This commit is contained in:
parent
8a7c7f08e9
commit
9231a4c6f6
@ -35,6 +35,14 @@ class ImageSize {
|
||||
retry: 0, // for `got`, used with image-size
|
||||
encoding: null
|
||||
};
|
||||
|
||||
this.NEEDLE_OPTIONS = {
|
||||
// we need the user-agent, otherwise some https request may fail (e.g. cloudflare)
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 Safari/537.36'
|
||||
},
|
||||
response_timeout: this.config.get('times:getImageSizeTimeoutInMS') || 10000
|
||||
};
|
||||
}
|
||||
|
||||
// processes the Buffer result of an image file using image-size
|
||||
@ -71,7 +79,7 @@ class ImageSize {
|
||||
}));
|
||||
}
|
||||
|
||||
return probeSizeOf(imageUrl, this.REQUEST_OPTIONS);
|
||||
return probeSizeOf(imageUrl, this.NEEDLE_OPTIONS);
|
||||
}
|
||||
|
||||
// download full image then use image-size to get it's dimensions
|
||||
@ -162,14 +170,14 @@ class ImageSize {
|
||||
statusCode: err.statusCode,
|
||||
context: err.url || imagePath
|
||||
}));
|
||||
}).catch({code: 'ETIMEDOUT'}, {code: 'ESOCKETTIMEDOUT'}, {statusCode: 408}, (err) => {
|
||||
}).catch({code: 'ETIMEDOUT'}, {code: 'ESOCKETTIMEDOUT'}, {code: 'ECONNRESET'}, {statusCode: 408}, (err) => {
|
||||
return Promise.reject(new errors.InternalServerError({
|
||||
message: 'Request timed out.',
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
statusCode: err.statusCode,
|
||||
context: err.url || imagePath
|
||||
}));
|
||||
}).catch({code: 'ENOENT'}, {statusCode: 404}, (err) => {
|
||||
}).catch({code: 'ENOENT'}, {code: 'ENOTFOUND'}, {statusCode: 404}, (err) => {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: 'Image not found.',
|
||||
code: 'IMAGE_SIZE_URL',
|
||||
|
Loading…
Reference in New Issue
Block a user