Skip to content

Commit

Permalink
fix: remove is-ipfs from @helia/ipns dependencies (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Feb 7, 2024
1 parent 483ba43 commit 3851fe2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/ipns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@
"hashlru": "^2.3.0",
"interface-datastore": "^8.2.10",
"ipns": "^9.0.0",
"is-ipfs": "^8.0.1",
"multiformats": "^13.0.1",
"p-queue": "^8.0.1",
"progress-events": "^1.0.0",
Expand Down
15 changes: 8 additions & 7 deletions packages/ipns/src/utils/dns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CodeError } from '@libp2p/interface'
import * as isIPFS from 'is-ipfs'
import { CID } from 'multiformats/cid'
import type { DNSResolver, ResolveDnsLinkOptions } from '../index.js'

export interface Question {
Expand Down Expand Up @@ -91,14 +91,15 @@ export const recursiveResolveDnslink = async (domain: string, depth: number, res
const result = dnslinkRecord.replace('dnslink=', '')
// result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
const domainOrCID = result.split('/')[2] // e.g. ["", "ipfs", "<cid>"]
const isIPFSCID = isIPFS.cid(domainOrCID)

// if the result is a CID, or depth is 1, we've reached the end of the recursion
// if depth is 1, another recursive call will be made, but it would throw.
// we could return if depth is 1 and allow users to handle, but that may be a breaking change
if (isIPFSCID) {
try {
CID.parse(domainOrCID)

// if the result is a CID, or depth is 1, we've reached the end of the recursion
// if depth is 1, another recursive call will be made, but it would throw.
// we could return if depth is 1 and allow users to handle, but that may be a breaking change
return result
}
} catch {}

return recursiveResolveDnslink(domainOrCID, depth - 1, resolve, options)
}
Expand Down

0 comments on commit 3851fe2

Please sign in to comment.