Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(cloudflare): add support for cloudflare's image cdn#2

Merged
ascorbic merged 4 commits into
ascorbic:mainfrom
nicksrandall:nick/cloudflare
Feb 12, 2023
Merged

feat(cloudflare): add support for cloudflare's image cdn#2
ascorbic merged 4 commits into
ascorbic:mainfrom
nicksrandall:nick/cloudflare

Conversation

@nicksrandall

@nicksrandall nicksrandall commented Feb 12, 2023

Copy link
Copy Markdown
Contributor

Fixes: #1

@nicksrandall

Copy link
Copy Markdown
Contributor Author

I'm excited to delete the custom, 100+ line image component in my app and replace it with this -- I just need it to support Cloudflare :)

If it's not too much trouble, could you please push a new version to NPM of this and unpic-img when (if?) this PR is merged?

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for this! Are there any default domains that it can auto-detect, or is it always the user's domain? Could you share a real example image to test it, preferably one from the Cloudflare docs.

Could you also add it to the README, but with a note saying that it's not auto-detected and needs to be manually specified. Thanks again!

Comment thread src/transformers/cloudflare.ts Outdated
Comment thread src/transformers/cloudflare.ts Outdated
@nicksrandall

Copy link
Copy Markdown
Contributor Author

I'll get your feedback implemented.

Regarding auto detection by domain, that is not possible with cloudflare because it always uses the users domain. That said, it would be possible to detect by a pathname prefix (/cdn-cgi/image). Do you think its worth adding that logic (similar to how you currently do subdomains)?

@nicksrandall

Copy link
Copy Markdown
Contributor Author

@ascorbic I addressed your feedback. I wasn't able to find an image in the docs that works but I did change the URL to match what is in the docs.

Also, I was able to add Cloudflare to the detection function by looking for a specific path prefix. Let me know if you think that is acceptable.

Comment thread src/transformers/cloudflare.test.ts Outdated
import { CloudflareParams, parse, transform } from "./cloudflare.ts";

const img =
"https://assets.example.comeight=64,f=auto,background=red/uploads/avatar1.jpg"

@ascorbic ascorbic Feb 12, 2023

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think something's wrong with this URL!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread src/transformers/cloudflare.test.ts Outdated

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good idea with the path matching. I think there are some others that we could use that approach for. Just a couple of typos left. I would really like if we can find at least one valid URL that can be used to demo this, so it can be added to the playground in examples.json. Otherwise I've no way of being sure it actually works. Comparing it to the docs only goes so far.

@ascorbic

Copy link
Copy Markdown
Owner

The tests are failing because of that broken url

@nicksrandall

Copy link
Copy Markdown
Contributor Author

Fixed the test with a generic image from my app. Hopefully that is good enough?

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Perfect! Thanks for your help

@ascorbic ascorbic merged commit 0ad2543 into ascorbic:main Feb 12, 2023
@mixie-bot mixie-bot Bot mentioned this pull request Dec 7, 2024
@mixie-bot mixie-bot Bot mentioned this pull request Dec 15, 2024
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.

Support for Cloudflare image service

2 participants