@k03mad/ip2geo 10.0.0 → 10.1.1
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/helpers/cache.js +17 -19
- package/app/helpers/utils.js +4 -0
- package/package.json +1 -1
package/.vscode/settings.json
CHANGED
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 = [
|
|
@@ -216,33 +218,29 @@ export const pruneCache = async (cacheDir, cacheFileSeparator, cacheFileNewline)
|
|
|
216
218
|
empty.push(elem);
|
|
217
219
|
});
|
|
218
220
|
|
|
219
|
-
const
|
|
220
|
-
.sort((a, b) => cacheLineToNum(a) - cacheLineToNum(b))
|
|
221
|
-
.filter((elem, i, arr) => {
|
|
222
|
-
for (const [j, line] of arr.entries()) {
|
|
223
|
-
if (
|
|
224
|
-
i !== j
|
|
225
|
-
&& line.split(cacheFileSeparator)[0] === elem.split(cacheFileSeparator)[0]
|
|
226
|
-
) {
|
|
227
|
-
different.add(elem);
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
221
|
+
const uniqSorted = [...new Set(dataArrRemoveEmpty)]
|
|
222
|
+
.sort((a, b) => cacheLineToNum(a) - cacheLineToNum(b));
|
|
231
223
|
|
|
232
|
-
|
|
233
|
-
|
|
224
|
+
getArrayDups(dataArrRemoveEmpty).forEach(dup => duplicates.add(dup));
|
|
225
|
+
const dupsIp = getArrayDups(uniqSorted.map(elem => elem.split(cacheFileSeparator)[0]));
|
|
226
|
+
|
|
227
|
+
const removeDiffs = uniqSorted.filter(elem => {
|
|
228
|
+
if (dupsIp.includes(elem.split(cacheFileSeparator)[0])) {
|
|
229
|
+
different.add(elem);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return true;
|
|
234
|
+
});
|
|
234
235
|
|
|
235
|
-
const fileContent =
|
|
236
|
+
const fileContent = removeDiffs.join(cacheFileNewline).trim();
|
|
236
237
|
|
|
237
238
|
if (fileContent) {
|
|
238
239
|
await fs.writeFile(fullFilePath, fileContent);
|
|
239
|
-
entries +=
|
|
240
|
+
entries += removeDiffs.length;
|
|
240
241
|
} else {
|
|
241
242
|
await fs.rm(fullFilePath);
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
dataArrRemoveEmpty
|
|
245
|
-
.forEach((elem, i, arr) => arr.indexOf(elem) !== i && duplicates.add(elem));
|
|
246
244
|
}));
|
|
247
245
|
|
|
248
246
|
return {
|