Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit f267dd3

Browse files
update to new consistent api
1 parent 690a77c commit f267dd3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/api/swarm.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module.exports = (send) => {
1313
opts = {}
1414
}
1515

16+
const verbose = opts.v || opts.verbose
17+
1618
send({
1719
path: 'swarm/peers',
1820
qs: opts
@@ -21,14 +23,24 @@ module.exports = (send) => {
2123
return callback(err)
2224
}
2325

24-
console.log(JSON.stringify(result, null, 2))
25-
2626
if (result.Strings) {
2727
// go-ipfs <= 0.4.4
2828
callback(null, result.Strings.map((p) => {
29-
// splitting on whitespace as verbose mode
30-
// returns the latency appended
31-
return multiaddr(p.split(' ')[0])
29+
const res = {}
30+
31+
if (verbose) {
32+
const parts = p.split(' ')
33+
res.addr = multiaddr(parts[0])
34+
res.latency = parts[1]
35+
} else {
36+
res.addr = multiaddr(p)
37+
}
38+
39+
res.peer = PeerId.createFromB58String(
40+
res.addr.decapsulate('ipfs')
41+
)
42+
43+
return res
3244
}))
3345
} else if (result.Peers) {
3446
// go-ipfs >= 0.4.5

0 commit comments

Comments
 (0)