Refactor: adjust more output

This commit is contained in:
SukkaW
2024-09-21 19:04:11 +08:00
parent 7c372b3b8c
commit eeeadbc86b
10 changed files with 131 additions and 133 deletions

View File

@@ -218,8 +218,12 @@ export abstract class RuleOutput {
abstract clash(): string[];
abstract singbox(): string[];
done() {
return this.pendingPromise;
}
async write(): Promise<void> {
await this.pendingPromise;
await this.done();
invariant(this.title, 'Missing title');
invariant(this.description, 'Missing description');

View File

@@ -76,15 +76,15 @@ export class DomainsetOutput extends RuleOutput {
invariant(this.apexDomainMap, 'Missing apex domain map');
return Array.from(
(
nullthrow(this.sorted, 'Non dumped yet').reduce<Map<string, number>>((acc, cur) => {
nullthrow(this.sorted, 'Non dumped yet')
.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()
.entries()
)
.filter(a => a[1] > 9)
.sort(

View File

@@ -12,7 +12,7 @@ export class RulesetOutput extends RuleOutput {
}
private $computed: [domain: string[], domainSuffix: string[], sortedDomainRules: string[]] | null = null;
private get computed() {
private computed() {
if (!this.$computed) {
const kwfilter = createKeywordFilter(this.domainKeywords);
@@ -40,7 +40,7 @@ export class RulesetOutput extends RuleOutput {
surge(): string[] {
const results: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
appendArrayInPlace(results, this.computed[2]);
appendArrayInPlace(results, this.computed()[2]);
appendArrayFromSet(results, this.domainKeywords, i => `DOMAIN-KEYWORD,${i}`);
appendArrayFromSet(results, this.domainWildcard, i => `DOMAIN-WILDCARD,${i}`);
@@ -70,7 +70,7 @@ export class RulesetOutput extends RuleOutput {
clash(): string[] {
const results: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
appendArrayInPlace(results, this.computed[2]);
appendArrayInPlace(results, this.computed()[2]);
appendArrayFromSet(results, this.domainKeywords, i => `DOMAIN-KEYWORD,${i}`);
appendArrayFromSet(results, this.domainWildcard, i => `DOMAIN-REGEX,${RuleOutput.domainWildCardToRegex(i)}`);
@@ -97,8 +97,8 @@ export class RulesetOutput extends RuleOutput {
const singbox: SingboxSourceFormat = {
version: 2,
rules: [{
domain: ['this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'].concat(this.computed[0]),
domain_suffix: this.computed[1],
domain: ['this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'].concat(this.computed()[0]),
domain_suffix: this.computed()[1],
domain_keyword: Array.from(this.domainKeywords),
domain_regex: Array.from(this.domainWildcard).map(RuleOutput.domainWildCardToRegex),
ip_cidr: appendArrayFromSet([], [this.ipcidr, this.ipcidrNoResolve, this.ipcidr6, this.ipcidr6NoResolve]),