Skip to content

Commit

Permalink
feat: updated dataset (2022-10-18) (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored Oct 19, 2022
1 parent e7ae952 commit 4b508ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CHILDREN = 32
// DATA_HASH
// |- locationsCsv
// |- blocksCsv
const DATA_HASH = 'bafybeiacaphdy5t63opus5mzeerco7ckpbyqathghnxnf732xdwvrk73qm' // GeoLite2-City-CSV_20220628
const DATA_HASH = 'bafybeicfcxk4bx3nwmg3hwjmlc6n2qzn73mfm5itfpadwh5w7bux2chgz4' // GeoLite2-City-CSV_20221018
const locationsCsv = 'GeoLite2-City-Locations-en.csv'
const blocksCsv = 'GeoLite2-City-Blocks-IPv4.csv'

Expand Down
12 changes: 9 additions & 3 deletions src/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CID } from 'multiformats/cid'
import fetch from 'cross-fetch'
import { formatData } from './format.js'

export const GEOIP_ROOT = CID.parse('bafyreihpmffy4un3u3qstv5bskxmdekdzydujbbephdwhshrgbrecjnqme') // GeoLite2-City-CSV_20220628
export const GEOIP_ROOT = CID.parse('bafyreihnpl7ami7esahkfdnemm6idx4r2n6u3apmtcrxlqwuapgjsciihy') // b-tree version of GeoLite2-City-CSV_20221018

const defaultGateway = ['https://ipfs.io', 'https://dweb.link']

Expand All @@ -28,9 +28,15 @@ async function getRawBlock (ipfs, cid) {
for (const url of gateways) { // eslint-disable-line no-unreachable-loop
const gwUrl = new URL(url)
gwUrl.pathname = `/ipfs/${cid.toString()}`
gwUrl.search = '?format=raw'
gwUrl.search = '?format=raw' // necessary as not every gateway supports dag-cbor, but every should support sending raw block as-is
try {
const res = await fetch(gwUrl, { cache: 'force-cache' })
const res = await fetch(gwUrl, {
headers: {
// also set header, just in case ?format= is filtered out by some reverse proxy
Accept: 'application/vnd.ipld.raw'
},
cache: 'force-cache'
})
if (!res.ok) throw res
return new Uint8Array(await res.arrayBuffer())
} catch (cause) {
Expand Down
6 changes: 3 additions & 3 deletions test/lookup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe('lookup via HTTP Gateway supporting application/vnd.ipld.raw responses'
country_code: 'US',
region_code: 'VA',
city: 'Ashburn',
postal_code: '20103',
latitude: 39.0019,
longitude: -77.4556,
postal_code: '20149',
latitude: 39.0469,
longitude: -77.4903,
planet: 'Earth'
})
})
Expand Down

0 comments on commit 4b508ac

Please sign in to comment.