mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Use local geo database instead of npm package.
This commit is contained in:
parent
6db386a455
commit
ad95da63b7
6 changed files with 65 additions and 24 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import path from 'path';
|
||||
import requestIp from 'request-ip';
|
||||
import { browserName, detectOS } from 'detect-browser';
|
||||
import isLocalhost from 'is-localhost-ip';
|
||||
import maxmind from 'maxmind';
|
||||
import geolite2 from 'geolite2-redist';
|
||||
import {
|
||||
DESKTOP_OS,
|
||||
MOBILE_OS,
|
||||
|
|
@ -60,15 +60,11 @@ export async function getCountry(req, ip) {
|
|||
}
|
||||
|
||||
// Database lookup
|
||||
const lookup = await geolite2.open('GeoLite2-Country', path => {
|
||||
return maxmind.open(path);
|
||||
});
|
||||
const lookup = await maxmind.open(path.resolve(__dirname, '../geo/GeoLite2-Country.mmdb'));
|
||||
|
||||
const result = lookup.get(ip);
|
||||
|
||||
lookup.close();
|
||||
|
||||
return result.country.iso_code;
|
||||
return result?.country?.iso_code;
|
||||
}
|
||||
|
||||
export async function getClientInfo(req, { screen }) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue