Browse Source

Refactor: remove domain wildcard to regex fallback

This change will not affect widely used app like
Surge/Mihomo/QuanX/Shadowrocket, as they most likely already support
native `DOMAIN-WILDCARD`.
SukkaW 2 weeks ago
parent
commit
5e9a2cc605
2 changed files with 1 additions and 96 deletions
  1. 0 21
      Build/lib/writing-strategy/base.ts
  2. 1 75
      Build/lib/writing-strategy/singbox.ts

+ 0 - 21
Build/lib/writing-strategy/base.ts

@@ -46,27 +46,6 @@ export abstract class BaseWriteStrategy {
 
 
   protected abstract withPadding(title: string, description: string[] | readonly string[], date: Date, content: string[]): string[];
   protected abstract withPadding(title: string, description: string[] | readonly string[], date: Date, content: string[]): string[];
 
 
-  static readonly domainWildCardToRegex = (domain: string) => {
-    let result = '^';
-    for (let i = 0, len = domain.length; i < len; i++) {
-      switch (domain[i]) {
-        case '.':
-          result += String.raw`\.`;
-          break;
-        case '*':
-          result += String.raw`[\w.-]*?`;
-          break;
-        case '?':
-          result += String.raw`[\w.-]`;
-          break;
-        default:
-          result += domain[i];
-      }
-    }
-    result += '$';
-    return result;
-  };
-
   public output(
   public output(
     span: Span,
     span: Span,
     title: string,
     title: string,

+ 1 - 75
Build/lib/writing-strategy/singbox.ts

@@ -71,29 +71,10 @@ export class SingboxSource extends BaseWriteStrategy {
     );
     );
   }
   }
 
 
-  writeDomainWildcard(wildcard: string): void {
-    this.singbox.domain_regex ??= [];
-    this.singbox.domain_regex.push(SingboxSource.domainWildCardToRegex(wildcard));
-  }
-
+  writeDomainWildcard = noop;
   writeUserAgents = noop;
   writeUserAgents = noop;
-
   writeProcessNames = noop;
   writeProcessNames = noop;
-  // writeProcessNames(processName: Set<string>): void {
-  //   appendArrayInPlace(
-  //     this.singbox.process_name ??= [],
-  //     Array.from(processName)
-  //   );
-  // }
-
   writeProcessPaths = noop;
   writeProcessPaths = noop;
-  // writeProcessPaths(processPath: Set<string>): void {
-  //   appendArrayInPlace(
-  //     this.singbox.process_path ??= [],
-  //     Array.from(processPath)
-  //   );
-  // }
-
   writeUrlRegexes = noop;
   writeUrlRegexes = noop;
 
 
   writeIpCidrs(ipCidr: string[]): void {
   writeIpCidrs(ipCidr: string[]): void {
@@ -111,65 +92,10 @@ export class SingboxSource extends BaseWriteStrategy {
   }
   }
 
 
   writeGeoip = noop;
   writeGeoip = noop;
-
   writeIpAsns = noop;
   writeIpAsns = noop;
-
   writeSourceIpCidrs = noop;
   writeSourceIpCidrs = noop;
-  // writeSourceIpCidrs(sourceIpCidr: string[]): void {
-  //   this.singbox.source_ip_cidr ??= [];
-  //   for (let i = 0, len = sourceIpCidr.length; i < len; i++) {
-  //     const value = sourceIpCidr[i];
-  //     if (value.includes('/')) {
-  //       this.singbox.source_ip_cidr.push(value);
-  //       continue;
-  //     }
-  //     const v = fastIpVersion(value);
-  //     if (v === 4) {
-  //       this.singbox.source_ip_cidr.push(`${value}/32`);
-  //       continue;
-  //     }
-  //     if (v === 6) {
-  //       this.singbox.source_ip_cidr.push(`${value}/128`);
-  //       continue;
-  //     }
-  //   }
-  // }
-
   writeSourcePorts = noop;
   writeSourcePorts = noop;
-  // writeSourcePorts(port: Set<string>): void {
-  //   this.singbox.source_port ??= [];
-
-  //   for (const i of port) {
-  //     const tmp = Number(i);
-  //     if (!Number.isNaN(tmp)) {
-  //       this.singbox.source_port.push(tmp);
-  //     }
-  //   }
-  // }
-
   writeDestinationPorts = noop;
   writeDestinationPorts = noop;
-  // writeDestinationPorts(port: Set<string>): void {
-  //   this.singbox.port ??= [];
-
-  //   for (const i of port) {
-  //     const tmp = Number(i);
-  //     if (!Number.isNaN(tmp)) {
-  //       this.singbox.port.push(tmp);
-  //     }
-  //   }
-  // }
-
   writeProtocols = noop;
   writeProtocols = noop;
-  // writeProtocols(protocol: Set<string>): void {
-  //   this.singbox.network ??= [];
-  //   // protocol has already be normalized and will only be uppercase
-  //   if (protocol.has('UDP')) {
-  //     this.singbox.network.push('udp');
-  //   }
-  //   if (protocol.has('TCP')) {
-  //     this.singbox.network.push('tcp');
-  //   }
-  // }
-
   writeOtherRules = noop;
   writeOtherRules = noop;
 }
 }