mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: adjust write strategy usage
This commit is contained in:
@@ -57,7 +57,7 @@ export class FileOutput {
|
||||
return this;
|
||||
}
|
||||
|
||||
replaceStrategies(strategies: Array<BaseWriteStrategy | false>) {
|
||||
public withStrategies(strategies: Array<BaseWriteStrategy | false>) {
|
||||
this.strategies = strategies;
|
||||
return this;
|
||||
}
|
||||
@@ -444,7 +444,7 @@ export class FileOutput {
|
||||
});
|
||||
}
|
||||
|
||||
async output(): Promise<Array<string[] | null>> {
|
||||
async compile(): Promise<Array<string[] | null>> {
|
||||
await this.writeToStrategies();
|
||||
|
||||
return this.strategies.reduce<Array<string[] | null>>((acc, strategy) => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { Span } from '../../trace';
|
||||
import { AdGuardHome } from '../writing-strategy/adguardhome';
|
||||
import type { BaseWriteStrategy } from '../writing-strategy/base';
|
||||
import { ClashDomainSet } from '../writing-strategy/clash';
|
||||
import { SingboxSource } from '../writing-strategy/singbox';
|
||||
@@ -13,3 +15,19 @@ export class DomainsetOutput extends FileOutput {
|
||||
new SingboxSource(this.type)
|
||||
];
|
||||
}
|
||||
|
||||
export class AdGuardHomeOutput extends FileOutput {
|
||||
strategies: Array<false | BaseWriteStrategy>;
|
||||
|
||||
constructor(
|
||||
span: Span,
|
||||
id: string,
|
||||
outputDir: string
|
||||
) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new AdGuardHome(outputDir)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,3 +15,32 @@ export class RulesetOutput extends FileOutput {
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export class SurgeOnlyRulesetOutput extends FileOutput {
|
||||
constructor(
|
||||
span: Span,
|
||||
id: string,
|
||||
protected type: 'non_ip' | 'ip' | (string & {}),
|
||||
overrideOutputDir?: string
|
||||
) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new SurgeRuleSet(this.type, overrideOutputDir)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export class ClashOnlyRulesetOutput extends FileOutput {
|
||||
constructor(
|
||||
span: Span,
|
||||
id: string,
|
||||
protected type: 'non_ip' | 'ip' | (string & {})
|
||||
) {
|
||||
super(span, id);
|
||||
|
||||
this.strategies = [
|
||||
new ClashClassicRuleSet(this.type)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user