mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Chore: drop reject stats generation
This commit is contained in:
parent
79c8e2ceef
commit
43085cc00e
@ -6,7 +6,7 @@ import { task } from './trace';
|
||||
import { treeDir, TreeFileType } from './lib/tree-dir';
|
||||
import type { TreeType, TreeTypeArray } from './lib/tree-dir';
|
||||
|
||||
import { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||
import { OUTPUT_MOCK_DIR, OUTPUT_MODULES_DIR, OUTPUT_MODULES_RULES_DIR, PUBLIC_DIR, ROOT_DIR } from './constants/dir';
|
||||
import { fastStringCompare, mkdirp, writeFile } from './lib/misc';
|
||||
import picocolors from 'picocolors';
|
||||
import { tagged as html } from 'foxts/tagged';
|
||||
@ -34,7 +34,8 @@ async function copyDirContents(srcDir: string, destDir: string) {
|
||||
export const buildPublic = task(require.main === module, __filename)(async (span) => {
|
||||
await span.traceChildAsync('copy rest of the files', async () => {
|
||||
await Promise.all([
|
||||
mkdirp(OUTPUT_MODULES_DIR),
|
||||
// mkdirp(OUTPUT_MODULES_DIR),
|
||||
mkdirp(OUTPUT_MODULES_RULES_DIR),
|
||||
mkdirp(OUTPUT_MOCK_DIR)
|
||||
]);
|
||||
|
||||
|
||||
@ -129,26 +129,9 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as
|
||||
}
|
||||
});
|
||||
|
||||
// Create reject stats
|
||||
const rejectDomainsStats: string[] = span
|
||||
.traceChild('create reject stats')
|
||||
.traceSyncFn(() => {
|
||||
const results = [];
|
||||
results.push('=== base ===');
|
||||
appendArrayInPlace(results, rejectOutput.getStatMap());
|
||||
results.push('=== extra ===');
|
||||
appendArrayInPlace(results, rejectExtraOutput.getStatMap());
|
||||
return results;
|
||||
});
|
||||
|
||||
return Promise.all([
|
||||
rejectOutput.write(),
|
||||
rejectExtraOutput.write(),
|
||||
compareAndWriteFile(
|
||||
span,
|
||||
rejectDomainsStats,
|
||||
path.join(OUTPUT_INTERNAL_DIR, 'reject-stats.txt')
|
||||
),
|
||||
compareAndWriteFile(
|
||||
span,
|
||||
appendArrayInPlace(
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
import { invariant } from 'foxts/guard';
|
||||
import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie';
|
||||
import { RuleOutput } from './base';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
|
||||
import * as tldts from 'tldts-experimental';
|
||||
import { looseTldtsOpt } from '../../constants/loose-tldts-opt';
|
||||
import { fastStringCompare } from '../misc';
|
||||
import { escapeStringRegexp } from 'foxts/escape-string-regexp';
|
||||
|
||||
export class DomainsetOutput extends RuleOutput<string[]> {
|
||||
@ -55,42 +51,6 @@ export class DomainsetOutput extends RuleOutput<string[]> {
|
||||
} satisfies SingboxSourceFormat);
|
||||
}
|
||||
|
||||
protected apexDomainMap: Map<string, string> | null = null;
|
||||
getStatMap() {
|
||||
this.runPreprocess();
|
||||
|
||||
invariant(this.$preprocessed, 'Non dumped yet');
|
||||
|
||||
if (!this.apexDomainMap) {
|
||||
const domainMap = new Map<string, string>();
|
||||
|
||||
for (let i = 0, len = this.$preprocessed.length; i < len; i++) {
|
||||
const cur = this.$preprocessed[i];
|
||||
if (!domainMap.has(cur)) {
|
||||
const domain = tldts.getDomain(cur, looseTldtsOpt);
|
||||
domainMap.set(cur, domain ?? cur);
|
||||
}
|
||||
}
|
||||
this.apexDomainMap = domainMap;
|
||||
}
|
||||
|
||||
return Array.from(this.$preprocessed
|
||||
.reduce<Map<string, number>>(
|
||||
(acc, cur) => {
|
||||
const suffix = this.apexDomainMap!.get(cur);
|
||||
if (suffix) {
|
||||
acc.set(suffix, (acc.get(suffix) ?? 0) + 1);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
new Map()
|
||||
)
|
||||
.entries())
|
||||
.filter(a => a[1] > 9)
|
||||
.sort((a, b) => (b[1] - a[1]) || fastStringCompare(a[0], b[0]))
|
||||
.map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`);
|
||||
}
|
||||
|
||||
mitmSgmodule = undefined;
|
||||
|
||||
adguardhome(): string[] {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user