Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.geoipLookupPromises[ipv4Addr] = this.queue.add(async () => {
try {
const data = await geoip.lookup(getIpfs(), ipv4Addr)
await this.geoipCache.set(ipv4Addr, data)
} catch (e) {
// mark this one as failed so we don't retry again
this.failedAddrs.set(ipv4Addr, true)
} finally {
delete this.geoipLookupPromises[ipv4Addr]
}
})
}
var getLocation = module.exports = function (ipfs, multiaddrs, cb) {
if (multiaddrs.length === 0) return cb(null, null)
var address = multiaddrs[0].split('/')[2]
if (isLocal(address)) return getLocation(ipfs, multiaddrs.slice(1), cb)
geoip.lookup(ipfs, address, function (err, res) {
if (err) {
throw err
}
if (!res.country_name && multiaddrs.length > 1) {
return getLocation(ipfs, multiaddrs.slice(1), cb)
}
var location = 'Earth'
if (res.country_name) location = res.country_name + ', ' + location
if (res.region_code) location = res.region_code + ', ' + location
if (res.city) location = res.city + ', ' + location
res.formatted = location
cb(null, res)
})