@k03mad/ip2geo 9.7.0 → 10.1.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/.vscode/settings.json +1 -0
- package/app/cli.js +9 -1
- package/app/helpers/cache.js +20 -5
- package/app/helpers/utils.js +4 -0
- package/package.json +1 -1
package/.vscode/settings.json
CHANGED
package/app/cli.js
CHANGED
|
@@ -46,7 +46,13 @@ if (isPrune) {
|
|
|
46
46
|
log(blue(cacheFolder));
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
-
const {
|
|
49
|
+
const {
|
|
50
|
+
different,
|
|
51
|
+
duplicates,
|
|
52
|
+
empty,
|
|
53
|
+
entries,
|
|
54
|
+
longLinesFiles,
|
|
55
|
+
} = await pruneCache(
|
|
50
56
|
cacheFolder,
|
|
51
57
|
DEFAULT_CACHE_FILE_SEPARATOR,
|
|
52
58
|
DEFAULT_CACHE_FILE_NEWLINE,
|
|
@@ -56,6 +62,8 @@ if (isPrune) {
|
|
|
56
62
|
'',
|
|
57
63
|
green(`Removed duplicate cache entries: ${bold(duplicates.length)}`),
|
|
58
64
|
...duplicates.map(elem => dim(`— ${elem}`)),
|
|
65
|
+
green(`Removed different cache entries: ${bold(different.length)}`),
|
|
66
|
+
...different.map(elem => dim(`— ${elem}`)),
|
|
59
67
|
green(`Removed empty cache entries: ${bold(empty.length)}`),
|
|
60
68
|
...empty.map(elem => dim(`— ${elem}`)),
|
|
61
69
|
]);
|
package/app/helpers/cache.js
CHANGED
|
@@ -4,6 +4,8 @@ import path from 'node:path';
|
|
|
4
4
|
import _debug from 'debug';
|
|
5
5
|
import {isIP} from 'is-ip';
|
|
6
6
|
|
|
7
|
+
import {getArrayDups} from './utils.js';
|
|
8
|
+
|
|
7
9
|
const debug = _debug('mad:geoip');
|
|
8
10
|
|
|
9
11
|
const outputKeys = [
|
|
@@ -191,6 +193,7 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
|
|
|
191
193
|
);
|
|
192
194
|
|
|
193
195
|
const duplicates = new Set();
|
|
196
|
+
const different = new Set();
|
|
194
197
|
const empty = [];
|
|
195
198
|
const longLinesFiles = new Set();
|
|
196
199
|
let entries = 0;
|
|
@@ -215,25 +218,37 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
|
|
|
215
218
|
empty.push(elem);
|
|
216
219
|
});
|
|
217
220
|
|
|
218
|
-
const
|
|
221
|
+
const uniqSorted = [...new Set(dataArrRemoveEmpty)]
|
|
219
222
|
.sort((a, b) => cacheLineToNum(a) - cacheLineToNum(b));
|
|
220
223
|
|
|
221
|
-
const
|
|
224
|
+
const dupsIp = getArrayDups(uniqSorted.map(elem => elem.split(cacheFileSeparator)[0]));
|
|
225
|
+
|
|
226
|
+
const removeDiffs = uniqSorted.filter(elem => {
|
|
227
|
+
if (dupsIp.includes(elem.split(cacheFileSeparator)[0])) {
|
|
228
|
+
different.add(elem);
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const fileContent = removeDiffs.join(cacheFileNewline).trim();
|
|
222
236
|
|
|
223
237
|
if (fileContent) {
|
|
224
238
|
await fs.writeFile(fullFilePath, fileContent);
|
|
225
|
-
entries +=
|
|
239
|
+
entries += removeDiffs.length;
|
|
226
240
|
} else {
|
|
227
241
|
await fs.rm(fullFilePath);
|
|
228
242
|
}
|
|
229
243
|
|
|
230
|
-
dataArrRemoveEmpty
|
|
231
|
-
|
|
244
|
+
const dups = getArrayDups(dataArrRemoveEmpty);
|
|
245
|
+
dups.forEach(dup => duplicates.add(dup));
|
|
232
246
|
}));
|
|
233
247
|
|
|
234
248
|
return {
|
|
235
249
|
entries,
|
|
236
250
|
duplicates: [...duplicates],
|
|
251
|
+
different: [...different],
|
|
237
252
|
empty,
|
|
238
253
|
longLinesFiles: [...longLinesFiles],
|
|
239
254
|
};
|