Merge pull request #11 from norbertjoni/main

Check for duplicates before trim
This commit is contained in:
mrrfv
2023-06-29 13:44:51 +02:00
committed by GitHub
+11 -12
View File
@@ -72,17 +72,6 @@ fs.readFile('input.csv', 'utf8', async (err, data) => {
}).filter(domain => {
return domainValidationPattern.test(domain);
});
// Remove domains from the domains array that are present in the whitelist array
domains = domains.filter(domain => {
return !whitelist.includes(domain);
});
// Trim array to 300,000 domains if it's longer than that
if (domains.length > LIST_ITEM_LIMIT) {
domains = trimArray(domains, LIST_ITEM_LIMIT);
console.warn(`More than ${LIST_ITEM_LIMIT} domains found in input.csv - input has to be trimmed`);
}
// Check for duplicates in domains array
let uniqueDomains = [];
@@ -99,6 +88,17 @@ fs.readFile('input.csv', 'utf8', async (err, data) => {
// Replace domains array with uniqueDomains array
domains = uniqueDomains;
// Remove domains from the domains array that are present in the whitelist array
domains = domains.filter(domain => {
return !whitelist.includes(domain);
});
// Trim array to 300,000 domains if it's longer than that
if (domains.length > LIST_ITEM_LIMIT) {
domains = trimArray(domains, LIST_ITEM_LIMIT);
console.warn(`More than ${LIST_ITEM_LIMIT} domains found in input.csv - input has to be trimmed`);
}
const listsToCreate = Math.ceil(domains.length / 1000);
if (!process.env.CI) console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`);
@@ -175,4 +175,3 @@ function percentage(percent, total) {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}