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

feat: improve ipfs media download when file its in folder #7752

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

evavirseda
Copy link
Collaborator

Summary

Closes #7689

...

Changelog

- Please write a list of changes

Testing

Platforms

Please select any platforms where your changes have been tested.

  • Desktop
    • MacOS
    • Linux
    • Windows

Instructions

Please describe the specific instructions, configurations, and/or test cases necessary to test and verify that your changes work as intended.

...

Checklist

Please tick the following boxes that are relevant to your changes.

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or modified tests that prove my changes work as intended
  • I have verified that new and existing unit tests pass locally with my changes
  • I have verified that my latest changes pass CI workflows for testing and linting
  • I have made corresponding changes to the documentation

@evavirseda evavirseda marked this pull request as ready for review November 29, 2023 15:09
Copy link
Collaborator

@brancoder brancoder left a comment

Choose a reason for hiding this comment

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

There seams to be an issue with encoding this example ipfs://bafybeigbmawzzda64hrr2zenodmivfandhkjsrf7nkcic52y5wb6nxywja


export async function getIpfsUri(link: { path?: string; hash: string }): Promise<string | undefined> {
try {
const slicedLink = link.hash.slice('https://ipfs.io/'.length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use the the constant IPFS_ENDPOINT here instead of hardcoded string

@@ -8,6 +9,13 @@ export function updateNftInAllAccountNfts(accountIndex: number, nftId: string, p
}
const nft = state[accountIndex].find((_nft) => _nft.id === nftId)
if (nft) {
const downloadUrl = nft.downloadUrl
void getIpfsUri({ hash: downloadUrl }).then((ipfsUri) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we check if the downloadUrl is a ipfs link before calling getIpfsUri for every nft? wdyt?

nft.composedUrl = ipfsUri
}
})
if (downloadUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking something along the lines like this check we have in explorer: https://github.com/iotaledger/explorer/blob/dev/client/src/helpers/hooks/useNftMetadataUri.ts#L22
Looks to me that we now try to getIpfsUri even if downloadUrl is not ipfs link.

@begonaalvarezd
Copy link
Member

There seams to be an issue with encoding this example ipfs://bafybeigbmawzzda64hrr2zenodmivfandhkjsrf7nkcic52y5wb6nxywja

This one is a folder inside a folder, I would ignore it, we should just check 1 level

const ipfsPrefix = 'ipfs'

if (url?.includes(ipfsPrefix)) {
return url.slice(ipfsPrefix.length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method now returns url with first 4 characters sliced ex. s://ipfs.io/ipfs....... instead of ipfs hash.

Copy link
Member

@begonaalvarezd begonaalvarezd left a comment

Choose a reason for hiding this comment

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

Im requesting changes just to block this PR from being merged, I would like to have a security expert have a look at it before we add it to production builds 🙏🏼

@@ -0,0 +1,7 @@
export function getIPFSHash(url?: string): string | undefined {
const ipfsPrefix = 'https://ipfs.io'
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are other gateways apart from ipfs.io, this isn't very robust imo

const ipfsPrefix = 'https://ipfs.io'

if (url?.includes(ipfsPrefix)) {
return url.slice(ipfsPrefix.length)
Copy link
Member

@rajivshah3 rajivshah3 Mar 28, 2024

Choose a reason for hiding this comment

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

Would it be better to use the URL module? Then we can also address @marc2332 's comment. If we have this URL:

https://cloudflare-ipfs.com/ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/Vincent_van_Gogh.html

and we want to get the bafy... part I think we could do this:

const ipfsUrl = new URL("https://cloudflare-ipfs.com/ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/wiki/Vincent_van_Gogh.html")
const path = ipfsUrl.pathname
return path.replace("/ipfs/", "").split("/")[0]

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.

[Task]: Improve ipfs media download when file its in folder
5 participants