Use new geo folder.

This commit is contained in:
Mike Cao 2023-03-28 19:24:36 -07:00
parent 23d02e5aac
commit 05933ff1d2
3 changed files with 12 additions and 9 deletions

8
.gitignore vendored
View File

@ -1,8 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies # dependencies
/node_modules node_modules
/.pnp .pnp
.pnp.js .pnp.js
# testing # testing
@ -16,14 +16,14 @@
# production # production
/build /build
/public/script.js /public/script.js
/public/geo /geo
# misc # misc
.DS_Store .DS_Store
.idea .idea
*.iml *.iml
*.log *.log
/.vscode/ .vscode
# debug # debug
npm-debug.log* npm-debug.log*

View File

@ -63,7 +63,9 @@ export async function getLocation(ip) {
// Database lookup // Database lookup
if (!lookup) { if (!lookup) {
lookup = await maxmind.open(path.resolve('node_modules/.geo/GeoLite2-Country.mmdb')); const dir = path.join(process.cwd(), 'geo');
lookup = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
} }
const result = lookup.get(ip); const result = lookup.get(ip);

View File

@ -7,16 +7,17 @@ const https = require('https');
const zlib = require('zlib'); const zlib = require('zlib');
const tar = require('tar'); const tar = require('tar');
let url = const db = 'GeoLite2-City';
'https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/GeoLite2-Country.tar.gz';
let url = `https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/${db}.tar.gz`;
if (process.env.MAXMIND_LICENSE_KEY) { if (process.env.MAXMIND_LICENSE_KEY) {
url = url =
`https://download.maxmind.com/app/geoip_download` + `https://download.maxmind.com/app/geoip_download` +
`?edition_id=GeoLite2-City&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`; `?edition_id=${db}&license_key=${process.env.MAXMIND_LICENSE_KEY}&suffix=tar.gz`;
} }
const dest = path.resolve(__dirname, '../node_modules/.geo'); const dest = path.resolve(__dirname, '../geo');
if (!fs.existsSync(dest)) { if (!fs.existsSync(dest)) {
fs.mkdirSync(dest); fs.mkdirSync(dest);