Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated dataset (2022-10-18) #97

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
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
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