Skip to content

Help avoid unnecessary hits to process & invalid requests#5

Merged
mminkoff merged 5 commits intomasterfrom
unknown repository
Feb 15, 2018
Merged

Help avoid unnecessary hits to process & invalid requests#5
mminkoff merged 5 commits intomasterfrom
unknown repository

Conversation

@sdhull
Copy link
Contributor

@sdhull sdhull commented Feb 7, 2018

  1. Unnecessary hits to process are any hits that have no resize options. When the helper is used without resize options, it should simply return either the URL passed to it (if passed a URL), or a URL to https://cdn.filestackcontent.com/token
  2. Prevent invalid requests by ensuring either width or height is present in the resize options. Otherwise return simple image url.
  3. Support custom CDNs for transform & display of images from filestack. This can make your quota last longer.

1. Unnecessary hits to process are any hits that have no resize options.  When the helper is used without resize options, it should simply return either the URL passed to it (if passed a URL), or a URL to https://cdn.filestackcontent.com/token
2. Prevent invalid requests by ensuring either `width` or `height` is present in the resize options. Otherwise return simple image url.
This commit adds support for `ENV.filestackProcessCDN` which should proxy to https://process.filestackapi.com and `ENV.filestackContentCDN` which should proxy to https://cdn.filestackcontent.com.

Setting up these CDNs (on AWS Cloudfront, for instance) will save duplicate hits to transform & display, making your filestack quotas last longer.
@sdhull
Copy link
Contributor Author

sdhull commented Feb 8, 2018

Should probably update the readme to mention the CDN configuration option...

Copy link
Owner

@mminkoff mminkoff left a comment

Choose a reason for hiding this comment

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

I think this is a terrific change! However, unless I'm missing something, there are many other processing tasks besides resizing - they don't all require a height or width, do they?

Also, yes, some documentation for this would be terrific - @scudco? @nolman?

imageUrl = `https://cdn.filestackcontent.com/${token}`;
urlRoot = 'https://process.filestackapi.com';
}
Object.keys(hash).forEach((key) => {
Copy link
Owner

Choose a reason for hiding this comment

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

shouldn't this forEach move to within the if at current line 36? No need to process if we don't have enough options, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good point! Updating incoming

@sdhull
Copy link
Contributor Author

sdhull commented Feb 10, 2018

@mminkoff there are indeed other processing tasks besides resizing, it's just that this helper has resize= hard-coded, and while the docs aren't exactly super obvious about it, I did test the endpoint with only crop and only align and both produce 400 error responses, with an error message that width or height are required. Which makes sense if you think about it -- clearly "resize" doesn't make much sense without width or height specified.

I'll add something to the readme presently...

Avoid looping through the hash if it doesn't have the required options (width or height).
@sdhull
Copy link
Contributor Author

sdhull commented Feb 10, 2018

To your other point -- the other transformations filestack supports -- it would be awesome to add support for them to the helper (or maybe add other helpers?). I think that should be done in a separate PR, maybe after some discussion about how to support them.

If we support them all in this helper, the helper is likely to be ridiculously large. Maybe we add options parsing per transformation type in utilities, or maybe we make each one its own helper (with some shared utilities). I'm not really sure what the best approach is. But I know it would be sweet to add support for image-to-ascii transformations 😀

@mminkoff
Copy link
Owner

@sdhull sorry for the delay. Great updates - thanks!

As for supporting all options, it's only an issue because we're checking for what's there. I'd be more inclined to leave that up to the developer so they can put whatever options they want. Maybe we should at least rename the helper to something specific to resize, though I don't want to introduce breaking changes.

I'll go with this for now and would welcome any support in broadening what this can do.

Thanks so much!

@mminkoff mminkoff merged commit faca6e2 into mminkoff:master Feb 15, 2018
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