@k03mad/ip2geo 11.6.0 → 11.7.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/app/api.js +15 -3
- package/package.json +2 -2
package/app/api.js
CHANGED
|
@@ -18,7 +18,7 @@ export const DEFAULT_CACHE_FILE_NAME = 'ip.log';
|
|
|
18
18
|
export const DEFAULT_CACHE_FILE_SEPARATOR = ';;';
|
|
19
19
|
export const DEFAULT_CACHE_FILE_NEWLINE = '\n';
|
|
20
20
|
export const DEFAULT_CACHE_MAP_MAX_ENTRIES = Number.POSITIVE_INFINITY;
|
|
21
|
-
export const
|
|
21
|
+
export const DEFAULT_CONCURRENCY = 2;
|
|
22
22
|
|
|
23
23
|
export const cacheStorage = new Map();
|
|
24
24
|
|
|
@@ -33,6 +33,7 @@ export const cacheStorage = new Map();
|
|
|
33
33
|
* @property {Map} [opts.cacheMap]
|
|
34
34
|
* @property {number} [opts.cacheMapMaxEntries]
|
|
35
35
|
* @property {number} [opts.rps]
|
|
36
|
+
* @property {number} [opts.concurrency]
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -64,7 +65,8 @@ export const ip2geo = async ({
|
|
|
64
65
|
cacheFileNewline = DEFAULT_CACHE_FILE_NEWLINE,
|
|
65
66
|
cacheMapMaxEntries = DEFAULT_CACHE_MAP_MAX_ENTRIES,
|
|
66
67
|
cacheMap = cacheStorage,
|
|
67
|
-
rps
|
|
68
|
+
rps,
|
|
69
|
+
concurrency,
|
|
68
70
|
} = {}) => {
|
|
69
71
|
if (ip) {
|
|
70
72
|
const mapCache = readFromMapCache(
|
|
@@ -97,7 +99,17 @@ export const ip2geo = async ({
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
const reqUrl = API + ip;
|
|
100
|
-
const
|
|
102
|
+
const queueOpts = {};
|
|
103
|
+
|
|
104
|
+
if (rps) {
|
|
105
|
+
queueOpts.rps = rps;
|
|
106
|
+
} else if (concurrency) {
|
|
107
|
+
queueOpts.concurrency = concurrency;
|
|
108
|
+
} else {
|
|
109
|
+
queueOpts.concurrency = DEFAULT_CONCURRENCY;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const {body} = await request(reqUrl, {}, queueOpts);
|
|
101
113
|
|
|
102
114
|
if (!body?.ip) {
|
|
103
115
|
throw new Error([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k03mad/ip2geo",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0",
|
|
4
4
|
"description": "GeoIP library",
|
|
5
5
|
"maintainers": [
|
|
6
6
|
"Kirill Molchanov <k03.mad@gmail.com"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@k03mad/eslint-config": "28.4.0",
|
|
30
|
-
"eslint": "9.
|
|
30
|
+
"eslint": "9.19.0",
|
|
31
31
|
"husky": "9.1.7",
|
|
32
32
|
"mocha": "11.1.0",
|
|
33
33
|
"npm-run-all": "4.1.5"
|