From f4187ba51ed9c1b3c8e0022bbd6dbba82c335a83 Mon Sep 17 00:00:00 2001 From: sapics Date: Sun, 8 Sep 2024 14:06:58 +0900 Subject: [PATCH] Use redist repository for update database --- .github/workflows/release.yml | 1 + scripts/updatedb.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0809ccc..fc4d72b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/updatedb.js b/scripts/updatedb.js index 4bf3f10..eff9138 100644 --- a/scripts/updatedb.js +++ b/scripts/updatedb.js @@ -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) @@ -177,6 +178,7 @@ 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') { @@ -184,8 +186,12 @@ function downloadDatabase(database, cb) { 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) } @@ -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) + } } }