Skip to content

Commit f30f938

Browse files
authored
fix: dht.findPeer API endpoint returns ndjson (#2965)
1 parent 0400ad2 commit f30f938

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/dht/find-peer.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ module.exports = configure(api => {
99
return async function findPeer (peerId, options = {}) {
1010
options.arg = `${Buffer.isBuffer(peerId) ? new CID(peerId) : peerId}`
1111

12-
const res = await api.post('dht/findpeer', {
12+
const res = await api.ndjson('dht/findpeer', {
1313
timeout: options.timeout,
1414
signal: options.signal,
1515
searchParams: options
1616
})
1717

18-
const data = await res.json()
19-
20-
if (data.Type === 3) {
21-
throw new Error(data.Extra)
22-
}
18+
for await (const data of res) {
19+
if (data.Type === 3) {
20+
throw new Error(data.Extra)
21+
}
2322

24-
if (data.Type === 2 && data.Responses) {
25-
const { ID, Addrs } = data.Responses[0]
26-
return {
27-
id: ID,
28-
addrs: (Addrs || []).map(a => multiaddr(a))
23+
if (data.Type === 2 && data.Responses) {
24+
const { ID, Addrs } = data.Responses[0]
25+
return {
26+
id: ID,
27+
addrs: (Addrs || []).map(a => multiaddr(a))
28+
}
2929
}
3030
}
3131

0 commit comments

Comments
 (0)