@k03mad/ip2geo 10.0.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/helpers/cache.js +18 -18
- 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,31 @@ 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
|
+
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
234
|
|
|
235
|
-
const fileContent =
|
|
235
|
+
const fileContent = removeDiffs.join(cacheFileNewline).trim();
|
|
236
236
|
|
|
237
237
|
if (fileContent) {
|
|
238
238
|
await fs.writeFile(fullFilePath, fileContent);
|
|
239
|
-
entries +=
|
|
239
|
+
entries += removeDiffs.length;
|
|
240
240
|
} else {
|
|
241
241
|
await fs.rm(fullFilePath);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
dataArrRemoveEmpty
|
|
245
|
-
|
|
244
|
+
const dups = getArrayDups(dataArrRemoveEmpty);
|
|
245
|
+
dups.forEach(dup => duplicates.add(dup));
|
|
246
246
|
}));
|
|
247
247
|
|
|
248
248
|
return {
|