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

Improve ipfs util #440

Closed

Conversation

Yuripetusko
Copy link
Contributor

@Yuripetusko Yuripetusko commented Feb 25, 2024

What changed? Why?

  • Use is-ipfs library to validate IPFS CID in provided uri/url
  • Handle IPFS URIs with folder/directory path structure
  • Handle HTTP IPFS URLs (many contracts use direct gateway urls in their contracts). And convert them to provided gateway
  • Use provided gateway on all required fields (previously metadata fetching was not using gateway)
  • Add more default gateway options, as ipfs.io fails often, so it is easier to test/develop before getting dedicated gateway

Notes to reviewers

How has it been tested?
yarn test

Fixes #441

- Use `is-ipfs` library to validate IPFS CID in provided uri/url
- Handle IPFS URIs with folder/directory path structure
- Handle http urls (many contracts use direct gateway urls in their contracts). And convert them to provided gateway
- Use provided gateway on all required fields (previously metadata fetching was not using gateway)
- Add more default gateway options, as ipfs.io fails often, so it is easier to test/develop before getting dedicated gateway
},
{
protocol: 'https',
hostname: 'nftstorage.link',
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's dope. Teach me a bit, how do they work together?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly telling nextjs to allow to load images from these domains in nextjs NextImage component

@@ -1,18 +1,128 @@
import { cid } from 'is-ipfs';
Copy link
Contributor

Choose a reason for hiding this comment

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

General thinking, I like a lot what's going on here.

Why some of these utility don't live in is-ipfs or, do we see other libraries have some of those?

Or should any of those live inside OnchainKit?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Yuripetusko thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is-ipfs is great, but it mostly just checks if url has ipfs, it doesn't have utils to replace gateway or add gateway and preserve the path etc. But regarding onchainkit I agree, I can create a similar PR there if this makes sense.

I actually have all of this code in a library already. Just need to add docs. Perhaps instead of having is-ipfs and all this code explicitly, our library will work? Otherwise I can just duplicate some of it in Onchainkit

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's probably move part of it inside OnchainKit.

We can proabably create a new section called IPFS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok will do tomorrow. I'll close this PR then and later will create a new one where onchainkit utils are used

@Yuripetusko Yuripetusko closed this Mar 8, 2024
@danimesq
Copy link

Hey @Yuripetusko 👋
Why you closed the PR?

@Yuripetusko
Copy link
Contributor Author

Hey @Yuripetusko 👋 Why you closed the PR?

The idea was to create a new one, more generic without any specific code that I had there that I copied over from our ipfs-utils https://github.com/rmrk-team/rmrk-js/tree/main/packages/ipfs-utils

unfortunately life and work happened and I couldn't find a time to do it since.

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

Successfully merging this pull request may close these issues.

Feature Request: Improve ipfs utils
3 participants