Skip to content

Commit

Permalink
Use redist repository for update database
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed Sep 8, 2024
1 parent 594849d commit f4187ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
run: npm run-script updatedb
env:
GEOLITE2_LICENSE_KEY: ${{secrets.GEOLITE2_LICENSE_KEY}}
GEOIP_USE_REDIST: true
- name: test
run: npm run test
- name: commit
Expand Down
16 changes: 12 additions & 4 deletions scripts/updatedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var language = process.env.npm_config_geoip_language || process.env.GEOIP_LANGUA
var isDebug = process.argv.indexOf('debug') >= 0
var addFakeData = process.env.npm_config_geoip_fake_data || process.env.GEOIP_FAKE_DATA || false
var unusedFields = process.env.npm_config_geoip_unused_fields || process.env.GEOIP_UNUSED_FIELDS
var useRedist = process.env.npm_config_geoip_use_redist || process.env.GEOIP_USE_REDIST || false
for(var i = 0; i < process.argv.length; ++i){
var arg = process.argv[i]
if(isDebug) console.log(arg)
Expand Down Expand Up @@ -177,15 +178,20 @@ function CSVtoArray(text) {
return a
}

var RedistDownloadUrl = 'https://raw.githubusercontent.com/sapics/node-geolite2-redist/master/redist/'
function downloadDatabase(database, cb) {
var downloadUrl, fileName
if(typeof database === 'string') {
// for ip-location-db
downloadUrl = database
fileName = path.basename(downloadUrl)
} else {
// for maxmind
downloadUrl = download_server + '?edition_id=' + database.edition + '&suffix=' + database.suffix + "&license_key=" + encodeURIComponent(license_key)
if(useRedist){
downloadUrl = RedistDownloadUrl + database.edition + '.' + database.suffix
} else {
// for maxmind
downloadUrl = download_server + '?edition_id=' + database.edition + '&suffix=' + database.suffix + "&license_key=" + encodeURIComponent(license_key)
}
fileName = database.edition + '.' + database.suffix
console.log('Fetching edition ' + database.edition + ' from ' + download_server)
}
Expand Down Expand Up @@ -927,8 +933,10 @@ if(ip_location_db){
} else {
if(!isDebug){
if (!license_key || license_key === "true") {
console.log('No GeoLite2 License Key Provided, Please Provide Argument: `--license_key=`')
process.exit(1)
if(!useRedist){
console.log('No GeoLite2 License Key Provided, Please Provide Argument: `--license_key=`')
process.exit(1)
}
}
}

Expand Down

0 comments on commit f4187ba

Please sign in to comment.