Skip to content

Commit

Permalink
fix: handle new and old object api
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla authored and daviddias committed Jan 3, 2019
1 parent 63cd03e commit 791a8af
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ function _lookup (ipfs, hash, lookfor, cb) {

const next = res.links[child - 1]

if (!next || !next.multihash) {
if (!next) {
return cb(new Error('Failed to lookup node'))
}

return memoizedLookup(ipfs, next.multihash, lookfor, cb)
const nextCid = getCid(next)

if (!nextCid) {
return cb(new Error('Failed to lookup node'))
}

return memoizedLookup(ipfs, nextCid, lookfor, cb)
} else if (obj.type === 'Leaf') {
while (obj.data[child] && obj.data[child].min <= lookfor) {
child++
Expand All @@ -60,3 +66,12 @@ memoizedLookup = memoize(_lookup, {async: true})
module.exports = function lookup (ipfs, ip, cb) {
memoizedLookup(ipfs, GEOIP_ROOT, inet.aton(ip), cb)
}

function getCid (node) {
if (!node) return null
// Handle ipfs-api < 27.0.0
if (node.multihash) return node.multihash
// Handle ipfs-http-client >= 27.0.0
if (node.cid) return node.cid.toString()
return null
}

0 comments on commit 791a8af

Please sign in to comment.