Feat: legacy Clash Premium support

This commit is contained in:
SukkaW
2025-04-29 21:54:41 +08:00
parent 6453a5b025
commit 70c5625199
6 changed files with 27 additions and 5 deletions

View File

@@ -95,7 +95,7 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
return;
}
return span.traceChildAsync(`writing ${filePath}`, async () => {
return span.traceChildAsync<void>(`writing ${filePath}`, async () => {
const linesALen = linesA.length;
// The default highwater mark is normally 16384,

View File

@@ -29,7 +29,7 @@ interface Write {
(
destination: string,
input: NodeJS.TypedArray | string,
): Promise<unknown>
): Promise<void>
}
export function mkdirp(dir: string) {
@@ -39,7 +39,7 @@ export function mkdirp(dir: string) {
return fsp.mkdir(dir, { recursive: true });
}
export const writeFile: Write = async (destination: string, input, dir = dirname(destination)) => {
export const writeFile: Write = async (destination: string, input, dir = dirname(destination)): Promise<void> => {
const p = mkdirp(dir);
if (p) {
await p;

View File

@@ -1,5 +1,6 @@
import type { Span } from '../../trace';
import { ClashClassicRuleSet } from '../writing-strategy/clash';
import { LegacyClashPremiumRuleSet } from '../writing-strategy/legacy-clash-premium';
import { SingboxSource } from '../writing-strategy/singbox';
import { SurgeRuleSet } from '../writing-strategy/surge';
import { FileOutput } from './base';
@@ -11,6 +12,7 @@ export class RulesetOutput extends FileOutput {
this.strategies = [
new SurgeRuleSet(type),
new ClashClassicRuleSet(type),
new LegacyClashPremiumRuleSet(type),
new SingboxSource(type)
];
}
@@ -40,7 +42,8 @@ export class ClashOnlyRulesetOutput extends FileOutput {
super(span, id);
this.strategies = [
new ClashClassicRuleSet(type)
new ClashClassicRuleSet(type),
new LegacyClashPremiumRuleSet(type)
];
}
}

View File

@@ -84,7 +84,7 @@ export class ClashIPSet extends BaseWriteStrategy {
}
export class ClashClassicRuleSet extends BaseWriteStrategy {
public readonly name = 'clash classic ruleset';
public readonly name: string = 'clash classic ruleset';
readonly fileExtension = 'txt';

View File

@@ -0,0 +1,18 @@
import { noop } from 'foxts/noop';
import { OUTPUT_LEAGCY_CLASH_PREMIUM } from '../../constants/dir';
import { ClashClassicRuleSet } from './clash';
export class LegacyClashPremiumRuleSet extends ClashClassicRuleSet {
public override readonly name = 'legacy clash premium ruleset';
readonly fileExtension = 'txt';
protected result: string[] = ['DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'];
constructor(public readonly type: 'ip' | 'non_ip' /* | (string & {}) */, public readonly outputDir = OUTPUT_LEAGCY_CLASH_PREMIUM) {
super(type, outputDir);
}
override writeDomainWildcards = noop;
override writeIpAsns = noop;
}