-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🙈 Used got
to handle requests for image-size
#8892
Conversation
2e5e2bf
to
6934a22
Compare
@@ -42,7 +42,7 @@ describe('{{ghost_head}} helper', function () { | |||
return localSettingsCache[key]; | |||
}); | |||
|
|||
configUtils.set('url', 'http://localhost:82832/'); | |||
configUtils.set('url', 'http://localhost:65530/'); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
got
to handle requests for image-sizegot
to handle requests for image-size
@ErisDS: I assume this change needs a lot of testing, as our image size util is the cause for many dispatcher issues. If you feel like we're missing some more tests, please let me know. |
f097088
to
3cbdb1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking so much better! I think there is a last pass through to do to tidy up one or two more things :)
@@ -34,7 +31,7 @@ var sizeOf = require('image-size'), | |||
module.exports.getImageSizeFromUrl = function getImageSizeFromUrl(imagePath) { | |||
return new Promise(function imageSizeRequest(resolve, reject) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
requestOptions | ||
).then(function (response) { | ||
try { | ||
dimensions = sizeOf(response.body); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
code: 'IMAGE_SIZE', | ||
statusCode: err.statusCode, | ||
context: err.url | ||
})); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
message: 'Image not found.', | ||
code: 'IMAGE_SIZE', | ||
statusCode: err.statusCode, | ||
context: err.url |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
3cbdb1d
to
5958a4f
Compare
5958a4f
to
d4fa95d
Compare
I've tested several cases from the past and looks like |
d4fa95d
to
f52279e
Compare
refs TryGhost#8589 refs TryGhost#8868 Swap `request` with `got` in `getImageSizeFromUrl` util.
f52279e
to
87edb67
Compare
closes #8589, refs #8868 This PR ports most of the changes of #8892 and #8986 to improve the image-size util. - Swapped `request` with `got` in `getImageSizeFromUrl` fn. - wrapped `got` request library in its own `request.js` util that returns bluebird promises and validates URL before starting a request - Used catch predicates instead of conditionals in `getImageSizeFromUrl` - Returned `NotFoundError` if applicable as the caller function `cachedImageSizeFromUrl` is differentiating those between this error and others. - The logic that checked for an existing protocol (e. g. gravatar URLs) was overly complicated. Refactored it to be more simple. - We're always resolving the result in `getCachedImageSizeFromUrl`, so there's no need to return the values with a `Promise.resolve()`. The caller fn uses waits for the Promises to be fulfilled. - added and improved tests
refs #8589
refs #8868
Swap
request
withgot
ingetImageSizeFromUrl
fn.TODOs: