mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Refactor: refine writing strategy
This commit is contained in:
@@ -8,7 +8,7 @@ import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
||||
import { readFileByLine } from '../fetch-text-by-line';
|
||||
import { asyncWriteToStream } from 'foxts/async-write-to-stream';
|
||||
import type { BaseWriteStrategy } from '../writing-strategy/base';
|
||||
import { merge } from 'fast-cidr-tools';
|
||||
import { merge as mergeCidr } from 'fast-cidr-tools';
|
||||
import { createRetrieKeywordFilter as createKeywordFilter } from 'foxts/retrie';
|
||||
import path from 'node:path';
|
||||
import { SurgeMitmSgmodule } from '../writing-strategy/surge';
|
||||
@@ -369,10 +369,10 @@ export class FileOutput {
|
||||
let ipcidr6NoResolve: string[] | null = null;
|
||||
|
||||
if (this.ipcidr.size) {
|
||||
ipcidr = merge(Array.from(this.ipcidr), true);
|
||||
ipcidr = mergeCidr(Array.from(this.ipcidr), true);
|
||||
}
|
||||
if (this.ipcidrNoResolve.size) {
|
||||
ipcidrNoResolve = merge(Array.from(this.ipcidrNoResolve), true);
|
||||
ipcidrNoResolve = mergeCidr(Array.from(this.ipcidrNoResolve), true);
|
||||
}
|
||||
if (this.ipcidr6.size) {
|
||||
ipcidr6 = Array.from(this.ipcidr6);
|
||||
@@ -433,9 +433,12 @@ export class FileOutput {
|
||||
this.title,
|
||||
this.description,
|
||||
this.date,
|
||||
strategy.type
|
||||
? path.join(strategy.type, basename)
|
||||
: basename
|
||||
path.join(
|
||||
strategy.outputDir,
|
||||
strategy.type
|
||||
? path.join(strategy.type, basename)
|
||||
: basename
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,10 @@ import { SurgeDomainSet } from '../writing-strategy/surge';
|
||||
import { FileOutput } from './base';
|
||||
|
||||
export class DomainsetOutput extends FileOutput {
|
||||
protected type = 'domainset' as const;
|
||||
|
||||
strategies: Array<false | BaseWriteStrategy> = [
|
||||
new SurgeDomainSet(),
|
||||
new ClashDomainSet(),
|
||||
new SingboxSource(this.type)
|
||||
new SingboxSource('domainset')
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,15 @@ import { SurgeRuleSet } from '../writing-strategy/surge';
|
||||
import { FileOutput } from './base';
|
||||
|
||||
export class IPListOutput extends FileOutput {
|
||||
protected type = 'ip' as const;
|
||||
strategies: Array<false | BaseWriteStrategy>;
|
||||
|
||||
constructor(span: Span, id: string, private readonly clashUseRule = true) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new SurgeRuleSet(this.type),
|
||||
this.clashUseRule ? new ClashClassicRuleSet(this.type) : new ClashIPSet(),
|
||||
new SingboxSource(this.type)
|
||||
new SurgeRuleSet('ip'),
|
||||
this.clashUseRule ? new ClashClassicRuleSet('ip') : new ClashIPSet(),
|
||||
new SingboxSource('ip')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import { SurgeRuleSet } from '../writing-strategy/surge';
|
||||
import { FileOutput } from './base';
|
||||
|
||||
export class RulesetOutput extends FileOutput {
|
||||
constructor(span: Span, id: string, protected type: 'non_ip' | 'ip' | (string & {})) {
|
||||
constructor(span: Span, id: string, type: 'non_ip' | 'ip') {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new SurgeRuleSet(this.type),
|
||||
new ClashClassicRuleSet(this.type),
|
||||
new SingboxSource(this.type)
|
||||
new SurgeRuleSet(type),
|
||||
new ClashClassicRuleSet(type),
|
||||
new SingboxSource(type)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,13 @@ export class SurgeOnlyRulesetOutput extends FileOutput {
|
||||
constructor(
|
||||
span: Span,
|
||||
id: string,
|
||||
protected type: 'non_ip' | 'ip' | (string & {}),
|
||||
type: 'non_ip' | 'ip' | (string & {}),
|
||||
overrideOutputDir?: string
|
||||
) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new SurgeRuleSet(this.type, overrideOutputDir)
|
||||
new SurgeRuleSet(type, overrideOutputDir)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,12 @@ export class ClashOnlyRulesetOutput extends FileOutput {
|
||||
constructor(
|
||||
span: Span,
|
||||
id: string,
|
||||
protected type: 'non_ip' | 'ip' | (string & {})
|
||||
type: 'non_ip' | 'ip'
|
||||
) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new ClashClassicRuleSet(this.type)
|
||||
new ClashClassicRuleSet(type)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user