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

Add series option to support GeoIP2 premium database #265

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Run `cd node_modules/geoip-lite && npm run-script updatedb license_key=YOUR_LICE

You can create a maxmind account [here](https://www.maxmind.com/en/geolite2/signup)

Maxmind also sells subscriptions to premium and more accurate data. With a subscritpion the files can be updated with the `series` option. With a license key with a premium subscription, run `cd node_modules/geoip-lite && npm run-script updatedb license_key=YOUR_LICENSE_KEY series=GeoIP2` to update the data files with the premium more accureate data sets.

**NOTE** that this requires a lot of RAM. It is known to fail on on a Digital Ocean or AWS micro instance.
There are no plans to change this. `geoip-lite` stores all data in RAM in order to be fast.

Expand Down
35 changes: 23 additions & 12 deletions scripts/updatedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ var geodatadir = args.find(function(arg) {
if (typeof geodatadir === 'undefined' && typeof process.env.GEODATADIR !== 'undefined') {
geodatadir = 'geodatadir='+process.env.GEODATADIR;
}
var series = args.find(function(arg) {
return arg.match(/^series=[\w./]+/) !== null;
});
if (typeof series === 'undefined' && typeof process.env.GEODBSERIES !== 'undefined') {
series = process.env.GEODBSERIES;
} else if (typeof series !== 'undefined') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you move the else if to a new line?

series = series.slice('series='.length);
}
if (typeof series === 'undefined') {
series = 'GeoLite2'
Copy link
Collaborator

Choose a reason for hiding this comment

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

check indentation on these lines.

}
var dataPath = path.resolve(__dirname, '..', 'data');
if (typeof geodatadir !== 'undefined') {
dataPath = path.resolve(process.cwd(), geodatadir.split('=')[1]);
Expand All @@ -51,13 +62,13 @@ var cityLookup = {NaN: -1};
var databases = [
{
type: 'country',
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&'+license_key,
checksum: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&'+license_key,
fileName: 'GeoLite2-Country-CSV.zip',
url: 'https://download.maxmind.com/app/geoip_download?edition_id='+series+'-Country-CSV&suffix=zip&'+license_key,
checksum: 'https://download.maxmind.com/app/geoip_download?edition_id='+series+'-Country-CSV&suffix=zip.sha256&'+license_key,
fileName: series+'-Country-CSV.zip',
src: [
'GeoLite2-Country-Locations-en.csv',
'GeoLite2-Country-Blocks-IPv4.csv',
'GeoLite2-Country-Blocks-IPv6.csv'
series+'-Country-Locations-en.csv',
series+'-Country-Blocks-IPv4.csv',
series+'-Country-Blocks-IPv6.csv'
],
dest: [
'',
Expand All @@ -67,13 +78,13 @@ var databases = [
},
{
type: 'city',
url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&'+license_key,
checksum: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&'+license_key,
fileName: 'GeoLite2-City-CSV.zip',
url: 'https://download.maxmind.com/app/geoip_download?edition_id='+series+'-City-CSV&suffix=zip&'+license_key,
checksum: 'https://download.maxmind.com/app/geoip_download?edition_id='+series+'-City-CSV&suffix=zip.sha256&'+license_key,
fileName: series+'-City-CSV.zip',
src: [
'GeoLite2-City-Locations-en.csv',
'GeoLite2-City-Blocks-IPv4.csv',
'GeoLite2-City-Blocks-IPv6.csv'
series+'-City-Locations-en.csv',
series+'-City-Blocks-IPv4.csv',
series+'-City-Blocks-IPv6.csv'
],
dest: [
'geoip-city-names.dat',
Expand Down