Build reject hosts stats

This commit is contained in:
SukkaW 2023-07-24 20:56:43 +08:00
parent 814cb741e5
commit 2cec0789b1

View File

@ -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;
@ -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);
@ -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'));