Skip to content
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

Add callback call in the resizer function. #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sosfos
Copy link

@sosfos sosfos commented Jan 17, 2019

Thank the team first as this library is useful in one of my project.

But when using it, I encountered one problem, when using in expressjs, which is when the user upload a fake picture (like after changing the ext of another non-pic file) and the server try to make a thumbnail of it, there will be an exception (unkown MIME type) in the jimp which will cause the resizer function to throw out the exception. But in expressjs, I cannot catch the exception which will cause the process terminate.

I am not sure whether I could find a better solution in expressjs side, but for now I just folk this project and add the callback in resizer function so that I can process the exception in the expressjs.

It will be appreciated if someone can provide a better solution without changing this lib!

@@ -41,6 +41,7 @@ extensions = ['.jpg', '.jpeg', '.png'];
resizer = (options, callback) =>
jimp.read(options.srcPath, (err, file) => {
if (err) {
if(done) return done(file, err);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're returning early from the function, we don't need to throw the error.

@honza
Copy link
Owner

honza commented Jan 17, 2019

Also, the reason why Travis is failing is because of formatting. You can run npm run prettier to fix it.

@honza
Copy link
Owner

honza commented Jan 17, 2019

I just pushed some fixes that should take care of this. Would you mind testing your code with latest master?

@sosfos
Copy link
Author

sosfos commented Jan 29, 2019

hi honza, I just checked your fix, it works in my project. It will not make the app crash after trying to creating thumbnail for a fake image, but the error was just hidden underground as you are calling the internal callback but not the customized callback.

Anyway, it's good enough for my project so far. Thanks for your fix.

By the way, the CI shows there are conflicts and I just try to fixed, not sure how to restart the ci so please help to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants