Skip to content

Commit

Permalink
Build reject hosts stats
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jul 24, 2023
1 parent 814cb74 commit 2cec078
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Build/build-reject-domainset.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ const domainSuffixSet = new Set();

console.time('* Write reject.conf');

/** @type {Record<string, number>} */
const rejectDomainsStats = {};

const sorter = (a, b) => {
if (a.domain > b.domain) {
return 1;
Expand All @@ -209,7 +212,9 @@ const domainSuffixSet = new Set();
};
const sortedDomainSets = dudupedDominArray
.map((v) => {
return { v, domain: getDomain(v.charCodeAt(0) === 46 ? v.slice(1) : v) || v };
const domain = getDomain(v.charCodeAt(0) === 46 ? v.slice(1) : v) || v;
rejectDomainsStats[domain] = (rejectDomainsStats[domain] || 0) + 1;
return { v, domain };
})
.sort(sorter)
.map((i) => i.v);
Expand All @@ -234,6 +239,14 @@ const domainSuffixSet = new Set();
pathResolve(__dirname, '../List/domainset/reject.conf')
);

await fs.promises.writeFile(
pathResolve(__dirname, '../List/internal/reject-stats.txt'),
Object.entries(rejectDomainsStats)
.sort((a, b) => b[1] - a[1])
.map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`)
.join('\n')
);

// Copy reject_sukka.conf for backward compatibility
await fse.copy(pathResolve(__dirname, '../Source/domainset/reject_sukka.conf'), pathResolve(__dirname, '../List/domainset/reject_sukka.conf'));

Expand Down

0 comments on commit 2cec078

Please sign in to comment.