sub-store-convert 2.21.25 → 2.21.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +429 -43
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -164,7 +164,7 @@ anytls = tag equals "anytls" address (passwordk/reuse/ip_version/underlying_prox
164
164
  proxy.tls = true;
165
165
  }
166
166
  trust_tunnel = tag equals "trust-tunnel" address (usernamek/passwordk/reuse/ip_version/underlying_proxy/tos/allow_other_interface/interface/test_url/test_udp/test_timeout/hybrid/no_error_alert/tls_fingerprint/tls_verification/sni/fast_open/tfo/block_quic/others)* {
167
- proxy.type = "trust-tunnel";
167
+ proxy.type = "trusttunnel";
168
168
  proxy.tls = true;
169
169
  }
170
170
 
@@ -355,7 +355,7 @@ var grammars2 = String.raw`
355
355
  }
356
356
  }
357
357
 
358
- start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2) {
358
+ start = (shadowsocksr/shadowsocks/vmess/vless/trojan/https/http/socks5/hysteria2/anytls) {
359
359
  return proxy;
360
360
  }
361
361
 
@@ -364,7 +364,7 @@ shadowsocksr = tag equals "shadowsocksr"i address method password (ssr_protocol/
364
364
  // handle ssr obfs
365
365
  proxy.obfs = obfs.type;
366
366
  }
367
- shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs_hostv)? (obfs_ss/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/others)* {
367
+ shadowsocks = tag equals "shadowsocks"i address method password (obfs_typev obfs_hostv)? (obfs_ss/obfs_host/obfs_uri/fast_open/udp_relay/udp_port/shadow_tls_version/shadow_tls_sni/shadow_tls_password/ip_mode/block_quic/udp_over_tcp/others)* {
368
368
  proxy.type = "ss";
369
369
  // handle ss obfs
370
370
  if (obfs.type == "http" || obfs.type === "tls") {
@@ -388,6 +388,10 @@ trojan = tag equals "trojan"i address password (transport/transport_host/transpo
388
388
  proxy.type = "trojan";
389
389
  handleTransport();
390
390
  }
391
+ anytls = tag equals "anytls"i address password (transport/transport_host/transport_path/over_tls/tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/fast_open/udp_relay/ip_mode/block_quic/idle_session_check_interval/idle_session_timeout/min_idle_session/max_stream_count/others)* {
392
+ proxy.type = "anytls";
393
+ handleTransport();
394
+ }
391
395
  hysteria2 = tag equals "hysteria2"i address password (tls_name/sni/tls_verification/tls_cert_sha256/tls_pubkey_sha256/udp_relay/fast_open/download_bandwidth/salamander_password/ecn/ip_mode/block_quic/others)* {
392
396
  proxy.type = "hysteria2";
393
397
  }
@@ -515,6 +519,13 @@ salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['ob
515
519
 
516
520
  block_quic = comma "block-quic" equals flag:bool { if(flag) proxy["block-quic"] = "on"; else proxy["block-quic"] = "off"; }
517
521
 
522
+ idle_session_check_interval = comma "idle-session-check-interval" equals match:$[0-9]+ { proxy["idle-session-check-interval"] = parseInt(match.trim()); }
523
+ idle_session_timeout = comma "idle-session-timeout" equals match:$[0-9]+ { proxy["idle-session-timeout"] = parseInt(match.trim()); }
524
+ min_idle_session = comma "min-idle-session" equals match:$[0-9]+ { proxy["min-idle-session"] = parseInt(match.trim()); }
525
+ max_stream_count = comma "max-stream-count" equals match:$[0-9]+ { proxy["max-stream-count"] = parseInt(match.trim()); }
526
+
527
+ udp_over_tcp = comma "udp-over-tcp" equals flag:bool { proxy["udp-over-tcp"] = true; proxy["udp-over-tcp-version"] = 2; }
528
+
518
529
  tag = match:[^=,]* { proxy.name = match.join("").trim(); }
519
530
  comma = _ "," _
520
531
  equals = _ "=" _
@@ -1209,7 +1220,7 @@ function URI_SS() {
1209
1220
  proxy.plugin = "v2ray-plugin";
1210
1221
  proxy["plugin-opts"] = {
1211
1222
  mode: "websocket",
1212
- host: getIfNotBlank(params2["obfs-host"]),
1223
+ host: getIfNotBlank(params2["obfs-host"]) || getIfNotBlank(params2["host"]),
1213
1224
  path: getIfNotBlank(params2.path),
1214
1225
  tls: getIfPresent(params2.tls)
1215
1226
  };
@@ -2024,7 +2035,7 @@ function Clash_All() {
2024
2035
  proxy = yaml_default.parse(line);
2025
2036
  }
2026
2037
  if (![
2027
- "trust-tunnel",
2038
+ "trusttunnel",
2028
2039
  "naive",
2029
2040
  "anytls",
2030
2041
  "mieru",
@@ -2050,7 +2061,7 @@ function Clash_All() {
2050
2061
  `Clash does not support proxy with type: ${proxy.type}`
2051
2062
  );
2052
2063
  }
2053
- if (["vmess", "vless"].includes(proxy.type)) {
2064
+ if (["vmess", "vless"].includes(proxy.type) && proxy.servername) {
2054
2065
  proxy.sni = proxy.servername;
2055
2066
  delete proxy.servername;
2056
2067
  }
@@ -2172,6 +2183,14 @@ function Loon_Trojan() {
2172
2183
  const parse = (line) => getParser2().parse(line);
2173
2184
  return { name, test, parse };
2174
2185
  }
2186
+ function Loon_AnyTLS() {
2187
+ const name = "Loon AnyTLS Parser";
2188
+ const test = (line) => {
2189
+ return /^.*=\s*anytls/i.test(line.split(",")[0]);
2190
+ };
2191
+ const parse = (line) => getParser2().parse(line);
2192
+ return { name, test, parse };
2193
+ }
2175
2194
  function Loon_Hysteria2() {
2176
2195
  const name = "Loon Hysteria2 Parser";
2177
2196
  const test = (line) => {
@@ -2304,8 +2323,8 @@ function Surge_Direct() {
2304
2323
  const parse = (line) => getParser().parse(line);
2305
2324
  return { name, test, parse };
2306
2325
  }
2307
- function Surge_Anytls() {
2308
- const name = "Surge Anytls Parser";
2326
+ function Surge_AnyTLS() {
2327
+ const name = "Surge AnyTLS Parser";
2309
2328
  const test = (line) => {
2310
2329
  return /^.*=\s*anytls/.test(line.split(",")[0]);
2311
2330
  };
@@ -2488,7 +2507,7 @@ var parsers_default = [
2488
2507
  URI_AnyTLS(),
2489
2508
  Clash_All(),
2490
2509
  Surge_Direct(),
2491
- Surge_Anytls(),
2510
+ Surge_AnyTLS(),
2492
2511
  Surge_TrustTunnel(),
2493
2512
  Surge_SSH(),
2494
2513
  Surge_SS(),
@@ -2507,6 +2526,7 @@ var parsers_default = [
2507
2526
  Loon_Vless(),
2508
2527
  Loon_Hysteria2(),
2509
2528
  Loon_Trojan(),
2529
+ Loon_AnyTLS(),
2510
2530
  Loon_Http(),
2511
2531
  Loon_Socks5(),
2512
2532
  Loon_WireGuard(),
@@ -2601,8 +2621,8 @@ function Surge_Producer() {
2601
2621
  }
2602
2622
  return anytls(proxy);
2603
2623
  }
2604
- if (opts["include-unsupported-proxy"] && proxy.type === "trust-tunnel") {
2605
- return trust_tunnel(proxy);
2624
+ if (opts["include-unsupported-proxy"] && proxy.type === "trusttunnel") {
2625
+ return trusttunnel(proxy);
2606
2626
  }
2607
2627
  throw new Error(
2608
2628
  `Platform ${targetPlatform} does not support proxy type: ${proxy.type}`
@@ -2835,9 +2855,10 @@ function anytls(proxy) {
2835
2855
  result.appendIfPresent(`,reuse=${proxy["reuse"]}`, "reuse");
2836
2856
  return result.toString();
2837
2857
  }
2838
- function trust_tunnel(proxy) {
2858
+ function trusttunnel(proxy) {
2839
2859
  const result = new Result(proxy);
2840
- result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
2860
+ result.append(`${proxy.name}=trust-tunnel,${proxy.server},${proxy.port}`);
2861
+ result.appendIfPresent(`,username="${proxy.username}"`, "username");
2841
2862
  result.appendIfPresent(`,password="${proxy.password}"`, "password");
2842
2863
  const ip_version = ipVersions[proxy["ip-version"]] || proxy["ip-version"];
2843
2864
  result.appendIfPresent(`,ip-version=${ip_version}`, "ip-version");
@@ -3568,7 +3589,7 @@ function ClashMeta_Producer() {
3568
3589
  if (opts["include-unsupported-proxy"]) return true;
3569
3590
  if (proxy.type === "snell" && proxy.version >= 4) {
3570
3591
  return false;
3571
- } else if (["trust-tunnel", "juicity", "naive"].includes(proxy.type)) {
3592
+ } else if (["juicity", "naive"].includes(proxy.type)) {
3572
3593
  return false;
3573
3594
  } else if (["ss"].includes(proxy.type) && ![
3574
3595
  "aes-128-ctr",
@@ -3732,7 +3753,7 @@ function ClashMeta_Producer() {
3732
3753
  "hysteria2",
3733
3754
  "juicity",
3734
3755
  "anytls",
3735
- "trust-tunnel",
3756
+ "trusttunnel",
3736
3757
  "naive"
3737
3758
  ].includes(proxy.type)) {
3738
3759
  delete proxy.tls;
@@ -4027,7 +4048,7 @@ function Clash_Producer() {
4027
4048
  "hysteria2",
4028
4049
  "juicity",
4029
4050
  "anytls",
4030
- "trust-tunnel",
4051
+ "trusttunnel",
4031
4052
  "naive"
4032
4053
  ].includes(proxy.type)) {
4033
4054
  delete proxy.tls;
@@ -4102,8 +4123,6 @@ function Stash_Producer() {
4102
4123
  "2022-blake3-aes-256-gcm"
4103
4124
  ].includes(proxy.cipher) || proxy.type === "snell" && proxy.version >= 4 || proxy.type === "vless" && proxy["reality-opts"] && !["xtls-rprx-vision"].includes(proxy.flow)) {
4104
4125
  return false;
4105
- } else if (["anytls"].includes(proxy.type) && !opts["include-unsupported-proxy"]) {
4106
- return false;
4107
4126
  } else if (["anytls"].includes(proxy.type) && proxy.network && (!["tcp"].includes(proxy.network) || ["tcp"].includes(proxy.network) && proxy["reality-opts"])) {
4108
4127
  return false;
4109
4128
  } else if (["xhttp"].includes(proxy.network)) {
@@ -4258,7 +4277,7 @@ function Stash_Producer() {
4258
4277
  "hysteria2",
4259
4278
  "juicity",
4260
4279
  "anytls",
4261
- "trust-tunnel",
4280
+ "trusttunnel",
4262
4281
  "naive"
4263
4282
  ].includes(proxy.type)) {
4264
4283
  delete proxy.tls;
@@ -4267,6 +4286,10 @@ function Stash_Producer() {
4267
4286
  proxy["server-cert-fingerprint"] = proxy["tls-fingerprint"];
4268
4287
  }
4269
4288
  delete proxy["tls-fingerprint"];
4289
+ if (proxy["underlying-proxy"]) {
4290
+ proxy["dialer-proxy"] = proxy["underlying-proxy"];
4291
+ }
4292
+ delete proxy["underlying-proxy"];
4270
4293
  if (isPresent2(proxy, "tls") && typeof proxy.tls !== "boolean") {
4271
4294
  delete proxy.tls;
4272
4295
  }
@@ -4324,6 +4347,8 @@ function Loon_Producer() {
4324
4347
  return shadowsocksr(proxy);
4325
4348
  case "trojan":
4326
4349
  return trojan2(proxy);
4350
+ case "anytls":
4351
+ return anytls2(proxy);
4327
4352
  case "vmess":
4328
4353
  return vmess2(proxy, opts["include-unsupported-proxy"]);
4329
4354
  case "vless":
@@ -4428,6 +4453,21 @@ function shadowsocks2(proxy) {
4428
4453
  );
4429
4454
  }
4430
4455
  }
4456
+ if (proxy["udp-over-tcp"]) {
4457
+ if (proxy["udp-over-tcp-version"] === 2) {
4458
+ if (proxy.plugin === "obfs") {
4459
+ app_default.error(
4460
+ `Platform ${targetPlatform3} shadowsocks udp-over-tcp does not support obfs`
4461
+ );
4462
+ } else {
4463
+ result.append(`,udp-over-tcp=true`);
4464
+ }
4465
+ } else {
4466
+ app_default.error(
4467
+ `Platform ${targetPlatform3} shadowsocks only supports udp-over-tcp-version 2`
4468
+ );
4469
+ }
4470
+ }
4431
4471
  result.appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
4432
4472
  if (proxy["block-quic"] === "on") {
4433
4473
  result.append(",block-quic=true");
@@ -4549,6 +4589,47 @@ function trojan2(proxy) {
4549
4589
  result.appendIfPresent(`,ip-mode=${ip_version}`, "ip-version");
4550
4590
  return result.toString();
4551
4591
  }
4592
+ function anytls2(proxy) {
4593
+ const result = new Result(proxy);
4594
+ result.append(
4595
+ `${proxy.name}=anytls,${proxy.server},${proxy.port},"${proxy.password}"`
4596
+ );
4597
+ for (const key of [
4598
+ // 'idle-session-check-interval',
4599
+ "idle-session-timeout",
4600
+ // 'min-idle-session',
4601
+ "max-stream-count"
4602
+ ]) {
4603
+ if (isPresent2(proxy, key) && Number.isInteger(proxy[key])) {
4604
+ result.append(`,${key}=${proxy[key]}`);
4605
+ }
4606
+ }
4607
+ result.appendIfPresent(
4608
+ `,skip-cert-verify=${proxy["skip-cert-verify"]}`,
4609
+ "skip-cert-verify"
4610
+ );
4611
+ result.appendIfPresent(`,tls-name=${proxy.sni}`, "sni");
4612
+ result.appendIfPresent(
4613
+ `,tls-cert-sha256=${proxy["tls-fingerprint"]}`,
4614
+ "tls-fingerprint"
4615
+ );
4616
+ result.appendIfPresent(
4617
+ `,tls-pubkey-sha256=${proxy["tls-pubkey-sha256"]}`,
4618
+ "tls-pubkey-sha256"
4619
+ );
4620
+ result.appendIfPresent(`,fast-open=${proxy.tfo}`, "tfo");
4621
+ if (proxy["block-quic"] === "on") {
4622
+ result.append(",block-quic=true");
4623
+ } else if (proxy["block-quic"] === "off") {
4624
+ result.append(",block-quic=false");
4625
+ }
4626
+ if (proxy.udp) {
4627
+ result.append(`,udp=true`);
4628
+ }
4629
+ const ip_version = ipVersions3[proxy["ip-version"]] || proxy["ip-version"];
4630
+ result.appendIfPresent(`,ip-mode=${ip_version}`, "ip-version");
4631
+ return result.toString();
4632
+ }
4552
4633
  function vmess2(proxy) {
4553
4634
  const isReality = !!proxy["reality-opts"];
4554
4635
  const result = new Result(proxy);
@@ -5004,13 +5085,11 @@ function URI_Producer() {
5004
5085
  }
5005
5086
  }
5006
5087
  if ([
5007
- "trojan",
5008
5088
  "tuic",
5009
5089
  "hysteria",
5010
5090
  "hysteria2",
5011
5091
  "juicity",
5012
- "anytls",
5013
- "trust-tunnel"
5092
+ "trusttunnel"
5014
5093
  ].includes(proxy.type)) {
5015
5094
  delete proxy.tls;
5016
5095
  }
@@ -5042,7 +5121,7 @@ function URI_Producer() {
5042
5121
  break;
5043
5122
  case "v2ray-plugin":
5044
5123
  query += encodeURIComponent(
5045
- `v2ray-plugin;obfs=${opts.mode}${opts.host ? ";obfs-host" + opts.host : ""}${opts.tls ? ";tls" : ""}`
5124
+ `v2ray-plugin;obfs=${opts.mode}${opts.host ? ";obfs-host=" + opts.host : ""}${opts.host ? ";host=" + opts.host : ""}${opts.path ? ";path=" + opts.path : ""}${opts.tls ? ";tls" : ""}`
5046
5125
  );
5047
5126
  break;
5048
5127
  case "shadow-tls":
@@ -6057,7 +6136,7 @@ function Shadowrocket_Producer() {
6057
6136
  if (proxy.type === "snell" && proxy.version >= 4) {
6058
6137
  return false;
6059
6138
  } else if ([
6060
- "trust-tunnel",
6139
+ "trusttunnel",
6061
6140
  "mieru",
6062
6141
  "sudoku",
6063
6142
  "naive",
@@ -6195,7 +6274,7 @@ function Shadowrocket_Producer() {
6195
6274
  "hysteria2",
6196
6275
  "juicity",
6197
6276
  "anytls",
6198
- "trust-tunnel",
6277
+ "trusttunnel",
6199
6278
  "naive"
6200
6279
  ].includes(proxy.type)) {
6201
6280
  delete proxy.tls;
@@ -6255,10 +6334,12 @@ function Surfboard_Producer() {
6255
6334
  return vmess4(proxy);
6256
6335
  case "http":
6257
6336
  return http4(proxy);
6337
+ case "snell":
6338
+ return snell2(proxy);
6258
6339
  case "socks5":
6259
6340
  return socks54(proxy);
6260
6341
  case "anytls":
6261
- return anytls2(proxy);
6342
+ return anytls3(proxy);
6262
6343
  case "wireguard-surge":
6263
6344
  return wireguard3(proxy);
6264
6345
  }
@@ -6268,7 +6349,7 @@ function Surfboard_Producer() {
6268
6349
  };
6269
6350
  return { produce: produce2 };
6270
6351
  }
6271
- function anytls2(proxy) {
6352
+ function anytls3(proxy) {
6272
6353
  const result = new Result(proxy);
6273
6354
  result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
6274
6355
  result.appendIfPresent(`,password="${proxy.password}"`, "password");
@@ -6282,6 +6363,34 @@ function anytls2(proxy) {
6282
6363
  result.appendIfPresent(`,reuse=${proxy["reuse"]}`, "reuse");
6283
6364
  return result.toString();
6284
6365
  }
6366
+ function snell2(proxy) {
6367
+ if (proxy.version > 3) {
6368
+ throw new Error(
6369
+ `Platform ${targetPlatform5} does not support snell version ${proxy.version}`
6370
+ );
6371
+ }
6372
+ const result = new Result(proxy);
6373
+ result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
6374
+ result.appendIfPresent(`,version=${proxy.version}`, "version");
6375
+ result.appendIfPresent(`,psk=${proxy.psk}`, "psk");
6376
+ result.appendIfPresent(
6377
+ `,obfs=${proxy["obfs-opts"]?.mode}`,
6378
+ "obfs-opts.mode"
6379
+ );
6380
+ result.appendIfPresent(
6381
+ `,obfs-host=${proxy["obfs-opts"]?.host}`,
6382
+ "obfs-opts.host"
6383
+ );
6384
+ result.appendIfPresent(
6385
+ `,obfs-uri=${proxy["obfs-opts"]?.path}`,
6386
+ "obfs-opts.path"
6387
+ );
6388
+ result.appendIfPresent(`,tfo=${proxy.tfo}`, "tfo");
6389
+ if (proxy.version >= 3) {
6390
+ result.appendIfPresent(`,udp-relay=${proxy.udp}`, "udp");
6391
+ }
6392
+ return result.toString();
6393
+ }
6285
6394
  function shadowsocks4(proxy) {
6286
6395
  const result = new Result(proxy);
6287
6396
  result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
@@ -7381,7 +7490,7 @@ function singbox_Producer() {
7381
7490
  // src/vendors/Sub-Store/backend/src/core/proxy-utils/producers/egern.js
7382
7491
  function Egern_Producer() {
7383
7492
  const type = "ALL";
7384
- const produce2 = (proxies, type2, opts = {}) => {
7493
+ const produce2 = (proxies, type2) => {
7385
7494
  const list = proxies.filter((proxy) => {
7386
7495
  if (![
7387
7496
  "http",
@@ -7393,10 +7502,8 @@ function Egern_Producer() {
7393
7502
  "vless",
7394
7503
  "vmess",
7395
7504
  "tuic",
7396
- "wireguard"
7397
- // ...(opts['include-unsupported-proxy']
7398
- // ? ['wireguard']
7399
- // : []),
7505
+ "wireguard",
7506
+ "anytls"
7400
7507
  ].includes(proxy.type) || proxy.type === "ss" && (proxy.plugin === "obfs" && !["http", "tls"].includes(
7401
7508
  proxy["plugin-opts"]?.mode
7402
7509
  ) || ![
@@ -7428,7 +7535,11 @@ function Egern_Producer() {
7428
7535
  "chacha20-ietf",
7429
7536
  "2022-blake3-aes-128-gcm",
7430
7537
  "2022-blake3-aes-256-gcm"
7431
- ].includes(proxy.cipher)) || proxy.type === "vmess" && !["http", "ws", "tcp"].includes(proxy.network) && proxy.network || proxy.type === "trojan" && !["http", "ws", "tcp"].includes(proxy.network) && proxy.network || proxy.type === "vless" && !["http", "ws", "tcp"].includes(proxy.network) && proxy.network || proxy.type === "tuic" && proxy.token && proxy.token.length !== 0) {
7538
+ ].includes(proxy.cipher)) || proxy.type === "vmess" && !["http", "ws", "tcp"].includes(proxy.network) && proxy.network || proxy.type === "trojan" && !["http", "ws", "tcp"].includes(proxy.network) && proxy.network || proxy.type === "vless" && (!["http", "ws", "tcp"].includes(proxy.network) && proxy.network || typeof proxy.flow !== "undefined" && !["xtls-rprx-vision", ""].includes(
7539
+ proxy.flow
7540
+ )) || proxy.type === "tuic" && proxy.token && proxy.token.length !== 0) {
7541
+ return false;
7542
+ } else if (["anytls"].includes(proxy.type) && proxy.network && (!["tcp"].includes(proxy.network) || ["tcp"].includes(proxy.network) && proxy["reality-opts"])) {
7432
7543
  return false;
7433
7544
  } else if (["ws"].includes(proxy.network) && proxy["ws-opts"]?.["v2ray-http-upgrade"]) {
7434
7545
  return false;
@@ -7539,6 +7650,19 @@ function Egern_Producer() {
7539
7650
  skip_tls_verify: proxy["skip-cert-verify"],
7540
7651
  websocket: proxy.websocket
7541
7652
  };
7653
+ } else if (proxy.type === "anytls") {
7654
+ proxy = {
7655
+ type: "anytls",
7656
+ name: proxy.name,
7657
+ server: proxy.server,
7658
+ port: proxy.port,
7659
+ password: proxy.password,
7660
+ tfo: proxy.tfo || proxy["fast-open"],
7661
+ udp_relay: proxy.udp || proxy.udp_relay || proxy.udp_relay,
7662
+ next_hop: proxy.next_hop,
7663
+ sni: proxy.sni,
7664
+ skip_tls_verify: proxy["skip-cert-verify"]
7665
+ };
7542
7666
  } else if (proxy.type === "vmess") {
7543
7667
  let security = proxy.cipher;
7544
7668
  if (security && ![
@@ -7658,14 +7782,8 @@ function Egern_Producer() {
7658
7782
  reality
7659
7783
  }
7660
7784
  };
7661
- if (typeof proxy.flow !== "undefined") {
7662
- if (!["xtls-rprx-vision"].includes(proxy.flow)) {
7663
- throw new Error(
7664
- `VLESS flow(${proxy.flow}) is not supported`
7665
- );
7666
- }
7667
- }
7668
7785
  flow = proxy.flow;
7786
+ if (flow === "") flow = void 0;
7669
7787
  }
7670
7788
  proxy = {
7671
7789
  type: "vless",
@@ -7716,7 +7834,8 @@ function Egern_Producer() {
7716
7834
  "ss",
7717
7835
  "trojan",
7718
7836
  "vless",
7719
- "vmess"
7837
+ "vmess",
7838
+ "anytls"
7720
7839
  ].includes(original.type)) {
7721
7840
  if (isPresent2(original, "shadow-tls-password")) {
7722
7841
  if (original["shadow-tls-version"] != 3)
@@ -7746,7 +7865,8 @@ function Egern_Producer() {
7746
7865
  "vmess",
7747
7866
  "wireguard",
7748
7867
  "tuic",
7749
- "hysteria2"
7868
+ "hysteria2",
7869
+ "anytls"
7750
7870
  ].includes(original.type)) {
7751
7871
  if (["on", "true", true, "1", 1].includes(
7752
7872
  original["block-quic"]
@@ -7840,10 +7960,276 @@ var producers_default = {
7840
7960
  Egern: Egern_Producer()
7841
7961
  };
7842
7962
 
7963
+ // src/vendors/Sub-Store/backend/src/core/proxy-utils/preprocessors/index.js
7964
+ import { Base64 as Base645 } from "js-base64";
7965
+ function HTML() {
7966
+ const name = "HTML";
7967
+ const test = (raw) => /^<!DOCTYPE html>/.test(raw);
7968
+ const parse = () => "";
7969
+ return { name, test, parse };
7970
+ }
7971
+ function Base64Encoded() {
7972
+ const name = "Base64 Pre-processor";
7973
+ const keys = [
7974
+ "dm1lc3M",
7975
+ // vmess
7976
+ "c3NyOi8v",
7977
+ // ssr://
7978
+ "c29ja3M6Ly",
7979
+ // socks://
7980
+ "dHJvamFu",
7981
+ // trojan
7982
+ "c3M6Ly",
7983
+ // ss:/
7984
+ "c3NkOi8v",
7985
+ // ssd://
7986
+ "c2hhZG93",
7987
+ // shadow
7988
+ "aHR0c",
7989
+ // htt
7990
+ "dmxlc3M=",
7991
+ // vless
7992
+ "aHlzdGVyaWEy",
7993
+ // hysteria2
7994
+ "aHkyOi8v",
7995
+ // hy2://
7996
+ "d2lyZWd1YXJkOi8v",
7997
+ // wireguard://
7998
+ "d2c6Ly8=",
7999
+ // wg://
8000
+ "dHVpYzovLw=="
8001
+ // tuic://
8002
+ ];
8003
+ const test = function(raw) {
8004
+ return !/^\w+:\/\/\w+/im.test(raw) && keys.some((k) => raw.indexOf(k) !== -1);
8005
+ };
8006
+ const parse = function(raw) {
8007
+ const decoded = Base645.decode(raw);
8008
+ if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
8009
+ app_default.error(
8010
+ `Base64 Pre-processor error: decoded line does not start with protocol`
8011
+ );
8012
+ return raw;
8013
+ }
8014
+ return decoded;
8015
+ };
8016
+ return { name, test, parse };
8017
+ }
8018
+ function fallbackBase64Encoded() {
8019
+ const name = "Fallback Base64 Pre-processor";
8020
+ const test = function(raw) {
8021
+ return true;
8022
+ };
8023
+ const parse = function(raw) {
8024
+ const decoded = Base645.decode(raw);
8025
+ if (!/^\w+(:\/\/|\s*?=\s*?)\w+/m.test(decoded)) {
8026
+ app_default.error(
8027
+ `Fallback Base64 Pre-processor error: decoded line does not start with protocol`
8028
+ );
8029
+ return raw;
8030
+ }
8031
+ return decoded;
8032
+ };
8033
+ return { name, test, parse };
8034
+ }
8035
+ function Clash() {
8036
+ const name = "Clash Pre-processor";
8037
+ const test = function(raw) {
8038
+ if (!/proxies/.test(raw)) return false;
8039
+ const content = safeLoad(raw);
8040
+ return content.proxies && Array.isArray(content.proxies);
8041
+ };
8042
+ const parse = function(raw, includeProxies) {
8043
+ const afterReplace = raw.replace(
8044
+ /short-id:([ \t]*[^#\n,}]*)/g,
8045
+ (matched, value) => {
8046
+ const afterTrim = value.trim();
8047
+ if (!afterTrim || afterTrim === "") {
8048
+ return 'short-id: ""';
8049
+ }
8050
+ if (/^(['"]).*\1$/.test(afterTrim)) {
8051
+ return `short-id: ${afterTrim}`;
8052
+ } else if (["null"].includes(afterTrim)) {
8053
+ return `short-id: ${afterTrim}`;
8054
+ } else {
8055
+ return `short-id: "${afterTrim}"`;
8056
+ }
8057
+ }
8058
+ );
8059
+ const {
8060
+ proxies,
8061
+ "global-client-fingerprint": globalClientFingerprint
8062
+ } = safeLoad(afterReplace);
8063
+ return (includeProxies ? "proxies:\n" : "") + proxies.map((p) => {
8064
+ if (globalClientFingerprint && ["trojan", "vmess", "vless"].includes(p.type) && !p["client-fingerprint"]) {
8065
+ p["client-fingerprint"] = globalClientFingerprint;
8066
+ }
8067
+ return `${includeProxies ? " - " : ""}${JSON.stringify(
8068
+ p
8069
+ )}
8070
+ `;
8071
+ }).join("");
8072
+ };
8073
+ return { name, test, parse };
8074
+ }
8075
+ function SSD() {
8076
+ const name = "SSD Pre-processor";
8077
+ const test = function(raw) {
8078
+ return raw.indexOf("ssd://") === 0;
8079
+ };
8080
+ const parse = function(raw) {
8081
+ const output = [];
8082
+ let ssdinfo = JSON.parse(Base645.decode(raw.split("ssd://")[1]));
8083
+ let port = ssdinfo.port;
8084
+ let method = ssdinfo.encryption;
8085
+ let password = ssdinfo.password;
8086
+ let servers = ssdinfo.servers;
8087
+ for (let i = 0; i < servers.length; i++) {
8088
+ let server = servers[i];
8089
+ method = server.encryption ? server.encryption : method;
8090
+ password = server.password ? server.password : password;
8091
+ let userinfo = Base645.encode(method + ":" + password);
8092
+ let hostname = server.server;
8093
+ port = server.port ? server.port : port;
8094
+ let tag = server.remarks ? server.remarks : i;
8095
+ let plugin = server.plugin_options ? "/?plugin=" + encodeURIComponent(
8096
+ server.plugin + ";" + server.plugin_options
8097
+ ) : "";
8098
+ output[i] = "ss://" + userinfo + "@" + hostname + ":" + port + plugin + "#" + tag;
8099
+ }
8100
+ return output.join("\n");
8101
+ };
8102
+ return { name, test, parse };
8103
+ }
8104
+ function FullConfig() {
8105
+ const name = "Full Config Preprocessor";
8106
+ const test = function(raw) {
8107
+ return /^(\[server_local\]|\[Proxy\])/gm.test(raw);
8108
+ };
8109
+ const parse = function(raw) {
8110
+ const match = raw.match(
8111
+ /^\[server_local|Proxy\]([\s\S]+?)^\[.+?\](\r?\n|$)/im
8112
+ )?.[1];
8113
+ return match || raw;
8114
+ };
8115
+ return { name, test, parse };
8116
+ }
8117
+ var preprocessors_default = [
8118
+ HTML(),
8119
+ Clash(),
8120
+ Base64Encoded(),
8121
+ SSD(),
8122
+ FullConfig(),
8123
+ fallbackBase64Encoded()
8124
+ ];
8125
+
7843
8126
  // src/index.js
7844
8127
  var parsers = parsers_default;
7845
8128
  var produce = producers_default;
8129
+ var preprocessors = preprocessors_default;
8130
+ function loadProducer(target) {
8131
+ const targetLower = target.toLowerCase();
8132
+ for (const key of Object.keys(produce)) {
8133
+ if (key.toLowerCase() === targetLower) {
8134
+ return produce[key];
8135
+ }
8136
+ }
8137
+ return null;
8138
+ }
8139
+ async function loadRemoteData(url) {
8140
+ try {
8141
+ const response = await fetch(url);
8142
+ const raw = await response.text();
8143
+ for (const preprocessor of preprocessors) {
8144
+ try {
8145
+ if (preprocessor.test(raw)) {
8146
+ return preprocessor.parse(raw).split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
8147
+ }
8148
+ } catch (error) {
8149
+ console.error("Preprocessor error:", error);
8150
+ }
8151
+ }
8152
+ return [];
8153
+ } catch (error) {
8154
+ console.error("Failed to load remote data:", error);
8155
+ return [];
8156
+ }
8157
+ }
8158
+ function tryParseProxy(parser5, line) {
8159
+ try {
8160
+ if (parser5.test(line)) {
8161
+ return parser5.parse(line);
8162
+ }
8163
+ } catch (error) {
8164
+ console.error("Parser test/parse error:", error);
8165
+ }
8166
+ return null;
8167
+ }
8168
+ function buildProxyServer(proxy, opts) {
8169
+ const server = { ...proxy, ...opts };
8170
+ if (server.name) {
8171
+ server.name = server.name.trim();
8172
+ }
8173
+ return server;
8174
+ }
8175
+ function parseProxyLines(lines, opts) {
8176
+ const proxyList = [];
8177
+ let lastParser = null;
8178
+ for (const line of lines) {
8179
+ if (line.length === 0) continue;
8180
+ let proxy = null;
8181
+ if (lastParser) {
8182
+ proxy = tryParseProxy(lastParser, line);
8183
+ if (proxy) {
8184
+ proxyList.push(buildProxyServer(proxy, opts));
8185
+ continue;
8186
+ }
8187
+ }
8188
+ for (const parser5 of parsers) {
8189
+ proxy = tryParseProxy(parser5, line);
8190
+ if (proxy) {
8191
+ proxyList.push(buildProxyServer(proxy, opts));
8192
+ lastParser = parser5;
8193
+ break;
8194
+ }
8195
+ }
8196
+ }
8197
+ return proxyList;
8198
+ }
8199
+ function produceOutput(producer, proxyList) {
8200
+ if (producer.type === "ALL") {
8201
+ return producer.produce(proxyList);
8202
+ }
8203
+ const results = [];
8204
+ for (const proxy of proxyList) {
8205
+ try {
8206
+ results.push(producer.produce(proxy, proxy.type));
8207
+ } catch (error) {
8208
+ console.error("Producer error:", error);
8209
+ }
8210
+ }
8211
+ return results.join("\n");
8212
+ }
8213
+ async function convert(url, target, opts = {}) {
8214
+ const producer = loadProducer(target);
8215
+ if (!producer) {
8216
+ throw new Error(`Unknown target: ${target}`);
8217
+ }
8218
+ const urls = url.split("|");
8219
+ const allLines = await Promise.all(urls.map(loadRemoteData));
8220
+ const lines = allLines.flat();
8221
+ const proxyList = parseProxyLines(lines, opts);
8222
+ return produceOutput(producer, proxyList);
8223
+ }
7846
8224
  export {
8225
+ buildProxyServer,
8226
+ convert,
8227
+ loadProducer,
8228
+ loadRemoteData,
8229
+ parseProxyLines,
7847
8230
  parsers,
7848
- produce
8231
+ preprocessors,
8232
+ produce,
8233
+ produceOutput,
8234
+ tryParseProxy
7849
8235
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sub-store-convert",
3
- "version": "2.21.25",
3
+ "version": "2.21.45",
4
4
  "description": "Advanced Subscription Converter for QX, Loon, Surge, Stash and ShadowRocket.",
5
5
  "type": "module",
6
6
  "module": "./index.js",