Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 718394a

Browse files
authored
fix: ipfs.id does not double append ipfs/<id> anymore (#732)
1 parent 89367a5 commit 718394a

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/core/components/id.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const mafmt = require('mafmt')
45

56
module.exports = function id (self) {
67
return promisify((opts, callback) => {
78
if (typeof opts === 'function') {
89
callback = opts
910
opts = {}
1011
}
11-
if (!self._peerInfo) { // because of split second warmup
12-
setTimeout(ready, 100)
13-
} else {
14-
ready()
15-
}
1612

17-
function ready () {
18-
callback(null, {
19-
id: self._peerInfo.id.toB58String(),
20-
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
21-
addresses: self._peerInfo.multiaddrs.map((ma) => {
22-
const addr = ma.toString() + '/ipfs/' + self._peerInfo.id.toB58String()
23-
return addr
24-
}).sort(),
25-
agentVersion: 'js-ipfs',
26-
protocolVersion: '9000'
27-
})
28-
}
13+
setImmediate(() => callback(null, {
14+
id: self._peerInfo.id.toB58String(),
15+
publicKey: self._peerInfo.id.pubKey.bytes.toString('base64'),
16+
addresses: self._peerInfo.multiaddrs.map((ma) => {
17+
if (mafmt.IPFS.matches(ma)) {
18+
return ma.toString()
19+
} else {
20+
return ma.toString() + '/ipfs/' + self._peerInfo.id.toB58String()
21+
}
22+
}).sort(),
23+
agentVersion: 'js-ipfs',
24+
protocolVersion: '9000'
25+
}))
2926
})
3027
}

0 commit comments

Comments
 (0)