Skip to content

Commit ccff48b

Browse files
hugomrdiaslidel
authored andcommitted
fix: append remainder
1 parent 2091b89 commit ccff48b

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"execa": "^1.0.0",
7373
"form-data": "^2.3.3",
7474
"hat": "0.0.3",
75-
"interface-ipfs-core": "~0.99.1",
75+
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#feat/name-resolve-dns",
7676
"ipfsd-ctl": "~0.42.0",
7777
"libp2p-websocket-star": "~0.10.2",
7878
"ncp": "^2.0.0",

Diff for: src/cli/commands/name/resolve.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ module.exports = {
3232
const ipfs = await argv.getIpfs()
3333
const result = await ipfs.name.resolve(argv.name, opts)
3434

35-
if (result && result.path) {
36-
print(result.path)
37-
} else {
38-
print(result)
39-
}
35+
print(result)
4036
})())
4137
}
4238
}

Diff for: src/core/components/name.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ const keyLookup = (ipfsNode, kname, callback) => {
3838
})
3939
}
4040

41+
const appendRemainder = (cb, remainder) => {
42+
return (err, result) => {
43+
if (err) {
44+
return cb(err)
45+
}
46+
if (remainder.length) {
47+
return cb(null, result + '/' + remainder.join('/'))
48+
}
49+
return cb(null, result)
50+
}
51+
}
52+
4153
/**
4254
* @typedef { import("../index") } IPFS
4355
*/
@@ -46,7 +58,7 @@ const keyLookup = (ipfsNode, kname, callback) => {
4658
* IPNS - Inter-Planetary Naming System
4759
*
4860
* @param {IPFS} self
49-
* @returns {Function}
61+
* @returns {Object}
5062
*/
5163
module.exports = function name (self) {
5264
return {
@@ -162,27 +174,28 @@ module.exports = function name (self) {
162174
name = `/ipns/${name}`
163175
}
164176

165-
const [ , hash ] = name.slice(1).split('/')
177+
const [ namespace, hash, ...remainder ] = name.slice(1).split('/')
166178
try {
167179
mh.fromB58String(hash)
168-
169-
// ipns resolve needs a online daemon
170-
if (!self.isOnline() && !offline) {
171-
const errMsg = utils.OFFLINE_ERROR
172-
173-
log.error(errMsg)
174-
return callback(errcode(errMsg, 'OFFLINE_ERROR'))
175-
}
176-
self._ipns.resolve(name, options, callback)
177180
} catch (err) {
178181
// lets check if we have a domain ex. /ipns/ipfs.io and resolve with dns
179182
if (isDomain(hash)) {
180-
return self.dns(hash, options, callback)
183+
return self.dns(hash, options, appendRemainder(callback, remainder))
181184
}
182185

183186
log.error(err)
184-
callback(errcode(new Error('Invalid IPNS name.'), 'ERR_IPNS_INVALID_NAME'))
187+
return callback(errcode(new Error('Invalid IPNS name.'), 'ERR_IPNS_INVALID_NAME'))
188+
}
189+
190+
// multihash is valid lets resolve with IPNS
191+
// IPNS resolve needs a online daemon
192+
if (!self.isOnline() && !offline) {
193+
const errMsg = utils.OFFLINE_ERROR
194+
195+
log.error(errMsg)
196+
return callback(errcode(errMsg, 'OFFLINE_ERROR'))
185197
}
198+
self._ipns.resolve(`/${namespace}/${hash}`, options, appendRemainder(callback, remainder))
186199
}),
187200
pubsub: namePubsub(self)
188201
}

0 commit comments

Comments
 (0)