Skip to content

Commit 542285f

Browse files
committed
feat: enhance MihomoGeneratorService to support FlClashX compatibility
- Updated generateConfig method to accept an additional parameter for FlClashX detection. - Modified addProxy method to handle serverDescription for FlClashX compatibility.
1 parent afd44b7 commit 542285f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/modules/subscription-template/generators/mihomo.generator.service.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface ProxyNode {
4848
type: string;
4949
udp: boolean;
5050
uuid?: string;
51+
serverDescription?: string;
5152
}
5253

5354
@Injectable()
@@ -56,7 +57,11 @@ export class MihomoGeneratorService {
5657

5758
constructor(private readonly subscriptionTemplateService: SubscriptionTemplateService) {}
5859

59-
async generateConfig(hosts: IFormattedHost[], isStash = false): Promise<string> {
60+
async generateConfig(
61+
hosts: IFormattedHost[],
62+
isStash = false,
63+
isFlClashX = false,
64+
): Promise<string> {
6065
try {
6166
const data: ClashData = {
6267
proxies: [],
@@ -68,7 +73,7 @@ export class MihomoGeneratorService {
6873
if (!host) {
6974
continue;
7075
}
71-
this.addProxy(host, data, proxyRemarks);
76+
this.addProxy(host, data, proxyRemarks, isFlClashX);
7277
}
7378

7479
return await this.renderConfig(data, proxyRemarks, isStash);
@@ -181,7 +186,12 @@ export class MihomoGeneratorService {
181186
}
182187
}
183188

184-
private addProxy(host: IFormattedHost, data: ClashData, proxyRemarks: string[]): void {
189+
private addProxy(
190+
host: IFormattedHost,
191+
data: ClashData,
192+
proxyRemarks: string[],
193+
isFlClashX: boolean,
194+
): void {
185195
if (host.network === 'xhttp') {
186196
return;
187197
}
@@ -241,6 +251,11 @@ export class MihomoGeneratorService {
241251
return;
242252
}
243253

254+
if (host.serverDescription && isFlClashX) {
255+
// supported in FlClashX, custom field
256+
node.serverDescription = Buffer.from(host.serverDescription, 'base64').toString();
257+
}
258+
244259
data.proxies.push(node);
245260
proxyRemarks.push(proxyRemark);
246261
}

src/modules/subscription-template/render-templates.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ export class RenderTemplatesService {
144144
switch (clientType) {
145145
case 'MIHOMO':
146146
return {
147-
sub: await this.mihomoGeneratorService.generateConfig(formattedHosts, false),
147+
sub: await this.mihomoGeneratorService.generateConfig(
148+
formattedHosts,
149+
false,
150+
/^FlClashX\//.test(userAgent),
151+
),
148152
contentType: SUBSCRIPTION_CONFIG_TYPES.MIHOMO.CONTENT_TYPE,
149153
};
150154

0 commit comments

Comments
 (0)