@smpx/koa-request 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GeoIP.js +13 -4
- package/IPRange.js +11 -5
- package/Request.js +8 -1
- package/index.js +2 -0
- package/package.json +6 -6
package/GeoIP.js
CHANGED
|
@@ -9,6 +9,7 @@ const fileName = 'GeoLite2-City';
|
|
|
9
9
|
const fileUrl = `https://raw.githubusercontent.com/GitSquared/node-geolite2-redist/master/redist/${fileName}.tar.gz`;
|
|
10
10
|
const fileDir = __dirname;
|
|
11
11
|
const filePath = `${fileDir}/${fileName}.mmdb`;
|
|
12
|
+
let geoInitPromise;
|
|
12
13
|
let geoip;
|
|
13
14
|
|
|
14
15
|
function save(url, outDir) {
|
|
@@ -84,13 +85,21 @@ async function updateDb() {
|
|
|
84
85
|
setTimeout(updateDb, 3 * 24 * 3600 * 1000);
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
async function geoIpInit() {
|
|
89
|
+
await download();
|
|
90
|
+
geoip = await maxmind.open(filePath);
|
|
91
|
+
if (process.env.NODE_ENV === 'production') {
|
|
92
|
+
updateDb();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
87
96
|
async function getGeoIp() {
|
|
88
97
|
if (!geoip) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (process.env.NODE_ENV === 'production') {
|
|
92
|
-
updateDb();
|
|
98
|
+
if (!geoInitPromise) {
|
|
99
|
+
geoInitPromise = geoIpInit();
|
|
93
100
|
}
|
|
101
|
+
await geoInitPromise;
|
|
102
|
+
geoInitPromise = null;
|
|
94
103
|
}
|
|
95
104
|
return geoip;
|
|
96
105
|
}
|
package/IPRange.js
CHANGED
|
@@ -11,6 +11,7 @@ const PRIVATE_IPS = [
|
|
|
11
11
|
];
|
|
12
12
|
|
|
13
13
|
// Source: https://www.lifewire.com/what-is-the-ip-address-of-google-818153
|
|
14
|
+
// https://developers.google.com/search/apis/ipranges/googlebot.json
|
|
14
15
|
const GOOGLE_IPS = [
|
|
15
16
|
'64.233.160.0 - 64.233.191.255',
|
|
16
17
|
'66.102.0.0 - 66.102.15.255',
|
|
@@ -27,11 +28,16 @@ const GOOGLE_IPS = [
|
|
|
27
28
|
];
|
|
28
29
|
|
|
29
30
|
const SEARCH_IPS = [
|
|
30
|
-
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
31
|
+
// BingBot (https://www.bing.com/toolbox/bingbot.json)
|
|
32
|
+
'157.55.0.0/16',
|
|
33
|
+
'207.46.0.0/19',
|
|
34
|
+
'52.167.144.0/24',
|
|
35
|
+
'40.77.128.0/17',
|
|
36
|
+
// YANDAX
|
|
37
|
+
'178.154.128.0/17',
|
|
38
|
+
'87.250.224.0/19',
|
|
39
|
+
// Apple
|
|
40
|
+
'17.0.0.0/8',
|
|
35
41
|
];
|
|
36
42
|
|
|
37
43
|
let compiledPrivateIps;
|
package/Request.js
CHANGED
|
@@ -1423,9 +1423,16 @@ class Request {
|
|
|
1423
1423
|
}
|
|
1424
1424
|
}
|
|
1425
1425
|
|
|
1426
|
+
geoipLoc() {
|
|
1427
|
+
if (this._giploc === undefined) {
|
|
1428
|
+
this._giploc = GeoIP.getSync(this.ip()) || {};
|
|
1429
|
+
}
|
|
1430
|
+
return this._giploc;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1426
1433
|
ipLocation() {
|
|
1427
1434
|
if (this._ipLoc === undefined) {
|
|
1428
|
-
const loc =
|
|
1435
|
+
const loc = this.geoipLoc();
|
|
1429
1436
|
const country = loc.country;
|
|
1430
1437
|
const city = loc.city;
|
|
1431
1438
|
const state = loc.subdivisions && loc.subdivisions[0];
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smpx/koa-request",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Handle basic tasks for koajs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/smartprix/koa-request#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"ip": "^
|
|
33
|
+
"ip": "^2.0.1",
|
|
34
34
|
"koa-basic-auth": "^4.0.0",
|
|
35
35
|
"koa-body": "^5.0.0",
|
|
36
36
|
"koa-send": "^5.0.1",
|
|
37
|
-
"koa2-ratelimit": "^1.1.
|
|
38
|
-
"maxmind": "^4.3.
|
|
39
|
-
"tar": "^6.1
|
|
40
|
-
"ua-parser-js": "^1.0.
|
|
37
|
+
"koa2-ratelimit": "^1.1.3",
|
|
38
|
+
"maxmind": "^4.3.20",
|
|
39
|
+
"tar": "^6.2.1",
|
|
40
|
+
"ua-parser-js": "^1.0.38"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"eslint": "^5.7.0",
|