This commit is contained in:
undefined committed 2020-08-06 14:24:16 +08:00
1 parent 8389519249
commit a5886ecb99
37 files changed
+940 -162

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
# GeoIp
显示用户登录地。
IP geo-location data is provided by [Maxmind](http://www.maxmind.com)
+26
View File
@@ -0,0 +1,26 @@
import fs from 'fs';
import path from 'path';
import { Reader } from 'maxmind';
const buffer = fs.readFileSync(path.resolve(__dirname, 'GeoLite2-City.mmdb'));
const reader = new Reader(buffer);
function lookup(ip: string, locale: string) {
const res: any = reader.get(ip);
if (!res) return {};
const ret: any = {};
if (res.location) ret.location = res.location;
if (res.continent) ret.continent = res.continent.names[locale] || res.continent.names.en;
if (res.country || res.registered_country) {
ret.country = (res.country || res.registered_country).names[locale]
|| (res.country || res.registered_country).names.en;
}
if (res.city) ret.city = res.city.names[locale] || res.city.names.en;
ret.display = `${ret.continent} ${ret.country} ${ret.city}`;
return ret;
}
global.Hydro.lib.geoip = exports = {
provider: '<a href="http://www.maxmind.com" target="_blank">MaxMind</a>',
lookup,
};
+1
View File
@@ -0,0 +1 @@
geoip_locale: zh-CN
+1
View File
@@ -0,0 +1 @@
geoip_locale: zh-CN
+14
View File
@@ -0,0 +1,14 @@
{
"name": "@hydrooj/geoip",
"version": "1.1.6",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <masnn0@outlook.com>",
"license": "MIT",
"dependencies": {
"maxmind": "^4.1.3"
},
"peerDependencies": {
"hydrooj": "^2.12.0"
}
}
+4
View File
@@ -0,0 +1,4 @@
wget -O ./GeoLite2-City.tar.gz "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${LICENSE_KEY}&suffix=tar.gz"
tar zxvf ./GeoLite2-City.tar.gz -C .
mv ./GeoLite2-City_*/GeoLite2-City.mmdb ./GeoLite2-City.mmdb
rm -r ./GeoLite2-City_* ./GeoLite2-City.tar.gz