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

fix: dht.findPeer API endpoint returns ndjson #2965

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/ipfs-http-client/src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ module.exports = configure(api => {
return async function findPeer (peerId, options = {}) {
options.arg = `${Buffer.isBuffer(peerId) ? new CID(peerId) : peerId}`

const res = await api.post('dht/findpeer', {
const res = await api.ndjson('dht/findpeer', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was changed from a .post it needs to include method: 'POST' in the options.
See https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/src/dht/find-provs.js#L10-L15

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I think @lidel was going to PR the client to change all methods to post.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that now though..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking shape here: #2977

timeout: options.timeout,
signal: options.signal,
searchParams: options
})

const data = await res.json()

if (data.Type === 3) {
throw new Error(data.Extra)
}
for await (const data of res) {
if (data.Type === 3) {
throw new Error(data.Extra)
}

if (data.Type === 2 && data.Responses) {
const { ID, Addrs } = data.Responses[0]
return {
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
if (data.Type === 2 && data.Responses) {
const { ID, Addrs } = data.Responses[0]
return {
id: ID,
addrs: (Addrs || []).map(a => multiaddr(a))
}
}
}

Expand Down