-
Notifications
You must be signed in to change notification settings - Fork 22
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: support subdomains in isIPFS.url(url) #32
Conversation
This change adds support for DNSLink subdomains on localhost gateway (ipfs/kubo#6096) Example: en.wikipedia-on-ipfs.org.ipfs.localhost:8080 BREAKING CHANGE: `isIPFS.subdomain` now returns true for <domain.tld>.ipns.localhost BREAKING CHANGE: `isIPFS.subdomainPattern` changed License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
Context: libp2p/libp2p#79 License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
.url and .path now return true when validating: https://ipfs.io/ipfs/<CID>?filename=name.png#foo License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
|
||
### `isIPFS.ipfsSubdomain(url)` | ||
|
||
Returns `true` if the provided string includes a valid IPFS subdomain or `false` otherwise. | ||
Returns `true` if the provided `url` string includes a valid IPFS subdomain (case-insensitive CIDv1) or `false` otherwise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it check for a case insensitive encoding or is this actually just base32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web browsers force-lowercase hostname in URL and is-ipfs does the same before we check if CID in subdomain is valid:
https://github.com/ipfs/is-ipfs/blob/f1823cc0b12e97ac1f202ba7c06663b5b9b5d265/src/index.js#L83-L87
README.md
Outdated
|
||
isIPFS.path('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true | ||
isIPFS.path('/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?filename=guardian.jpg') // true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a thing now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ?filename=
sets proper Content-Disposition header and all that jazz. Folks use it as more efficient way of sharing single file, as it keeps the same CID while enables filename tweaks (does not require wrapping in a directory)
I've added it to README as its important to show that URL params do not impact CID validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it does that for URLs on the gateways but I didn't know if we'd formalised it in IPFS paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I get your point now.
No, it is not formalized in the context of IPFS paths – ?filename=foo.jpg
is just a valid filename in IPFS.
See this example:
$ ipfs object patch add-link QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn "?filename=test.jpg" QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
QmbcBPAwCDxRMB1Qe7CRQmxdrTSkxKwM9y6rZw2FjGtbsb
$ ipfs ls /ipfs/QmbcBPAwCDxRMB1Qe7CRQmxdrTSkxKwM9y6rZw2FjGtbsb
QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR 119762 ?filename=test.jpg
When exposed on the gateway, filenames are URIencoded:
https://ipfs.io/ipfs/QmbcBPAwCDxRMB1Qe7CRQmxdrTSkxKwM9y6rZw2FjGtbsb/%3Ffilename=test.jpg
Here I just forgot /
before ?
, but I agree the naming overlap is confusing, so I changed it to be something else:
isIPFS.path('/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?filename=guardian.jpg') // true | |
isIPFS.path('/ipfs/QmbcBPAwCDxRMB1Qe7CRQmxdrTSkxKwM9y6rZw2FjGtbsb/?weird-filename=test.jpg') // true |
When .url was created we only had path gateways. When .subdomain was added, we did not update .url to test for subdomain gateways, which in the long run will confuse people and feels like a bug. Let's fix this: .url() will now check for both subdomain and path gateways #32 (comment) BREAKING CHANGE: .url(url) now returns true if .subdomain(url) is true License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
When .url was created we only had path gateways. When .subdomain was added, we did not update .url to test for subdomain gateways, which in the long run will confuse people and feels like a bug. Let's fix this: .url() will now check for both subdomain and path gateways #32 (comment) BREAKING CHANGE: .url(url) now returns true if .subdomain(url) is true License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
bd61cb6
to
c520efc
Compare
This makes subdomain checks follow what path gateway checks do, removing confusion. In both cases (IPNS and DNSLink) user needs to perform online record check, so this is just a handy way of detecting potential matches. License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
8066bad
to
d5717e9
Compare
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
978a5ed
to
87d746a
Compare
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
This PR updates
isIPFS.url(url)
to return true ifisIPFS.subdomain(url)
does,and improves
isIPFS.ipnsSubdomain(url)
to match potential DNSLink just likeisIPFS.ipnsPath(url)
already did.This is needed for ipfs/ipfs-companion#853:
BREAKING CHANGES
isIPFS.subdomain
now returns true for<domain.tld>.ipns.localhost
isIPFS.subdomainPattern|pathPattern|urlPattern
are replaced withpathPattern|pathGatewayPattern|subdomainGatewayPattern
isIPFS.url
now returns true ifisIPFS.subdomain
didDue to this I plan to release this as v1.0.0