cfpilot 0.15.7 → 0.15.9

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.
package/dist/cli.js CHANGED
@@ -87,7 +87,7 @@ var VERSION, NAME;
87
87
  var init_version = __esm({
88
88
  "src/shared/version.ts"() {
89
89
  "use strict";
90
- VERSION = "0.15.7";
90
+ VERSION = "0.15.9";
91
91
  NAME = "cfpilot";
92
92
  }
93
93
  });
@@ -1115,9 +1115,9 @@ var init_account_resolve = __esm({
1115
1115
  import { randomBytes } from "node:crypto";
1116
1116
  function randomAlnum(length) {
1117
1117
  const bytes = randomBytes(length);
1118
- let out = "";
1119
- for (const byte of bytes) out += ALPHABET[byte % ALPHABET.length];
1120
- return out;
1118
+ let out2 = "";
1119
+ for (const byte of bytes) out2 += ALPHABET[byte % ALPHABET.length];
1120
+ return out2;
1121
1121
  }
1122
1122
  function randomPassword() {
1123
1123
  return `cfp-${randomAlnum(14)}`;
@@ -1933,7 +1933,7 @@ async function readBodyWithLimit(response) {
1933
1933
  const reader = body.getReader();
1934
1934
  const decoder = new TextDecoder();
1935
1935
  let total = 0;
1936
- let out = "";
1936
+ let out2 = "";
1937
1937
  try {
1938
1938
  for (; ; ) {
1939
1939
  const { done, value } = await reader.read();
@@ -1945,27 +1945,27 @@ async function readBodyWithLimit(response) {
1945
1945
  await reader.cancel().catch(() => void 0);
1946
1946
  throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
1947
1947
  }
1948
- out += decoder.decode(chunk, { stream: true });
1948
+ out2 += decoder.decode(chunk, { stream: true });
1949
1949
  }
1950
1950
  } finally {
1951
1951
  reader.releaseLock();
1952
1952
  }
1953
- out += decoder.decode();
1954
- return out;
1953
+ out2 += decoder.decode();
1954
+ return out2;
1955
1955
  }
1956
1956
  function sha256Hex(content) {
1957
1957
  return createHash("sha256").update(content, "utf8").digest("hex");
1958
1958
  }
1959
1959
  function parseChecksums(text2) {
1960
- const out = /* @__PURE__ */ new Map();
1960
+ const out2 = /* @__PURE__ */ new Map();
1961
1961
  for (const raw of text2.split("\n")) {
1962
1962
  const line = raw.trim();
1963
1963
  if (!line || line.startsWith("#")) continue;
1964
1964
  const match = /^([0-9a-fA-F]{64})\s+\*?(.+)$/.exec(line);
1965
1965
  if (!match) continue;
1966
- out.set(match[2].trim().toLowerCase(), match[1].toLowerCase());
1966
+ out2.set(match[2].trim().toLowerCase(), match[1].toLowerCase());
1967
1967
  }
1968
- return out;
1968
+ return out2;
1969
1969
  }
1970
1970
  async function downloadChecksums(info, timeoutMs) {
1971
1971
  if (!info.checksumsUrl.trim()) {
@@ -2180,7 +2180,7 @@ async function readManifest(client, accountId, namespaceId) {
2180
2180
  }
2181
2181
  async function listCfPilotNamespaces(client, accountId) {
2182
2182
  const namespaces = await client.listKvNamespaces(accountId);
2183
- const out = [];
2183
+ const out2 = [];
2184
2184
  for (const ns of namespaces) {
2185
2185
  let manifest = null;
2186
2186
  try {
@@ -2188,9 +2188,9 @@ async function listCfPilotNamespaces(client, accountId) {
2188
2188
  } catch {
2189
2189
  continue;
2190
2190
  }
2191
- if (manifest) out.push({ id: ns.id, title: ns.title, manifest });
2191
+ if (manifest) out2.push({ id: ns.id, title: ns.title, manifest });
2192
2192
  }
2193
- return out;
2193
+ return out2;
2194
2194
  }
2195
2195
  async function writeManifest(client, accountId, namespaceId, manifest) {
2196
2196
  try {
@@ -2850,9 +2850,9 @@ async function deployPagesSplit(options) {
2850
2850
  function randomSuffix(length) {
2851
2851
  const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
2852
2852
  const bytes = randomBytes2(length);
2853
- let out = "";
2854
- for (const byte of bytes) out += alphabet[byte % alphabet.length];
2855
- return out;
2853
+ let out2 = "";
2854
+ for (const byte of bytes) out2 += alphabet[byte % alphabet.length];
2855
+ return out2;
2856
2856
  }
2857
2857
  async function configureProject(client, accountId, project, label, result, options, log, warnings, effective) {
2858
2858
  const kvBindings = {
@@ -3667,9 +3667,9 @@ function isKnownCountry(code) {
3667
3667
  }
3668
3668
  function normalizeCountryFilter(input) {
3669
3669
  if (!Array.isArray(input)) return [];
3670
- const out = [];
3670
+ const out2 = [];
3671
3671
  const push = (code) => {
3672
- if (code && !out.includes(code)) out.push(code);
3672
+ if (code && !out2.includes(code)) out2.push(code);
3673
3673
  };
3674
3674
  for (const raw of input) {
3675
3675
  const code = String(raw ?? "").trim().toUpperCase();
@@ -3685,7 +3685,7 @@ function normalizeCountryFilter(input) {
3685
3685
  const country = countryOfColo(code);
3686
3686
  if (country) push(country);
3687
3687
  }
3688
- return out;
3688
+ return out2;
3689
3689
  }
3690
3690
  function coloCity(colo) {
3691
3691
  return COLO_CITIES[colo.toUpperCase()] ?? "";
@@ -4681,13 +4681,13 @@ function ipv6Prefix48(cidr) {
4681
4681
  return `${groups[0]}:${groups[1]}:${groups[2]}::/48`;
4682
4682
  }
4683
4683
  function buildWeightEntries(src, family) {
4684
- const out = [];
4684
+ const out2 = [];
4685
4685
  for (const [cidr, weight] of Object.entries(src)) {
4686
4686
  const parsed = parseCidr(cidr);
4687
4687
  if (!parsed || parsed.family !== family) continue;
4688
- out.push({ base: parsed.base, prefix: parsed.prefix, weight });
4688
+ out2.push({ base: parsed.base, prefix: parsed.prefix, weight });
4689
4689
  }
4690
- return out;
4690
+ return out2;
4691
4691
  }
4692
4692
  function lpmWeight(table, parsed, bits, fallback) {
4693
4693
  let bestPrefix = -1;
@@ -4850,23 +4850,23 @@ function splitByWeight(cidr, weightFn = cidrWeight) {
4850
4850
  }
4851
4851
  return false;
4852
4852
  };
4853
- const out = [];
4853
+ const out2 = [];
4854
4854
  const stack = [{ c: cidr }];
4855
4855
  while (stack.length > 0) {
4856
4856
  const item = stack.pop();
4857
4857
  const c2 = item.c;
4858
4858
  const weight = item.known ?? weightFn(c2.cidr);
4859
4859
  if (c2.prefix >= maxPrefix) {
4860
- out.push(c2);
4860
+ out2.push(c2);
4861
4861
  continue;
4862
4862
  }
4863
4863
  if (cidr.family === 6) {
4864
4864
  if (weight > 0) {
4865
- out.push(c2);
4865
+ out2.push(c2);
4866
4866
  continue;
4867
4867
  }
4868
4868
  if (!v6HasEntryInside(c2)) {
4869
- out.push(c2);
4869
+ out2.push(c2);
4870
4870
  continue;
4871
4871
  }
4872
4872
  }
@@ -4880,12 +4880,12 @@ function splitByWeight(cidr, weightFn = cidrWeight) {
4880
4880
  const lw = weightFn(left.cidr);
4881
4881
  const rw = weightFn(right.cidr);
4882
4882
  if (cidr.family === 4 && lw === rw) {
4883
- out.push(c2);
4883
+ out2.push(c2);
4884
4884
  continue;
4885
4885
  }
4886
4886
  stack.push({ c: left, known: lw }, { c: right, known: rw });
4887
4887
  }
4888
- return out.sort((a, b) => a.base < b.base ? -1 : a.base > b.base ? 1 : 0);
4888
+ return out2.sort((a, b) => a.base < b.base ? -1 : a.base > b.base ? 1 : 0);
4889
4889
  }
4890
4890
  function expandCidrs(cidrs, options = {}) {
4891
4891
  const neutral = options.neutral === true;
@@ -4908,7 +4908,7 @@ function expandCidrs(cidrs, options = {}) {
4908
4908
  return all;
4909
4909
  }
4910
4910
  const minPerCidr = sample <= 1e3 ? 1 : 64;
4911
- const out = [];
4911
+ const out2 = [];
4912
4912
  for (const family of [4, 6]) {
4913
4913
  const group = parsed.filter((c2) => c2.family === family);
4914
4914
  if (group.length === 0) continue;
@@ -4959,7 +4959,7 @@ function expandCidrs(cidrs, options = {}) {
4959
4959
  if (count2 >= Number(cidr.size)) {
4960
4960
  for (let i = 0n; i < cidr.size; i++) {
4961
4961
  const value = cidr.base + i;
4962
- out.push(family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
4962
+ out2.push(family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
4963
4963
  }
4964
4964
  continue;
4965
4965
  }
@@ -4977,11 +4977,11 @@ function expandCidrs(cidrs, options = {}) {
4977
4977
  value = cidr.base + offsetValue;
4978
4978
  }
4979
4979
  }
4980
- out.push(cidr.family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
4980
+ out2.push(cidr.family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
4981
4981
  }
4982
4982
  }
4983
4983
  }
4984
- return out;
4984
+ return out2;
4985
4985
  }
4986
4986
  function looksLikeIpLiteral(rawValue) {
4987
4987
  if (!rawValue) return false;
@@ -4998,7 +4998,7 @@ function looksLikeIpLiteral(rawValue) {
4998
4998
  return false;
4999
4999
  }
5000
5000
  function readIpFile(text2) {
5001
- const out = [];
5001
+ const out2 = [];
5002
5002
  for (const raw of text2.split(/\r?\n/)) {
5003
5003
  let line = raw.trim();
5004
5004
  if (!line || line.startsWith("#")) continue;
@@ -5017,21 +5017,21 @@ function readIpFile(text2) {
5017
5017
  if (/\s/.test(line)) continue;
5018
5018
  const bracket = /^\[([^\]]+)\](?::\d+)?$/.exec(line);
5019
5019
  if (bracket) {
5020
- out.push(bracket[1]);
5020
+ out2.push(bracket[1]);
5021
5021
  continue;
5022
5022
  }
5023
5023
  if (line.includes(":") && line.split(":").length > 2) {
5024
- out.push(line);
5024
+ out2.push(line);
5025
5025
  continue;
5026
5026
  }
5027
5027
  if (line.includes(":")) {
5028
5028
  const [host] = line.split(":");
5029
- if (host) out.push(host);
5029
+ if (host) out2.push(host);
5030
5030
  continue;
5031
5031
  }
5032
- out.push(line);
5032
+ out2.push(line);
5033
5033
  }
5034
- return out;
5034
+ return out2;
5035
5035
  }
5036
5036
  async function readIpUrl(rawUrl, timeoutMs = IP_URL_TIMEOUT_MS, maxBytes = IP_URL_MAX_BYTES) {
5037
5037
  const trimmed = rawUrl.trim();
@@ -5241,28 +5241,28 @@ async function tcpPing(ip, port, timeoutMs) {
5241
5241
  });
5242
5242
  }
5243
5243
  async function pool(items, concurrency, worker, shouldStop) {
5244
- const out = new Array(items.length);
5244
+ const out2 = new Array(items.length);
5245
5245
  let cursor = 0;
5246
5246
  const runners = Array.from({ length: Math.max(1, Math.min(concurrency, items.length)) }, async () => {
5247
5247
  for (; ; ) {
5248
5248
  if (shouldStop?.()) return;
5249
5249
  const index = cursor++;
5250
5250
  if (index >= items.length) return;
5251
- out[index] = await worker(items[index], index);
5251
+ out2[index] = await worker(items[index], index);
5252
5252
  }
5253
5253
  });
5254
5254
  await Promise.all(runners);
5255
- return out;
5255
+ return out2;
5256
5256
  }
5257
5257
  async function poolAdaptive(items, concurrency, worker, batchSize = 200) {
5258
- const out = [];
5258
+ const out2 = [];
5259
5259
  const maxConcurrency = Math.max(1, concurrency);
5260
5260
  const minConcurrency = Math.min(8, maxConcurrency);
5261
5261
  let current = maxConcurrency;
5262
5262
  for (let start = 0; start < items.length; start += batchSize) {
5263
5263
  const batch = items.slice(start, start + batchSize);
5264
5264
  const results = await pool(batch, current, worker);
5265
- out.push(...results);
5265
+ out2.push(...results);
5266
5266
  const okCount = results.reduce((n, r) => n + (r.ok ? 1 : 0), 0);
5267
5267
  const rate2 = results.length > 0 ? okCount / results.length : 1;
5268
5268
  if (rate2 < 0.4) {
@@ -5271,7 +5271,7 @@ async function poolAdaptive(items, concurrency, worker, batchSize = 200) {
5271
5271
  current = Math.min(maxConcurrency, current * 2);
5272
5272
  }
5273
5273
  }
5274
- return out;
5274
+ return out2;
5275
5275
  }
5276
5276
  function isTimeoutError(error) {
5277
5277
  if (!error) return false;
@@ -5792,20 +5792,20 @@ function roundRobinBy(ranked, top, keyOf) {
5792
5792
  }
5793
5793
  if (buckets.size <= 1) return ranked.slice(0, top);
5794
5794
  const groups = [...buckets.values()];
5795
- const out = [];
5796
- for (let round = 0; out.length < top; round++) {
5795
+ const out2 = [];
5796
+ for (let round = 0; out2.length < top; round++) {
5797
5797
  let pickedAny = false;
5798
5798
  for (const group of groups) {
5799
- if (out.length >= top) break;
5799
+ if (out2.length >= top) break;
5800
5800
  const item = group[round];
5801
5801
  if (item) {
5802
- out.push(item);
5802
+ out2.push(item);
5803
5803
  pickedAny = true;
5804
5804
  }
5805
5805
  }
5806
5806
  if (!pickedAny) break;
5807
5807
  }
5808
- return out;
5808
+ return out2;
5809
5809
  }
5810
5810
  var COARSE_SPEED_DEFAULTS;
5811
5811
  var init_scan = __esm({
@@ -6239,10 +6239,10 @@ function adaptivePool(cidrs, limit, includeZero, neutral, random, store, options
6239
6239
  const exploreBudgetCount = exploreBudget(budget, explorationRate);
6240
6240
  let capPerPrefix = prefixCap(budget);
6241
6241
  const byPrefix = /* @__PURE__ */ new Map();
6242
- const out = [];
6242
+ const out2 = [];
6243
6243
  const capacityOf = (bucket) => bucket.capacity - bucket.used;
6244
- while (out.length < budget) {
6245
- const isExplore = out.length < exploreBudgetCount;
6244
+ while (out2.length < budget) {
6245
+ const isExplore = out2.length < exploreBudgetCount;
6246
6246
  const weights = [];
6247
6247
  let totalWeight = 0;
6248
6248
  for (const bucket2 of pool2) {
@@ -6306,9 +6306,9 @@ function adaptivePool(cidrs, limit, includeZero, neutral, random, store, options
6306
6306
  bucket.used++;
6307
6307
  const prefixKey = `${bucket.family}:${bucket.family24}`;
6308
6308
  byPrefix.set(prefixKey, (byPrefix.get(prefixKey) ?? 0) + 1);
6309
- out.push({ ip: format(address, bucket.family), staticWeight: bucket.staticWeight });
6309
+ out2.push({ ip: format(address, bucket.family), staticWeight: bucket.staticWeight });
6310
6310
  }
6311
- return out;
6311
+ return out2;
6312
6312
  }
6313
6313
  const v4Pool = buckets.filter((bucket) => bucket.family === 4);
6314
6314
  const v6Pool = buckets.filter((bucket) => bucket.family === 6);
@@ -6664,15 +6664,15 @@ async function probeDefaultRoute(timeoutMs = 800) {
6664
6664
  });
6665
6665
  try {
6666
6666
  if (platform === "win32") {
6667
- const out2 = await run("route", ["print", "-6"]);
6668
- return out2.includes("::/0");
6667
+ const out3 = await run("route", ["print", "-6"]);
6668
+ return out3.includes("::/0");
6669
6669
  }
6670
6670
  if (platform === "darwin") {
6671
- const out2 = await run("netstat", ["-rn", "-f", "inet6"]);
6672
- return /^default\b/m.test(out2);
6671
+ const out3 = await run("netstat", ["-rn", "-f", "inet6"]);
6672
+ return /^default\b/m.test(out3);
6673
6673
  }
6674
- const out = await run("ip", ["-6", "route", "show", "default"]);
6675
- return /^default\b/m.test(out);
6674
+ const out2 = await run("ip", ["-6", "route", "show", "default"]);
6675
+ return /^default\b/m.test(out2);
6676
6676
  } catch {
6677
6677
  return null;
6678
6678
  }
@@ -6811,7 +6811,7 @@ import net5 from "node:net";
6811
6811
  function normalizeCidrInput(cidr) {
6812
6812
  if (cidr === void 0) return [];
6813
6813
  const list = Array.isArray(cidr) ? cidr : [cidr];
6814
- const out = [];
6814
+ const out2 = [];
6815
6815
  const rejected = [];
6816
6816
  for (const item of list) {
6817
6817
  if (typeof item !== "string") continue;
@@ -6819,7 +6819,7 @@ function normalizeCidrInput(cidr) {
6819
6819
  const value = part.trim();
6820
6820
  if (!value) continue;
6821
6821
  const normalized = withDefaultPrefix(value);
6822
- if (parseCidr(normalized)) out.push(normalized);
6822
+ if (parseCidr(normalized)) out2.push(normalized);
6823
6823
  else rejected.push(value);
6824
6824
  }
6825
6825
  }
@@ -6830,7 +6830,7 @@ function normalizeCidrInput(cidr) {
6830
6830
  `\u65E0\u6CD5\u8BC6\u522B\u7684\u7F51\u6BB5/IP\uFF1A${head}${more}\u3002\u6B63\u786E\u5199\u6CD5\u662F 1.2.3.4\u30011.2.3.0/24\u30012606:4700::1 \u6216 2606:4700::/48`
6831
6831
  );
6832
6832
  }
6833
- return out;
6833
+ return out2;
6834
6834
  }
6835
6835
  function withDefaultPrefix(value) {
6836
6836
  if (value.includes("/")) return value;
@@ -6860,7 +6860,7 @@ async function loadCloudflareCidrs(family) {
6860
6860
  return [...ipv4, ...ipv6];
6861
6861
  }
6862
6862
  async function discoverIPv6Prefixes(hosts, timeoutMs = 6e3) {
6863
- const out = /* @__PURE__ */ new Set();
6863
+ const out2 = /* @__PURE__ */ new Set();
6864
6864
  for (const raw of hosts) {
6865
6865
  const host = String(raw ?? "").trim().toLowerCase().replace(/^https?:\/\//, "").replace(/\/.*$/, "");
6866
6866
  if (!host || net5.isIP(host)) continue;
@@ -6868,12 +6868,12 @@ async function discoverIPv6Prefixes(hosts, timeoutMs = 6e3) {
6868
6868
  const addresses = await withTimeout(resolve6(host), timeoutMs);
6869
6869
  for (const address of addresses) {
6870
6870
  const bucket = networkBucket(address);
6871
- if (bucket) out.add(bucket);
6871
+ if (bucket) out2.add(bucket);
6872
6872
  }
6873
6873
  } catch {
6874
6874
  }
6875
6875
  }
6876
- return [...out].sort();
6876
+ return [...out2].sort();
6877
6877
  }
6878
6878
  function withTimeout(promise, ms) {
6879
6879
  return new Promise((resolve4, reject) => {
@@ -6891,9 +6891,9 @@ function withTimeout(promise, ms) {
6891
6891
  });
6892
6892
  }
6893
6893
  function weightsOf(prefixes) {
6894
- const out = {};
6895
- for (const cidr of prefixes) out[cidr] = 1;
6896
- return out;
6894
+ const out2 = {};
6895
+ for (const cidr of prefixes) out2[cidr] = 1;
6896
+ return out2;
6897
6897
  }
6898
6898
  function pickCanary(pool2, extraWeights, seed) {
6899
6899
  try {
@@ -7007,7 +7007,7 @@ function normalizeCandidateList(input) {
7007
7007
  const lines = input.filter((item) => typeof item === "string");
7008
7008
  if (lines.length === 0) return [];
7009
7009
  const seen = /* @__PURE__ */ new Set();
7010
- const out = [];
7010
+ const out2 = [];
7011
7011
  for (const ip of readIpFile(lines.join("\n"))) {
7012
7012
  if (seen.has(ip)) continue;
7013
7013
  seen.add(ip);
@@ -7016,9 +7016,9 @@ function normalizeCandidateList(input) {
7016
7016
  if (isIpv4Literal || isIpv6Literal) {
7017
7017
  if (!isPublicAddress(ip)) continue;
7018
7018
  }
7019
- out.push(ip);
7019
+ out2.push(ip);
7020
7020
  }
7021
- return out;
7021
+ return out2;
7022
7022
  }
7023
7023
  var DEFAULT_CANDIDATE_SAMPLE, DEFAULT_BRIDGE_SAMPLE;
7024
7024
  var init_candidates = __esm({
@@ -7492,6 +7492,9 @@ scan \u9009\u9879:
7492
7492
  --cidr <a,b> \u81EA\u5B9A\u4E49\u7F51\u6BB5\uFF08\u53EF\u91CD\u590D\uFF0C\u7528\u9017\u53F7\u5206\u9694\uFF09
7493
7493
  --ip-file <path> \u4F7F\u7528\u672C\u5730 IP \u5217\u8868\u6587\u4EF6
7494
7494
  --ip-url <\u94FE\u63A5> \u4F7F\u7528\u8FDC\u7A0B IP \u5217\u8868\uFF08http/https\uFF0C\u4E0A\u9650 2MB\uFF0C\u4E0E --ip-file \u4E8C\u9009\u4E00\uFF09
7495
+ --from-pool \u4ECE\u672C\u5730\u5916\u90E8\u5019\u9009\u6C60\u5206\u5C42\u53D6\u6837\uFF08\u9ED8\u8BA4\u5173\u95ED\uFF0C\u5173\u95ED\u65F6\u884C\u4E3A\u5B8C\u5168\u4E0D\u53D8\uFF09
7496
+ \u6C60\u7531 cfpilot source sync \u957F\u671F\u79EF\u7D2F\uFF1B\u53D6\u6837\u53EA\u53D6\u7AEF\u53E3 == --port \u7684\u6761\u76EE
7497
+ --pool-sample <n> --from-pool \u7684\u53D6\u6837\u4E0A\u9650\uFF0C\u9ED8\u8BA4 200\uFF08\u4E0D\u4F1A\u653E\u5927\u6D4B\u901F\u5E76\u53D1\uFF09
7495
7498
  --max-latency <ms> \u9636\u6BB5\u4E00 TCP \u5EF6\u8FDF\u4E0A\u9650\uFF0C\u9ED8\u8BA4 0\uFF08\u4E0D\u9650\uFF09
7496
7499
  --tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 2000
7497
7500
  \u8D85\u65F6\u4E0D\u518D\u91CD\u8BD5\uFF08\u8BE5 IP \u5728\u5F53\u524D\u7F51\u7EDC\u4E0B\u5C31\u662F\u4E0D\u53EF\u7528\uFF09
@@ -7622,6 +7625,443 @@ ${NAME} scan relay \u2014\u2014 \u53CD\u4EE3\u5165\u53E3\uFF08ProxyIP \u6C60\uFF
7622
7625
  }
7623
7626
  });
7624
7627
 
7628
+ // src/sources/pool.ts
7629
+ import {
7630
+ closeSync,
7631
+ existsSync as existsSync2,
7632
+ mkdirSync as mkdirSync2,
7633
+ openSync,
7634
+ readFileSync as readFileSync2,
7635
+ renameSync,
7636
+ statSync,
7637
+ unlinkSync,
7638
+ writeFileSync as writeFileSync2,
7639
+ writeSync
7640
+ } from "node:fs";
7641
+ import { homedir as homedir3 } from "node:os";
7642
+ import { isIP as isIP2 } from "node:net";
7643
+ import { join as join4 } from "node:path";
7644
+ import { randomUUID as randomUUID3 } from "node:crypto";
7645
+ function poolDir() {
7646
+ const override = process.env.CFPILOT_CONFIG_DIR?.trim();
7647
+ return override ? override : join4(homedir3(), ".cfpilot");
7648
+ }
7649
+ function poolPath() {
7650
+ return join4(poolDir(), POOL_FILENAME);
7651
+ }
7652
+ function poolLockPath() {
7653
+ return poolPath() + ".lock";
7654
+ }
7655
+ function isDomainHost(host) {
7656
+ if (!host || host.length > 253) return false;
7657
+ if (!/^[A-Za-z0-9.-]+$/.test(host)) return false;
7658
+ const labels = host.split(".");
7659
+ if (labels.length < 2) return false;
7660
+ if (/^[\d.]+$/.test(host)) return false;
7661
+ return labels.every(
7662
+ (label) => label.length > 0 && label.length <= 63 && /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(label)
7663
+ );
7664
+ }
7665
+ function normalizeCandidateKey(ip, port) {
7666
+ const clean = ip.trim();
7667
+ const family = isIP2(clean);
7668
+ if (family !== 4 && family !== 6 && !isDomainHost(clean)) return null;
7669
+ if (!Number.isInteger(port) || port < 1 || port > 65535) return null;
7670
+ return family === 6 ? `[${clean}]:${port}` : `${clean}:${port}`;
7671
+ }
7672
+ function isCloudflareEntryIp(ip) {
7673
+ const family = isIP2(ip.trim());
7674
+ if (family !== 4 && family !== 6) return false;
7675
+ const bits = family === 4 ? 32 : 128;
7676
+ const parsed = parseCidr(`${ip.trim()}/${bits}`);
7677
+ if (!parsed || parsed.family !== family) return false;
7678
+ const allOnes = (1n << BigInt(bits)) - 1n;
7679
+ const nets = family === 4 ? V4_NETS : V6_NETS;
7680
+ for (const net9 of nets) {
7681
+ const hostBits = bits - net9.prefix;
7682
+ const mask = allOnes << BigInt(hostBits) & allOnes;
7683
+ if ((parsed.base & mask) === net9.base) return true;
7684
+ }
7685
+ return false;
7686
+ }
7687
+ function emptyPool() {
7688
+ return { schema: POOL_SCHEMA, updatedAt: 0, candidates: [] };
7689
+ }
7690
+ function readPoolRaw() {
7691
+ try {
7692
+ return readFileSync2(poolPath(), "utf8");
7693
+ } catch {
7694
+ return "";
7695
+ }
7696
+ }
7697
+ function isValidCandidate(value) {
7698
+ if (!value || typeof value !== "object") return false;
7699
+ const c2 = value;
7700
+ if (typeof c2.key !== "string" || !c2.key || typeof c2.ip !== "string" || !c2.ip || !Number.isInteger(c2.port) || (c2.port ?? 0) < 1 || (c2.port ?? 0) > 65535 || c2.ipVersion !== 0 && c2.ipVersion !== 4 && c2.ipVersion !== 6 || c2.candidateType !== ENTRY_IP || !Array.isArray(c2.sources) || !c2.sources.every((s) => typeof s === "string") || typeof c2.firstSeen !== "number" || !Number.isFinite(c2.firstSeen) || c2.firstSeen < 0 || typeof c2.lastSeen !== "number" || !Number.isFinite(c2.lastSeen) || c2.lastSeen < 0 || typeof c2.status !== "string" || !c2.status || !isValidOptionalNumber(c2.failCount) || !isValidOptionalNumber(c2.successCount)) return false;
7701
+ if (c2.lightCheck !== null && c2.lightCheck !== void 0 && !isValidLightCheck(c2.lightCheck)) return false;
7702
+ if (c2.fullTest !== null && c2.fullTest !== void 0 && !isValidFullTest(c2.fullTest)) return false;
7703
+ return true;
7704
+ }
7705
+ function isValidOptionalNumber(v) {
7706
+ return v === void 0 || typeof v === "number" && Number.isFinite(v);
7707
+ }
7708
+ function isValidLightCheck(v) {
7709
+ if (!v || typeof v !== "object") return false;
7710
+ const x = v;
7711
+ return typeof x.tcpOk === "boolean" && typeof x.tlsOk === "boolean" && typeof x.at === "number" && (x.tlsMs === void 0 || typeof x.tlsMs === "number");
7712
+ }
7713
+ function isValidFullTest(v) {
7714
+ if (!v || typeof v !== "object") return false;
7715
+ const x = v;
7716
+ return (x.at === null || x.at === void 0 || typeof x.at === "number") && (x.wsOk === null || x.wsOk === void 0 || typeof x.wsOk === "boolean") && (x.speedMBps === null || x.speedMBps === void 0 || typeof x.speedMBps === "number") && (x.colo === null || x.colo === void 0 || typeof x.colo === "string");
7717
+ }
7718
+ function normalizeCandidate(value) {
7719
+ if (!isValidCandidate(value)) return null;
7720
+ const c2 = value;
7721
+ const lightCheck = c2.lightCheck ? {
7722
+ tcpOk: c2.lightCheck.tcpOk,
7723
+ tlsOk: c2.lightCheck.tlsOk,
7724
+ // tlsMs 是可选字段:位置必须排在 at 之前,与 Go struct 一致
7725
+ ...typeof c2.lightCheck.tlsMs === "number" ? { tlsMs: c2.lightCheck.tlsMs } : {},
7726
+ at: c2.lightCheck.at
7727
+ } : null;
7728
+ const fullTest = c2.fullTest ? {
7729
+ at: typeof c2.fullTest.at === "number" ? c2.fullTest.at : null,
7730
+ wsOk: typeof c2.fullTest.wsOk === "boolean" ? c2.fullTest.wsOk : null,
7731
+ speedMBps: typeof c2.fullTest.speedMBps === "number" ? c2.fullTest.speedMBps : null,
7732
+ colo: typeof c2.fullTest.colo === "string" ? c2.fullTest.colo : null
7733
+ } : null;
7734
+ return {
7735
+ key: c2.key,
7736
+ ip: c2.ip,
7737
+ port: c2.port,
7738
+ ipVersion: c2.ipVersion,
7739
+ candidateType: ENTRY_IP,
7740
+ sources: [...c2.sources],
7741
+ firstSeen: c2.firstSeen,
7742
+ lastSeen: c2.lastSeen,
7743
+ lightCheck,
7744
+ fullTest,
7745
+ status: c2.status,
7746
+ failCount: c2.failCount ?? 0,
7747
+ successCount: c2.successCount ?? 0
7748
+ };
7749
+ }
7750
+ function parsePool(raw) {
7751
+ if (!raw.trim()) return emptyPool();
7752
+ try {
7753
+ const obj = JSON.parse(raw);
7754
+ if (obj.schema !== POOL_SCHEMA) throw new Error(`schema ${String(obj.schema)} \u4E0D\u517C\u5BB9`);
7755
+ const list = Array.isArray(obj.candidates) ? obj.candidates : [];
7756
+ return {
7757
+ schema: POOL_SCHEMA,
7758
+ updatedAt: typeof obj.updatedAt === "number" ? obj.updatedAt : 0,
7759
+ // candidateType 隔离:异类型 / 结构损坏的条目直接丢弃,不进池
7760
+ candidates: list.map(normalizeCandidate).filter((c2) => c2 !== null)
7761
+ };
7762
+ } catch {
7763
+ const backup = `${poolPath()}.corrupt-${Date.now()}`;
7764
+ try {
7765
+ if (existsSync2(poolPath())) renameSync(poolPath(), backup);
7766
+ } catch {
7767
+ }
7768
+ return emptyPool();
7769
+ }
7770
+ }
7771
+ function serializePool(pool2) {
7772
+ return `${JSON.stringify(pool2, null, 2)}
7773
+ `;
7774
+ }
7775
+ function writePoolAtomic(text2) {
7776
+ const dir = poolDir();
7777
+ mkdirSync2(dir, { recursive: true, mode: 448 });
7778
+ const tmp = join4(dir, `${POOL_FILENAME}.${process.pid}.${randomUUID3()}.tmp`);
7779
+ try {
7780
+ writeFileSync2(tmp, text2, { mode: 384 });
7781
+ renameSync(tmp, poolPath());
7782
+ } catch (err) {
7783
+ try {
7784
+ unlinkSync(tmp);
7785
+ } catch {
7786
+ }
7787
+ throw err;
7788
+ }
7789
+ }
7790
+ async function acquirePoolLock() {
7791
+ mkdirSync2(poolDir(), { recursive: true, mode: 448 });
7792
+ const started = Date.now();
7793
+ for (; ; ) {
7794
+ try {
7795
+ const fd = openSync(poolLockPath(), "wx", 384);
7796
+ try {
7797
+ writeSync(fd, JSON.stringify({ pid: process.pid, at: Date.now() }));
7798
+ } finally {
7799
+ closeSync(fd);
7800
+ }
7801
+ return;
7802
+ } catch (err) {
7803
+ const code = err.code;
7804
+ if (code !== "EEXIST") throw err;
7805
+ try {
7806
+ const st = statSync(poolLockPath());
7807
+ if (Date.now() - st.mtimeMs > LOCK_STALE_MS) {
7808
+ unlinkSync(poolLockPath());
7809
+ continue;
7810
+ }
7811
+ } catch {
7812
+ continue;
7813
+ }
7814
+ if (Date.now() - started > LOCK_TIMEOUT_MS) {
7815
+ throw new Error("\u672C\u5730\u5019\u9009\u6C60\u6B63\u88AB\u53E6\u4E00\u4E2A\u8FDB\u7A0B\u5360\u7528\uFF08\u9501\u8D85\u65F6\uFF09");
7816
+ }
7817
+ await sleep(LOCK_RETRY_MS);
7818
+ }
7819
+ }
7820
+ }
7821
+ function releasePoolLock() {
7822
+ try {
7823
+ unlinkSync(poolLockPath());
7824
+ } catch {
7825
+ }
7826
+ }
7827
+ async function withConfigDirLock(fn) {
7828
+ await acquirePoolLock();
7829
+ try {
7830
+ return await fn();
7831
+ } finally {
7832
+ releasePoolLock();
7833
+ }
7834
+ }
7835
+ async function withPool(fn) {
7836
+ return withConfigDirLock(async () => {
7837
+ const before = readPoolRaw();
7838
+ const pool2 = parsePool(before);
7839
+ const result = await fn(pool2);
7840
+ const after = serializePool(pool2);
7841
+ if (after !== before) writePoolAtomic(after);
7842
+ return result;
7843
+ });
7844
+ }
7845
+ function bumpReason(reasons, reason) {
7846
+ reasons[reason] = (reasons[reason] ?? 0) + 1;
7847
+ }
7848
+ function upsertCandidates(pool2, inputs, now = Date.now(), maxCandidates = POOL_MAX_CANDIDATES) {
7849
+ const byKey = /* @__PURE__ */ new Map();
7850
+ for (const c2 of pool2.candidates) byKey.set(c2.key, c2);
7851
+ const result = { added: 0, updated: 0, rejected: 0, reasons: {} };
7852
+ for (const input of inputs) {
7853
+ const port = input.port ?? 443;
7854
+ if (input.candidateType !== void 0 && input.candidateType !== ENTRY_IP) {
7855
+ result.rejected++;
7856
+ bumpReason(result.reasons, "candidateType");
7857
+ continue;
7858
+ }
7859
+ const key = normalizeCandidateKey(input.ip, port);
7860
+ if (!key) {
7861
+ result.rejected++;
7862
+ bumpReason(result.reasons, "invalidIp");
7863
+ continue;
7864
+ }
7865
+ const clean = input.ip.trim();
7866
+ const family = isIP2(clean);
7867
+ const domain = family === 0 && isDomainHost(clean);
7868
+ if (!domain && !isCloudflareEntryIp(clean)) {
7869
+ result.rejected++;
7870
+ bumpReason(result.reasons, "notCloudflare");
7871
+ continue;
7872
+ }
7873
+ const ipVersion = domain ? 0 : family === 6 ? 6 : 4;
7874
+ const existing = byKey.get(key);
7875
+ if (existing) {
7876
+ if (!existing.sources.includes(input.source)) existing.sources.push(input.source);
7877
+ existing.lastSeen = now;
7878
+ if (existing.status === "disabled") {
7879
+ } else if (existing.status === "expired" || existing.status === "failed") {
7880
+ existing.status = "pending";
7881
+ }
7882
+ if (input.lightCheck) existing.lightCheck = input.lightCheck;
7883
+ result.updated++;
7884
+ continue;
7885
+ }
7886
+ const created = {
7887
+ key,
7888
+ ip: clean,
7889
+ port,
7890
+ ipVersion,
7891
+ candidateType: ENTRY_IP,
7892
+ sources: [input.source],
7893
+ firstSeen: now,
7894
+ lastSeen: now,
7895
+ lightCheck: input.lightCheck ?? null,
7896
+ fullTest: null,
7897
+ status: "pending",
7898
+ failCount: 0,
7899
+ successCount: 0
7900
+ };
7901
+ byKey.set(key, created);
7902
+ pool2.candidates.push(created);
7903
+ result.added++;
7904
+ }
7905
+ for (const c2 of pool2.candidates) {
7906
+ if (c2.status !== "disabled" && now - c2.lastSeen > POOL_EXPIRE_MS) c2.status = "expired";
7907
+ }
7908
+ if (pool2.candidates.length > maxCandidates) {
7909
+ const disposable = pool2.candidates.filter((c2) => c2.status !== "disabled").sort((a, b) => a.lastSeen - b.lastSeen);
7910
+ const overflow = pool2.candidates.length - maxCandidates;
7911
+ const drop = new Set(disposable.slice(0, overflow).map((c2) => c2.key));
7912
+ if (drop.size > 0) {
7913
+ pool2.candidates = pool2.candidates.filter((c2) => !drop.has(c2.key));
7914
+ bumpReason(result.reasons, "evicted");
7915
+ }
7916
+ }
7917
+ pool2.updatedAt = now;
7918
+ return result;
7919
+ }
7920
+ var POOL_SCHEMA, POOL_FILENAME, ENTRY_IP, POOL_EXPIRE_MS, POOL_MAX_CANDIDATES, LOCK_STALE_MS, LOCK_TIMEOUT_MS, LOCK_RETRY_MS, V4_NETS, V6_NETS, sleep;
7921
+ var init_pool = __esm({
7922
+ "src/sources/pool.ts"() {
7923
+ "use strict";
7924
+ init_ip_ranges();
7925
+ POOL_SCHEMA = 1;
7926
+ POOL_FILENAME = "external-candidates.json";
7927
+ ENTRY_IP = "entry_ip";
7928
+ POOL_EXPIRE_MS = 30 * 24 * 60 * 60 * 1e3;
7929
+ POOL_MAX_CANDIDATES = 5e3;
7930
+ LOCK_STALE_MS = 3e4;
7931
+ LOCK_TIMEOUT_MS = 5e3;
7932
+ LOCK_RETRY_MS = 25;
7933
+ V4_NETS = BUILTIN_IPV4_CIDRS.map(parseCidr).filter(
7934
+ (v) => v !== null && v.family === 4
7935
+ );
7936
+ V6_NETS = BUILTIN_IPV6_CIDRS.map(parseCidr).filter(
7937
+ (v) => v !== null && v.family === 6
7938
+ );
7939
+ sleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
7940
+ }
7941
+ });
7942
+
7943
+ // src/sources/sample.ts
7944
+ function networkBucket2(ip) {
7945
+ if (ip.includes(":")) {
7946
+ const parsed = parseCidr(`${ip}/48`);
7947
+ if (parsed && parsed.family === 6) {
7948
+ return [112n, 96n, 80n].map((s) => (parsed.base >> s & 65535n).toString(16)).join(":");
7949
+ }
7950
+ return ip;
7951
+ }
7952
+ const parts = ip.split(".");
7953
+ return parts.length === 4 ? parts.slice(0, 3).join(".") : ip;
7954
+ }
7955
+ function eligible(pool2, port, includeUnchecked) {
7956
+ return pool2.candidates.filter((c2) => {
7957
+ if (c2.port !== port || c2.status === "disabled" || c2.status === "expired") return false;
7958
+ if (c2.lightCheck === null) return includeUnchecked;
7959
+ return c2.lightCheck.tcpOk && c2.lightCheck.tlsOk;
7960
+ });
7961
+ }
7962
+ function roundRobin(items, quota) {
7963
+ const buckets = /* @__PURE__ */ new Map();
7964
+ for (const c2 of items) {
7965
+ const key = networkBucket2(c2.ip);
7966
+ const list = buckets.get(key);
7967
+ if (list) list.push(c2);
7968
+ else buckets.set(key, [c2]);
7969
+ }
7970
+ for (const list of buckets.values()) {
7971
+ list.sort(
7972
+ (a, b) => b.successCount - a.successCount || b.lastSeen - a.lastSeen || a.key.localeCompare(b.key)
7973
+ );
7974
+ }
7975
+ const keys = [...buckets.keys()].sort();
7976
+ const out2 = [];
7977
+ for (let round = 0; out2.length < quota; round++) {
7978
+ let progressed = false;
7979
+ for (const key of keys) {
7980
+ if (out2.length >= quota) break;
7981
+ const c2 = buckets.get(key)[round];
7982
+ if (c2) {
7983
+ out2.push(c2);
7984
+ progressed = true;
7985
+ }
7986
+ }
7987
+ if (!progressed) break;
7988
+ }
7989
+ return out2;
7990
+ }
7991
+ function sampleFromPool(pool2, options = {}) {
7992
+ const limit = Math.max(1, options.limit ?? POOL_SAMPLE_LIMIT);
7993
+ const port = options.port ?? 443;
7994
+ const candidates = eligible(pool2, port, options.includeUnchecked !== false);
7995
+ const v4 = candidates.filter((c2) => c2.ipVersion === 4);
7996
+ const v6 = candidates.filter((c2) => c2.ipVersion === 6);
7997
+ let v4Quota = Math.ceil(limit / 2);
7998
+ let v6Quota = limit - v4Quota;
7999
+ if (v4.length < v4Quota) {
8000
+ v6Quota += v4Quota - v4.length;
8001
+ v4Quota = v4.length;
8002
+ }
8003
+ if (v6.length < v6Quota) {
8004
+ v4Quota += v6Quota - v6.length;
8005
+ v6Quota = v6.length;
8006
+ }
8007
+ const picked = [
8008
+ ...roundRobin(v4, v4Quota),
8009
+ ...roundRobin(v6, v6Quota)
8010
+ ].slice(0, limit);
8011
+ return {
8012
+ candidates: picked.map((c2) => c2.ip),
8013
+ keys: picked.map((c2) => c2.key),
8014
+ family: v4.length > 0 && v6.length > 0 ? "both" : v6.length > 0 ? "v6" : "v4",
8015
+ counts: {
8016
+ v4: picked.filter((c2) => c2.ipVersion === 4).length,
8017
+ v6: picked.filter((c2) => c2.ipVersion === 6).length
8018
+ },
8019
+ totalEligible: candidates.length,
8020
+ note: `\u672C\u5730\u6C60\u5206\u5C42\u53D6\u6837\uFF1A\u7AEF\u53E3 ${port}\uFF0C\u53EF\u53D6\u6837 ${candidates.length} \u6761\uFF08v4 ${v4.length} / v6 ${v6.length}\uFF09\uFF0C\u672C\u6B21\u53D6 ${picked.length} \u6761`
8021
+ };
8022
+ }
8023
+ async function applyFullTestResults(keys, port, summary, now = Date.now()) {
8024
+ const winners = /* @__PURE__ */ new Map();
8025
+ for (const entry of summary.entries) {
8026
+ const key = entry.ip.includes(":") ? `[${entry.ip}]:${port}` : `${entry.ip}:${port}`;
8027
+ winners.set(key, {
8028
+ speedMBps: entry.peakMBps || entry.speed,
8029
+ colo: entry.colo
8030
+ });
8031
+ }
8032
+ let active = 0;
8033
+ let failed = 0;
8034
+ await withPool((pool2) => {
8035
+ for (const key of keys) {
8036
+ const c2 = pool2.candidates.find((x) => x.key === key);
8037
+ if (!c2 || c2.status === "disabled") continue;
8038
+ const win = winners.get(key);
8039
+ if (win) {
8040
+ c2.status = "active";
8041
+ c2.fullTest = { at: now, wsOk: true, speedMBps: win.speedMBps, colo: win.colo };
8042
+ c2.successCount += 1;
8043
+ active++;
8044
+ } else {
8045
+ c2.status = "failed";
8046
+ c2.fullTest = { at: now, wsOk: false, speedMBps: null, colo: null };
8047
+ c2.failCount += 1;
8048
+ failed++;
8049
+ }
8050
+ }
8051
+ pool2.updatedAt = now;
8052
+ });
8053
+ return { active, failed };
8054
+ }
8055
+ var POOL_SAMPLE_LIMIT;
8056
+ var init_sample = __esm({
8057
+ "src/sources/sample.ts"() {
8058
+ "use strict";
8059
+ init_ip_ranges();
8060
+ init_pool();
8061
+ POOL_SAMPLE_LIMIT = 200;
8062
+ }
8063
+ });
8064
+
7625
8065
  // src/scan/compare.ts
7626
8066
  var compare_exports = {};
7627
8067
  __export(compare_exports, {
@@ -7918,7 +8358,7 @@ var init_compare = __esm({
7918
8358
  });
7919
8359
 
7920
8360
  // src/scan/relay-builtin.ts
7921
- import { readFileSync as readFileSync2 } from "node:fs";
8361
+ import { readFileSync as readFileSync3 } from "node:fs";
7922
8362
  import { dirname as dirname3, resolve as resolve2 } from "node:path";
7923
8363
  import { fileURLToPath as fileURLToPath2 } from "node:url";
7924
8364
  function moduleDir2() {
@@ -7937,7 +8377,7 @@ function readBuiltinRelayCandidates() {
7937
8377
  ];
7938
8378
  for (const path of paths) {
7939
8379
  try {
7940
- const list = readIpFile(readFileSync2(path, "utf8")).filter(
8380
+ const list = readIpFile(readFileSync3(path, "utf8")).filter(
7941
8381
  (ip) => /^\d{1,3}(\.\d{1,3}){3}$/.test(ip)
7942
8382
  );
7943
8383
  if (list.length > 0) return list;
@@ -7963,37 +8403,37 @@ var relay_exports = {};
7963
8403
  __export(relay_exports, {
7964
8404
  runRelayCommand: () => runRelayCommand
7965
8405
  });
7966
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
8406
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
7967
8407
  import { Duplex } from "node:stream";
7968
8408
  import * as tls4 from "node:tls";
7969
8409
  function uuidToBytes(uuid) {
7970
8410
  const hex = uuid.replace(/[^0-9a-fA-F]/g, "");
7971
8411
  if (hex.length !== 32) throw new Error(`UUID \u5E94\u4E3A 32 \u4F4D\u5341\u516D\u8FDB\u5236\uFF0C\u5B9E\u9645 ${hex.length} \u4F4D`);
7972
- const out = new Uint8Array(16);
7973
- for (let i = 0; i < 16; i++) out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
7974
- return out;
8412
+ const out2 = new Uint8Array(16);
8413
+ for (let i = 0; i < 16; i++) out2[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
8414
+ return out2;
7975
8415
  }
7976
8416
  function ipv4Address(ip) {
7977
8417
  const parts = ip.split(".").map((p) => Number(p));
7978
8418
  if (parts.length !== 4 || parts.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) {
7979
8419
  throw new Error(`\u4E0D\u662F\u5408\u6CD5\u7684 IPv4\uFF1A${ip}`);
7980
8420
  }
7981
- const out = new Uint8Array(5);
7982
- out[0] = 1;
7983
- out.set(parts, 1);
7984
- return out;
8421
+ const out2 = new Uint8Array(5);
8422
+ out2[0] = 1;
8423
+ out2.set(parts, 1);
8424
+ return out2;
7985
8425
  }
7986
8426
  function buildVlessHello(uuid, ip, port) {
7987
8427
  const addr = ipv4Address(ip);
7988
- const out = new Uint8Array(21 + addr.length);
7989
- out[0] = 0;
7990
- out.set(uuidToBytes(uuid), 1);
7991
- out[17] = 0;
7992
- out[18] = 1;
7993
- out[19] = port >> 8 & 255;
7994
- out[20] = port & 255;
7995
- out.set(addr, 21);
7996
- return out;
8428
+ const out2 = new Uint8Array(21 + addr.length);
8429
+ out2[0] = 0;
8430
+ out2.set(uuidToBytes(uuid), 1);
8431
+ out2[17] = 0;
8432
+ out2[18] = 1;
8433
+ out2[19] = port >> 8 & 255;
8434
+ out2[20] = port & 255;
8435
+ out2.set(addr, 21);
8436
+ return out2;
7997
8437
  }
7998
8438
  function createDuplex(ws) {
7999
8439
  const duplex = new Duplex({
@@ -8118,7 +8558,7 @@ function readHttp(socket, timeoutMs) {
8118
8558
  });
8119
8559
  }
8120
8560
  async function probeOne(opts, ip, timeoutMs) {
8121
- const out = {
8561
+ const out2 = {
8122
8562
  ip,
8123
8563
  ok: false,
8124
8564
  tunnelMs: 0,
@@ -8136,7 +8576,7 @@ async function probeOne(opts, ip, timeoutMs) {
8136
8576
  const tunnel = await openTunnel(opts.wsUrl, opts.uuid, ip, 443, timeoutMs);
8137
8577
  ws = tunnel.ws;
8138
8578
  sniff = tunnel.first;
8139
- out.tunnelMs = tunnel.tunnelMs;
8579
+ out2.tunnelMs = tunnel.tunnelMs;
8140
8580
  const tlsStarted = Date.now();
8141
8581
  socket = await withTimeout2(
8142
8582
  new Promise((resolve4, reject) => {
@@ -8155,7 +8595,7 @@ async function probeOne(opts, ip, timeoutMs) {
8155
8595
  timeoutMs,
8156
8596
  "TLS \u63E1\u624B"
8157
8597
  );
8158
- out.tlsMs = Date.now() - tlsStarted;
8598
+ out2.tlsMs = Date.now() - tlsStarted;
8159
8599
  const httpStarted = Date.now();
8160
8600
  socket.write(
8161
8601
  `GET /__cfp_version HTTP/1.1\r
@@ -8166,28 +8606,28 @@ User-Agent: cfpilot-scan-relay\r
8166
8606
  `
8167
8607
  );
8168
8608
  const res = await readHttp(socket, timeoutMs);
8169
- out.httpMs = Date.now() - httpStarted;
8170
- out.status = res.status;
8609
+ out2.httpMs = Date.now() - httpStarted;
8610
+ out2.status = res.status;
8171
8611
  if (res.status === 200) {
8172
8612
  try {
8173
8613
  const parsed = JSON.parse(res.body);
8174
- out.build = typeof parsed.build === "string" ? parsed.build : "";
8175
- out.buildOk = out.build !== "" && out.build === opts.expectedBuild;
8614
+ out2.build = typeof parsed.build === "string" ? parsed.build : "";
8615
+ out2.buildOk = out2.build !== "" && out2.build === opts.expectedBuild;
8176
8616
  } catch {
8177
8617
  }
8178
8618
  }
8179
- if (out.buildOk) {
8180
- out.ok = true;
8619
+ if (out2.buildOk) {
8620
+ out2.ok = true;
8181
8621
  } else if (res.status === 0) {
8182
- out.error = `\u65E0\u6709\u6548 HTTP \u54CD\u5E94\uFF08\u6536\u5230 ${res.raw.length} \u5B57\u8282\uFF09`;
8622
+ out2.error = `\u65E0\u6709\u6548 HTTP \u54CD\u5E94\uFF08\u6536\u5230 ${res.raw.length} \u5B57\u8282\uFF09`;
8183
8623
  } else if (res.status === 200) {
8184
- out.error = `build \u4E0D\u5339\u914D\uFF08${out.build || "\u7A7A"} \u2260 ${opts.expectedBuild}\uFF09`;
8624
+ out2.error = `build \u4E0D\u5339\u914D\uFF08${out2.build || "\u7A7A"} \u2260 ${opts.expectedBuild}\uFF09`;
8185
8625
  } else {
8186
- out.error = `HTTP ${res.status}`;
8626
+ out2.error = `HTTP ${res.status}`;
8187
8627
  }
8188
8628
  } catch (err) {
8189
8629
  const preview = sniff && sniff.first.length > 0 ? ` | \u9996\u5305=${JSON.stringify(sniff.first.subarray(0, 40).toString("utf8"))}` : " | \u9996\u5305=\uFF08\u7A7A\uFF09";
8190
- out.error = (String(err instanceof Error ? err.message : err) + preview).slice(0, 400);
8630
+ out2.error = (String(err instanceof Error ? err.message : err) + preview).slice(0, 400);
8191
8631
  } finally {
8192
8632
  try {
8193
8633
  socket?.destroy();
@@ -8198,7 +8638,7 @@ User-Agent: cfpilot-scan-relay\r
8198
8638
  } catch {
8199
8639
  }
8200
8640
  }
8201
- return out;
8641
+ return out2;
8202
8642
  }
8203
8643
  function median2(values) {
8204
8644
  if (values.length === 0) return 0;
@@ -8251,7 +8691,7 @@ async function runRelayCommand(args) {
8251
8691
  let rawCount = 0;
8252
8692
  const sourceLabel = file ? `\u6587\u4EF6 ${file}` : url ? `\u94FE\u63A5 ${url}` : "\u5185\u7F6E\u6E05\u5355";
8253
8693
  try {
8254
- const raw = file ? readIpFile(readFileSync3(file, "utf8")) : url ? await readIpUrl(url) : readBuiltinRelayCandidates();
8694
+ const raw = file ? readIpFile(readFileSync4(file, "utf8")) : url ? await readIpUrl(url) : readBuiltinRelayCandidates();
8255
8695
  rawCount = raw.length;
8256
8696
  ips = raw.filter((ip) => /^\d{1,3}(\.\d{1,3}){3}$/.test(ip));
8257
8697
  } catch (err) {
@@ -8343,7 +8783,7 @@ async function runRelayCommand(args) {
8343
8783
  const neverOk = aggregates.filter((a) => a.successPct === 0).length;
8344
8784
  const picked = aggregates.filter((a) => a.successPct === 100).slice(0, topN).map((a) => a.ip);
8345
8785
  if (outPath) {
8346
- writeFileSync2(outPath, picked.join("\n") + (picked.length > 0 ? "\n" : ""), "utf8");
8786
+ writeFileSync3(outPath, picked.join("\n") + (picked.length > 0 ? "\n" : ""), "utf8");
8347
8787
  if (!quiet) process.stderr.write(`\u5DF2\u5199\u51FA ${picked.length} \u6761\u5230 ${outPath}
8348
8788
  `);
8349
8789
  }
@@ -8445,8 +8885,8 @@ __export(command_exports2, {
8445
8885
  normalizeWsPath: () => normalizeWsPath,
8446
8886
  runScanCommand: () => runScanCommand
8447
8887
  });
8448
- import { readFileSync as readFileSync4 } from "node:fs";
8449
- import { join as join4 } from "node:path";
8888
+ import { readFileSync as readFileSync5 } from "node:fs";
8889
+ import { join as join5 } from "node:path";
8450
8890
  function normalizeWsPath(raw, fallback) {
8451
8891
  const value = (raw ?? fallback).trim();
8452
8892
  if (!value) return fallback;
@@ -8488,7 +8928,7 @@ function normalizeAccess(raw) {
8488
8928
  return value === "mobile" ? "mobile" : "fixed";
8489
8929
  }
8490
8930
  async function loadAdaptiveContext(args) {
8491
- const file = join4(configDirPath(), "network-profiles.json");
8931
+ const file = join5(configDirPath(), "network-profiles.json");
8492
8932
  const isp = normalizeIsp(flagString(args, "isp"));
8493
8933
  const region = normalizeRegion(flagString(args, "region") ?? "").slice(0, 32);
8494
8934
  const access = normalizeAccess(flagString(args, "access"));
@@ -8533,11 +8973,25 @@ function familyFromArgs(args) {
8533
8973
  `);
8534
8974
  process.exit(1);
8535
8975
  }
8536
- async function resolveCandidatesFromArgs(args, extraHosts = []) {
8976
+ async function resolveCandidatesFromArgs(args, extraHosts = [], port = 443) {
8977
+ if (flagBool(args, "from-pool")) {
8978
+ const limit = flagNumber(args, "pool-sample", POOL_SAMPLE_LIMIT);
8979
+ const sample = sampleFromPool(parsePool(readPoolRaw()), { limit, port });
8980
+ poolSamples.set(args, { keys: sample.keys, port });
8981
+ return {
8982
+ candidates: sample.candidates,
8983
+ family: sample.family === "both" ? "both" : sample.family,
8984
+ ipv6Env: null,
8985
+ v6Prefixes: [],
8986
+ v6Discovered: [],
8987
+ counts: sample.counts,
8988
+ note: sample.note
8989
+ };
8990
+ }
8537
8991
  const ipFile = flagString(args, "ip-file");
8538
8992
  const ipUrl = flagString(args, "ip-url");
8539
8993
  if (ipFile || ipUrl) {
8540
- const candidates = ipFile ? readIpFile(readFileSync4(ipFile, "utf8")) : await readIpUrl(ipUrl);
8994
+ const candidates = ipFile ? readIpFile(readFileSync5(ipFile, "utf8")) : await readIpUrl(ipUrl);
8541
8995
  return {
8542
8996
  candidates,
8543
8997
  family: "both",
@@ -8600,23 +9054,23 @@ async function saveAdaptiveObservations(args, observations) {
8600
9054
  }
8601
9055
  function printProgress2(event, quiet, asJson = false) {
8602
9056
  if (quiet) return;
8603
- const out = asJson ? process.stderr : process.stdout;
9057
+ const out2 = asJson ? process.stderr : process.stdout;
8604
9058
  switch (event.type) {
8605
9059
  case "stage":
8606
- out.write(`
9060
+ out2.write(`
8607
9061
  \u25B6 \u9636\u6BB5 ${event.stage}\uFF1A${event.name}\uFF08\u5171 ${event.total} \u4E2A\u5019\u9009\uFF09
8608
9062
  `);
8609
9063
  break;
8610
9064
  case "progress":
8611
- if (event.message) out.write(`\r ${event.message}`.padEnd(78));
9065
+ if (event.message) out2.write(`\r ${event.message}`.padEnd(78));
8612
9066
  break;
8613
9067
  case "done":
8614
- out.write(`
9068
+ out2.write(`
8615
9069
  \u2713 \u4F18\u9009\u5B8C\u6210\uFF0C\u5171 ${event.count} \u6761
8616
9070
  `);
8617
9071
  break;
8618
9072
  case "error":
8619
- out.write(`
9073
+ out2.write(`
8620
9074
  \u2717 ${event.message}
8621
9075
  `);
8622
9076
  break;
@@ -8780,10 +9234,12 @@ ${NAME} v${VERSION}
8780
9234
  }
8781
9235
  }
8782
9236
  if (!quiet && !asJson) process.stdout.write("\u6B63\u5728\u51C6\u5907 Cloudflare \u7F51\u6BB5\u2026\n");
8783
- const candidatePlan = await resolveCandidatesFromArgs(args, [host, panelHost]);
9237
+ const candidatePlan = await resolveCandidatesFromArgs(args, [host, panelHost], port);
8784
9238
  const candidates = candidatePlan.candidates;
8785
9239
  if (candidates.length === 0) {
8786
- process.stderr.write("\u5019\u9009 IP \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5 --ip-file / --cidr \u53C2\u6570\n");
9240
+ process.stderr.write(
9241
+ flagBool(args, "from-pool") ? "\u672C\u5730\u5019\u9009\u6C60\u6CA1\u6709\u53EF\u53D6\u6837\u6761\u76EE\uFF0C\u8BF7\u5148\u8DD1 `cfpilot source sync`\uFF08\u6216\u53BB\u6389 --from-pool \u7528\u5B98\u65B9\u7F51\u6BB5\uFF09\n" : "\u5019\u9009 IP \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5 --ip-file / --cidr \u53C2\u6570\n"
9242
+ );
8787
9243
  if (candidatePlan.ipv6Env && candidatePlan.ipv6Env.status !== "ok") {
8788
9244
  process.stderr.write(` ${candidatePlan.ipv6Env.message}
8789
9245
  `);
@@ -8915,6 +9371,16 @@ ${NAME} v${VERSION}
8915
9371
  onProgress: (event) => printProgress2(event, quiet, asJson)
8916
9372
  });
8917
9373
  await saveAdaptiveObservations(args, summary.observations);
9374
+ const sampled = poolSamples.get(args);
9375
+ if (sampled && sampled.keys.length > 0) {
9376
+ const applied = await applyFullTestResults(sampled.keys, sampled.port, summary);
9377
+ if (!quiet && !asJson) {
9378
+ process.stdout.write(
9379
+ `\u672C\u5730\u6C60\u5DF2\u56DE\u5199\uFF1Aactive ${applied.active} \u6761 / failed ${applied.failed} \u6761
9380
+ `
9381
+ );
9382
+ }
9383
+ }
8918
9384
  const fillable = summary.entries;
8919
9385
  if (asJson) {
8920
9386
  process.stdout.write(
@@ -9051,7 +9517,7 @@ async function promptCallback(entries, dataHost, panelHost, panelPassword, mode)
9051
9517
  process.stdout.write("\u2192 \u53EF\u624B\u52A8\u590D\u5236\u4E0A\u9762\u7684 IP \u5217\u8868\u7C98\u8D34\u5230\u9762\u677F\n");
9052
9518
  }
9053
9519
  }
9054
- var adaptiveContexts;
9520
+ var adaptiveContexts, poolSamples;
9055
9521
  var init_command2 = __esm({
9056
9522
  "src/scan/command.ts"() {
9057
9523
  "use strict";
@@ -9068,7 +9534,10 @@ var init_command2 = __esm({
9068
9534
  init_help2();
9069
9535
  init_speed_url();
9070
9536
  init_ip_ranges();
9537
+ init_pool();
9538
+ init_sample();
9071
9539
  adaptiveContexts = /* @__PURE__ */ new WeakMap();
9540
+ poolSamples = /* @__PURE__ */ new WeakMap();
9072
9541
  }
9073
9542
  });
9074
9543
 
@@ -9786,6 +10255,1175 @@ var init_main = __esm({
9786
10255
  }
9787
10256
  });
9788
10257
 
10258
+ // src/sources/builtin.generated.ts
10259
+ var BUILTIN_SOURCES_JSON;
10260
+ var init_builtin_generated = __esm({
10261
+ "src/sources/builtin.generated.ts"() {
10262
+ "use strict";
10263
+ BUILTIN_SOURCES_JSON = '[{"id":"bestcf-domain-all","name":"\u57DF\u540D\xB7\u7CBE\u9009\u5168\u91CF\u7248","type":"custom-url","url":"https://bestcf.pages.dev/domain/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-domain-mini","name":"\u57DF\u540D\xB7\u7CBE\u9009\u8FF7\u4F60\u7248","type":"custom-url","url":"https://bestcf.pages.dev/domain/mini.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-domain-asia","name":"\u57DF\u540D\xB7\u7CBE\u9009\u4E9A\u6D32\u7248","type":"custom-url","url":"https://bestcf.pages.dev/domain/Domain-Asia.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-domain-checked","name":"\u57DF\u540D\xB7\u5DF2\u6821\u9A8C\u793A\u4F8B","type":"custom-url","url":"https://bestcf.pages.dev/domain/Domain-Checked.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vps789-top10","name":"\u57DF\u540D\xB7VPS789 TOP10","type":"custom-url","url":"https://bestcf.pages.dev/vps789/top10.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vps789-top20","name":"\u57DF\u540D\xB7VPS789 TOP20","type":"custom-url","url":"https://bestcf.pages.dev/vps789/top20.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vps789-top50","name":"\u57DF\u540D\xB7VPS789 TOP50","type":"custom-url","url":"https://bestcf.pages.dev/vps789/top50.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vps789-top100","name":"\u57DF\u540D\xB7VPS789 TOP100","type":"custom-url","url":"https://bestcf.pages.dev/vps789/top100.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-ygkkk-domain","name":"\u57DF\u540D\xB7YGKKK","type":"custom-url","url":"https://bestcf.pages.dev/domain/ygkkk/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-qms-domain","name":"\u57DF\u540D\xB7QMS","type":"custom-url","url":"https://bestcf.pages.dev/domain/qms/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-senflare-domain","name":"\u57DF\u540D\xB7Senflare","type":"custom-url","url":"https://bestcf.pages.dev/domain/senflare/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-ircf-domain","name":"\u57DF\u540D\xB7IRCF","type":"custom-url","url":"https://bestcf.pages.dev/domain/ircf/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-wetest-ipv4","name":"IP\xB7WeTest \u4E09\u7F51","type":"custom-url","url":"https://bestcf.pages.dev/wetest/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-uouin-all","name":"IP\xB7UOUIN \u4E09\u7F51\u5E26\u6D4B\u901F","type":"custom-url","url":"https://bestcf.pages.dev/uouin/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-mia-ipv4","name":"IP\xB7Mia \u534A\u5C0F\u65F6","type":"custom-url","url":"https://bestcf.pages.dev/xinyitang3/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lzj-all","name":"IP\xB7LZJ \u542B IPv6","type":"custom-url","url":"https://bestcf.pages.dev/lzj/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cfyes-ipv4","name":"IP\xB7CFYes IPv4","type":"custom-url","url":"https://bestcf.pages.dev/cfyes/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cfyes-ipv6","name":"IP\xB7CFYes IPv6","type":"custom-url","url":"https://bestcf.pages.dev/cfyes/ipv6.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cfyes-api","name":"IP\xB7CFYes \u5907\u7528 API","type":"custom-url","url":"https://addressesapi.090227.xyz/CloudFlareYes","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-zhixuan-ipv4","name":"IP\xB7ZhiXuan IPv4","type":"custom-url","url":"https://bestcf.pages.dev/zhixuanwang/ipv4-onlyip.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-zhixuan-api","name":"IP\xB7ZhiXuan \u5907\u7528 API","type":"custom-url","url":"https://addressesapi.090227.xyz/ip.164746.xyz","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vvhan-ipv4","name":"IP\xB7vvHan IPv4","type":"custom-url","url":"https://bestcf.pages.dev/vvhan/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-vvhan-ipv6","name":"IP\xB7vvHan IPv6","type":"custom-url","url":"https://bestcf.pages.dev/vvhan/ipv6.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-mingyu-ipv4","name":"IP\xB7MingYu IPv4","type":"custom-url","url":"https://raw.githubusercontent.com/ymyuuu/IPDB/refs/heads/main/BestCF/bestcfv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-mingyu-ipv6","name":"IP\xB7MingYu IPv6","type":"custom-url","url":"https://raw.githubusercontent.com/ymyuuu/IPDB/refs/heads/main/BestCF/bestcfv6.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-yuanxiawan","name":"IP\xB7Yuanxiawan","type":"custom-url","url":"https://raw.githubusercontent.com/yuanxiawan/cfipv4db/refs/heads/main/cfip.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cmliu-all","name":"IP\xB7CM 1","type":"custom-url","url":"https://bestcf.pages.dev/cmliu/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cmliu2-all","name":"IP\xB7CM 2","type":"custom-url","url":"https://bestcf.pages.dev/cmliu2/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-cmliu-worker","name":"IP\xB7CM 3","type":"custom-url","url":"https://raw.githubusercontent.com/cmliu/WorkerVless2sub/refs/heads/main/addressesapi.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-ircf-ipv4","name":"IP\xB7IRCF","type":"custom-url","url":"https://bestcf.pages.dev/ircf/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-nirevil-ipv4","name":"IP\xB7NiREvil IPv4","type":"custom-url","url":"https://bestcf.pages.dev/nirevil/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-nirevil-ipv6","name":"IP\xB7NiREvil IPv6","type":"custom-url","url":"https://bestcf.pages.dev/nirevil/ipv6.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-all","name":"IP\xB7\u5929\u8BDA1 \u5168\u91CF","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-mini","name":"IP\xB7\u5929\u8BDA1 \u8FF7\u4F60","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/mini.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-hk","name":"IP\xB7\u5929\u8BDA1 \u9999\u6E2F","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/hk.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-sg","name":"IP\xB7\u5929\u8BDA1 \u65B0\u52A0\u5761","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/sg.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-jp","name":"IP\xB7\u5929\u8BDA1 \u65E5\u672C","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/jp.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-kr","name":"IP\xB7\u5929\u8BDA1 \u97E9\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/kr.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-us","name":"IP\xB7\u5929\u8BDA1 \u7F8E\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/us.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc1-tw","name":"IP\xB7\u5929\u8BDA1 \u53F0\u6E7E","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng/tw.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-all","name":"IP\xB7\u5929\u8BDA2 \u5168\u91CF","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-mini","name":"IP\xB7\u5929\u8BDA2 \u8FF7\u4F60","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/mini.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-hk","name":"IP\xB7\u5929\u8BDA2 \u9999\u6E2F","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/hk.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-de","name":"IP\xB7\u5929\u8BDA2 \u5FB7\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/de.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-jp","name":"IP\xB7\u5929\u8BDA2 \u65E5\u672C","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/jp.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-kr","name":"IP\xB7\u5929\u8BDA2 \u97E9\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/kr.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-sg","name":"IP\xB7\u5929\u8BDA2 \u65B0\u52A0\u5761","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/sg.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-us","name":"IP\xB7\u5929\u8BDA2 \u7F8E\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/us.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc2-tw","name":"IP\xB7\u5929\u8BDA2 \u53F0\u6E7E","type":"custom-url","url":"https://bestcf.pages.dev/tiancheng2/tw.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-all","name":"IP\xB7S5\u516C\u76CA \u5168\u91CF","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-mini","name":"IP\xB7S5\u516C\u76CA \u8FF7\u4F60","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/mini.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-hk","name":"IP\xB7S5\u516C\u76CA \u9999\u6E2F","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/hk.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-sg","name":"IP\xB7S5\u516C\u76CA \u65B0\u52A0\u5761","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/sg.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-jp","name":"IP\xB7S5\u516C\u76CA \u65E5\u672C","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/jp.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-kr","name":"IP\xB7S5\u516C\u76CA \u97E9\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/kr.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-us","name":"IP\xB7S5\u516C\u76CA \u7F8E\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/us.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-s5gy-tw","name":"IP\xB7S5\u516C\u76CA \u53F0\u6E7E","type":"custom-url","url":"https://bestcf.pages.dev/s5gy/tw.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-gslege-all","name":"IP\xB7Gslege \u5E26\u6D4B\u901F","type":"custom-url","url":"https://bestcf.pages.dev/gslege/Cfxyz.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-gslege-sg","name":"IP\xB7Gslege \u65B0\u52A0\u5761","type":"custom-url","url":"https://bestcf.pages.dev/gslege/SG.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-gslege-de","name":"IP\xB7Gslege \u5FB7\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/gslege/DE.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-gslege-us","name":"IP\xB7Gslege \u7F8E\u56FD","type":"custom-url","url":"https://bestcf.pages.dev/gslege/US.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-mjz-cu","name":"IP\xB7MJZ \u8054\u901A","type":"custom-url","url":"https://cf.junzhen.qzz.io/best_ips.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-mjz-ct","name":"IP\xB7MJZ \u7535\u4FE1","type":"custom-url","url":"https://cf.junzhen.qzz.io/best_ips_bj.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-ss-cmcc","name":"IP\xB7SS \u79FB\u52A8","type":"custom-url","url":"https://raw.githubusercontent.com/svip-s/cloudflare_ip/refs/heads/main/best_ips.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lz-ct","name":"IP\xB7LZ \u7535\u4FE1","type":"custom-url","url":"https://raw.githubusercontent.com/love-ztm/cfip/refs/heads/main/best_ips.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lz-cu","name":"IP\xB7LZ \u8054\u901A","type":"custom-url","url":"https://raw.githubusercontent.com/love-ztm/cfip/refs/heads/main/ubest_ips.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-collected","name":"IP\xB7LancelotRar \u91C7\u96C6\u805A\u5408","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-collected.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-top20","name":"IP\xB7LancelotRar TOP20","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-scanned-top20.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-top50","name":"IP\xB7LancelotRar TOP50","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-scanned-top50.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-top100","name":"IP\xB7LancelotRar TOP100","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-scanned-top100.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-top200","name":"IP\xB7LancelotRar TOP200","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-scanned-top200.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-lancelot-top400","name":"IP\xB7LancelotRar TOP400","type":"custom-url","url":"https://raw.githubusercontent.com/LancelotRar/best-cf-ips/refs/heads/main/best-cf-ip-scanned-top400.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-joname-ipv4","name":"IP\xB7Joname IPv4","type":"custom-url","url":"https://raw.githubusercontent.com/joname1/BestCFip/refs/heads/main/ipv4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-joname-ipv6","name":"IP\xB7Joname IPv6","type":"custom-url","url":"https://raw.githubusercontent.com/joname1/BestCFip/refs/heads/main/ipv6.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-ahang","name":"IP\xB7Ahang","type":"custom-url","url":"https://raw.githubusercontent.com/ahang39/router/refs/heads/main/all.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-einsitang","name":"IP\xB7Einsitang","type":"custom-url","url":"https://raw.githubusercontent.com/einsitang/my-fast-cf-ip/refs/heads/master/fastips.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-hubbylei","name":"IP\xB7Hubbylei","type":"custom-url","url":"https://raw.githubusercontent.com/hubbylei/bestcf/refs/heads/main/bestcf.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-tc4","name":"IP\xB7\u5929\u8BDA4","type":"custom-url","url":"https://raw.githubusercontent.com/gshtwy/CF-DNS-Clone/refs/heads/main/wetest-cloudflare-v4.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-senflare-ip","name":"IP\xB7Senflare \u5355IP","type":"custom-url","url":"https://raw.githubusercontent.com/Senflare/Senflare-IP/refs/heads/main/IPlist-Pro.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-senflare-pro","name":"IP\xB7Senflare \u5E26\u5907\u6CE8","type":"custom-url","url":"https://raw.githubusercontent.com/Senflare/Senflare-IP/refs/heads/main/Senflare-Pro.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-jiechaocc","name":"IP\xB7JieChaoCC","type":"custom-url","url":"https://raw.githubusercontent.com/JieChaoCC/cf-ip-auto/refs/heads/main/data/ipapi.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-api-all","name":"API\xB7\u6309\u8FD0\u8425\u5546\u968F\u673A \u4E09\u7F51","type":"custom-url","url":"https://090227.pages.dev/bestcf?isp=all&ips=20","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-api-ct","name":"API\xB7\u6309\u8FD0\u8425\u5546\u968F\u673A \u7535\u4FE1","type":"custom-url","url":"https://090227.pages.dev/bestcf?isp=ct&ips=50","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-api-cu","name":"API\xB7\u6309\u8FD0\u8425\u5546\u968F\u673A \u8054\u901A","type":"custom-url","url":"https://090227.pages.dev/bestcf?isp=cu&ips=50","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-api-cmcc","name":"API\xB7\u6309\u8FD0\u8425\u5546\u968F\u673A \u79FB\u52A8","type":"custom-url","url":"https://090227.pages.dev/bestcf?isp=cmcc&ips=50","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-warp-mini","name":"IP\xB7WARP \u901A\u7528\u6BB5\u8FF7\u4F60","type":"custom-url","url":"https://bestcf.pages.dev/WARP/WARP-MINI.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-warp-mini-443","name":"IP\xB7WARP \u8FF7\u4F60 443","type":"custom-url","url":"https://bestcf.pages.dev/WARP/WARP-MINI-443.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200},{"id":"bestcf-warp-mini-8443","name":"IP\xB7WARP \u8FF7\u4F60 8443","type":"custom-url","url":"https://bestcf.pages.dev/WARP/WARP-MINI-8443.txt","mirrors":[],"enabled":false,"intervalHours":6,"etag":"","lastModified":"","lastSyncAt":0,"lastError":"","failCount":0,"query":"","maxResults":200}]';
10264
+ }
10265
+ });
10266
+
10267
+ // src/sources/config.ts
10268
+ import {
10269
+ existsSync as existsSync3,
10270
+ mkdirSync as mkdirSync3,
10271
+ readFileSync as readFileSync6,
10272
+ renameSync as renameSync2,
10273
+ unlinkSync as unlinkSync2,
10274
+ writeFileSync as writeFileSync4
10275
+ } from "node:fs";
10276
+ import { join as join6 } from "node:path";
10277
+ import { randomUUID as randomUUID4 } from "node:crypto";
10278
+ function sourcesPath() {
10279
+ return join6(poolDir(), SOURCES_FILENAME);
10280
+ }
10281
+ function emptySources() {
10282
+ return {
10283
+ schema: SOURCES_SCHEMA,
10284
+ updatedAt: 0,
10285
+ sources: JSON.parse(BUILTIN_SOURCES_JSON),
10286
+ runs: []
10287
+ };
10288
+ }
10289
+ function blankSources() {
10290
+ return { schema: SOURCES_SCHEMA, updatedAt: 0, sources: [], runs: [] };
10291
+ }
10292
+ function readSourcesRaw() {
10293
+ try {
10294
+ return readFileSync6(sourcesPath(), "utf8");
10295
+ } catch {
10296
+ return "";
10297
+ }
10298
+ }
10299
+ function validSource(v) {
10300
+ if (!v || typeof v !== "object") return false;
10301
+ const s = v;
10302
+ return typeof s.id === "string" && s.id.length > 0 && typeof s.name === "string" && SOURCE_TYPES.includes(s.type) && typeof s.url === "string" && Array.isArray(s.mirrors) && s.mirrors.every((m) => typeof m === "string") && typeof s.enabled === "boolean" && typeof s.intervalHours === "number" && typeof s.etag === "string" && typeof s.lastModified === "string" && typeof s.lastSyncAt === "number" && typeof s.lastError === "string" && typeof s.failCount === "number";
10303
+ }
10304
+ function validRun(v) {
10305
+ if (!v || typeof v !== "object") return false;
10306
+ const r = v;
10307
+ return typeof r.at === "number" && typeof r.sourceId === "string" && typeof r.ok === "boolean" && typeof r.added === "number" && typeof r.updated === "number" && typeof r.rejected === "number" && typeof r.error === "string" && typeof r.durationMs === "number" && typeof r.notModified === "boolean";
10308
+ }
10309
+ function normalizeSource(v) {
10310
+ return {
10311
+ id: v.id,
10312
+ name: v.name,
10313
+ type: v.type,
10314
+ url: v.url,
10315
+ mirrors: [...v.mirrors],
10316
+ enabled: v.enabled,
10317
+ intervalHours: v.intervalHours,
10318
+ etag: v.etag,
10319
+ lastModified: v.lastModified,
10320
+ lastSyncAt: v.lastSyncAt,
10321
+ lastError: v.lastError,
10322
+ failCount: v.failCount,
10323
+ query: typeof v.query === "string" ? v.query : "",
10324
+ maxResults: typeof v.maxResults === "number" && v.maxResults > 0 ? v.maxResults : 200
10325
+ };
10326
+ }
10327
+ function normalizeRun(v) {
10328
+ return {
10329
+ at: v.at,
10330
+ sourceId: v.sourceId,
10331
+ ok: v.ok,
10332
+ added: v.added,
10333
+ updated: v.updated,
10334
+ rejected: v.rejected,
10335
+ error: v.error,
10336
+ durationMs: v.durationMs,
10337
+ notModified: v.notModified
10338
+ };
10339
+ }
10340
+ function parseSources(raw) {
10341
+ if (!raw.trim()) return emptySources();
10342
+ try {
10343
+ const obj = JSON.parse(raw);
10344
+ if (obj.schema !== SOURCES_SCHEMA && obj.schema !== SOURCES_SCHEMA_V1) {
10345
+ throw new Error(`schema ${String(obj.schema)} \u4E0D\u517C\u5BB9`);
10346
+ }
10347
+ return {
10348
+ schema: SOURCES_SCHEMA,
10349
+ updatedAt: typeof obj.updatedAt === "number" ? obj.updatedAt : 0,
10350
+ sources: (Array.isArray(obj.sources) ? obj.sources : []).filter(validSource).map(normalizeSource),
10351
+ runs: (Array.isArray(obj.runs) ? obj.runs : []).filter(validRun).map(normalizeRun).slice(-MAX_SYNC_RUNS)
10352
+ };
10353
+ } catch {
10354
+ const backup = `${sourcesPath()}.corrupt-${Date.now()}`;
10355
+ try {
10356
+ if (existsSync3(sourcesPath())) renameSync2(sourcesPath(), backup);
10357
+ } catch {
10358
+ }
10359
+ return blankSources();
10360
+ }
10361
+ }
10362
+ function serializeSources(file) {
10363
+ return `${JSON.stringify(file, null, 2)}
10364
+ `;
10365
+ }
10366
+ function writeSourcesAtomic(text2) {
10367
+ const dir = poolDir();
10368
+ mkdirSync3(dir, { recursive: true, mode: 448 });
10369
+ const tmp = join6(dir, `${SOURCES_FILENAME}.${process.pid}.${randomUUID4()}.tmp`);
10370
+ try {
10371
+ writeFileSync4(tmp, text2, { mode: 384 });
10372
+ renameSync2(tmp, sourcesPath());
10373
+ } catch (err) {
10374
+ try {
10375
+ unlinkSync2(tmp);
10376
+ } catch {
10377
+ }
10378
+ throw err;
10379
+ }
10380
+ }
10381
+ function loadSources() {
10382
+ return parseSources(readSourcesRaw());
10383
+ }
10384
+ function makeSource(input) {
10385
+ return {
10386
+ id: input.id,
10387
+ name: input.name ?? input.id,
10388
+ type: input.type,
10389
+ url: input.url ?? "",
10390
+ mirrors: input.mirrors ?? [],
10391
+ enabled: input.enabled ?? true,
10392
+ intervalHours: input.intervalHours ?? (input.type === "github-raw" ? 12 : 24),
10393
+ etag: "",
10394
+ lastModified: "",
10395
+ lastSyncAt: 0,
10396
+ lastError: "",
10397
+ failCount: 0,
10398
+ query: input.query ?? "",
10399
+ maxResults: input.maxResults ?? 200
10400
+ };
10401
+ }
10402
+ function appendRun(file, run) {
10403
+ file.runs.push(run);
10404
+ if (file.runs.length > MAX_SYNC_RUNS) {
10405
+ file.runs = file.runs.slice(-MAX_SYNC_RUNS);
10406
+ }
10407
+ file.updatedAt = run.at;
10408
+ }
10409
+ var SOURCES_SCHEMA, SOURCES_SCHEMA_V1, SOURCES_FILENAME, MAX_SYNC_RUNS, SOURCE_TYPES;
10410
+ var init_config2 = __esm({
10411
+ "src/sources/config.ts"() {
10412
+ "use strict";
10413
+ init_builtin_generated();
10414
+ init_pool();
10415
+ SOURCES_SCHEMA = 2;
10416
+ SOURCES_SCHEMA_V1 = 1;
10417
+ SOURCES_FILENAME = "external-sources.json";
10418
+ MAX_SYNC_RUNS = 50;
10419
+ SOURCE_TYPES = ["github-raw", "custom-url", "ripe-stat"];
10420
+ }
10421
+ });
10422
+
10423
+ // src/sources/fetch.ts
10424
+ import { isIP as isIP3 } from "node:net";
10425
+ function isPrivateIPv4(ip) {
10426
+ const p = ip.split(".").map(Number);
10427
+ const [a, b] = p;
10428
+ if (p.length !== 4 || p.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return true;
10429
+ if (a === 0 || a === 10 || a === 127) return true;
10430
+ if (a === 100 && b !== void 0 && b >= 64 && b <= 127) return true;
10431
+ if (a === 169 && b === 254) return true;
10432
+ if (a === 172 && b !== void 0 && b >= 16 && b <= 31) return true;
10433
+ if (a === 192 && b === 168) return true;
10434
+ if (a === 192 && b === 0) return true;
10435
+ if (a === 198 && (b === 18 || b === 19)) return true;
10436
+ if (a === 198 && b === 51 && p[2] === 100) return true;
10437
+ if (a === 203 && b === 0 && p[2] === 113) return true;
10438
+ if (a !== void 0 && a >= 224) return true;
10439
+ return false;
10440
+ }
10441
+ function isPrivateIPv6(ip) {
10442
+ const lower = ip.toLowerCase();
10443
+ if (lower === "::" || lower === "::1") return true;
10444
+ if (lower.startsWith("::ffff:")) return true;
10445
+ if (lower.startsWith("fc") || lower.startsWith("fd")) return true;
10446
+ if (/^fe[89ab]/.test(lower)) return true;
10447
+ return false;
10448
+ }
10449
+ function validateSourceUrl(raw, opts = {}) {
10450
+ let url;
10451
+ try {
10452
+ url = new URL(raw.trim());
10453
+ } catch {
10454
+ throw new Error(`\u4E0D\u662F\u5408\u6CD5\u7684\u94FE\u63A5\uFF1A${raw}`);
10455
+ }
10456
+ if (url.protocol !== "https:" && !(opts.allowHttp === true && url.protocol === "http:")) {
10457
+ throw new Error(`\u5916\u90E8\u6570\u636E\u6E90\u53EA\u652F\u6301 HTTPS\uFF0C\u5B9E\u9645\u662F ${url.protocol}`);
10458
+ }
10459
+ if (url.username || url.password) {
10460
+ throw new Error("\u5916\u90E8\u6570\u636E\u6E90\u94FE\u63A5\u4E0D\u5141\u8BB8\u5E26\u7528\u6237\u540D/\u5BC6\u7801");
10461
+ }
10462
+ const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
10463
+ if (BLOCKED_HOSTS.has(host) || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal")) {
10464
+ throw new Error(`\u5916\u90E8\u6570\u636E\u6E90\u4E0D\u5141\u8BB8\u6307\u5411\u672C\u673A\u6216\u5185\u7F51\u57DF\u540D\uFF1A${host}`);
10465
+ }
10466
+ const family = isIP3(host);
10467
+ if (family === 4 && isPrivateIPv4(host)) {
10468
+ throw new Error(`\u5916\u90E8\u6570\u636E\u6E90\u4E0D\u5141\u8BB8\u6307\u5411\u79C1\u7F51/\u4FDD\u7559\u5730\u5740\uFF1A${host}`);
10469
+ }
10470
+ if (family === 6 && isPrivateIPv6(host)) {
10471
+ throw new Error(`\u5916\u90E8\u6570\u636E\u6E90\u4E0D\u5141\u8BB8\u6307\u5411\u79C1\u7F51/\u4FDD\u7559\u5730\u5740\uFF1A${host}`);
10472
+ }
10473
+ return url;
10474
+ }
10475
+ async function fetchWithRedirects(url, headers, opts, hopsLeft, fetchImpl = fetch) {
10476
+ const res = await fetchImpl(url, {
10477
+ redirect: "manual",
10478
+ signal: AbortSignal.timeout(opts.timeoutMs),
10479
+ headers
10480
+ });
10481
+ if (REDIRECT_CODES.has(res.status)) {
10482
+ if (hopsLeft <= 0) throw new Error(`\u91CD\u5B9A\u5411\u8D85\u8FC7 ${SOURCE_MAX_REDIRECTS} \u8DF3\u4E0A\u9650`);
10483
+ const loc = res.headers.get("location");
10484
+ if (!loc) throw new Error(`HTTP ${res.status} \u91CD\u5B9A\u5411\u6CA1\u6709 Location`);
10485
+ const next = validateSourceUrl(new URL(loc, url).toString(), opts);
10486
+ return fetchWithRedirects(next, headers, opts, hopsLeft - 1, fetchImpl);
10487
+ }
10488
+ return res;
10489
+ }
10490
+ async function readBodyLimited(res, maxBytes) {
10491
+ const declared = Number(res.headers.get("content-length") ?? "");
10492
+ if (Number.isFinite(declared) && declared > maxBytes) {
10493
+ throw new Error(`\u6E05\u5355\u8FC7\u5927\uFF1A\u58F0\u660E ${declared} \u5B57\u8282\uFF0C\u4E0A\u9650 ${maxBytes} \u5B57\u8282`);
10494
+ }
10495
+ const reader = res.body?.getReader();
10496
+ if (!reader) {
10497
+ const text3 = await res.text();
10498
+ if (Buffer.byteLength(text3) > maxBytes) throw new Error(`\u6E05\u5355\u8FC7\u5927\uFF1A\u8D85\u8FC7 ${maxBytes} \u5B57\u8282\u4E0A\u9650`);
10499
+ return text3;
10500
+ }
10501
+ const decoder = new TextDecoder();
10502
+ let text2 = "";
10503
+ let total = 0;
10504
+ for (; ; ) {
10505
+ const { done, value } = await reader.read();
10506
+ if (done) break;
10507
+ if (!value || value.byteLength === 0) continue;
10508
+ total += value.byteLength;
10509
+ if (total > maxBytes) {
10510
+ try {
10511
+ await reader.cancel();
10512
+ } catch {
10513
+ }
10514
+ throw new Error(`\u6E05\u5355\u8FC7\u5927\uFF1A\u8D85\u8FC7 ${maxBytes} \u5B57\u8282\u4E0A\u9650`);
10515
+ }
10516
+ text2 += decoder.decode(value, { stream: true });
10517
+ }
10518
+ return text2 + decoder.decode();
10519
+ }
10520
+ function sourceUrls(source) {
10521
+ const out2 = [source.url, ...source.mirrors];
10522
+ if (source.type === "github-raw") {
10523
+ for (const m of MIRRORS) {
10524
+ out2.push(m.prefix + source.url);
10525
+ for (const mirror of source.mirrors) out2.push(m.prefix + mirror);
10526
+ }
10527
+ }
10528
+ return [...new Set(out2)];
10529
+ }
10530
+ async function fetchSourceText(source, opts = {}) {
10531
+ const timeoutMs = opts.timeoutMs ?? SOURCE_TIMEOUT_MS;
10532
+ const maxBytes = opts.maxBytes ?? SOURCE_MAX_BYTES;
10533
+ const headers = {
10534
+ "User-Agent": "CFPilot-ExternalSources/1.0",
10535
+ Accept: "text/plain, application/json, text/csv, */*"
10536
+ };
10537
+ if (source.etag) headers["If-None-Match"] = source.etag;
10538
+ if (source.lastModified) headers["If-Modified-Since"] = source.lastModified;
10539
+ const errors = [];
10540
+ for (const raw of sourceUrls(source)) {
10541
+ let url;
10542
+ try {
10543
+ url = validateSourceUrl(raw, opts);
10544
+ } catch (err) {
10545
+ errors.push(`${sanitizeUrl(raw)}\uFF1A${err instanceof Error ? err.message : String(err)}`);
10546
+ continue;
10547
+ }
10548
+ try {
10549
+ const res = await fetchWithRedirects(url, headers, { ...opts, timeoutMs }, SOURCE_MAX_REDIRECTS);
10550
+ if (res.status === 304) {
10551
+ return { text: "", url: sanitizeUrl(raw), etag: source.etag, lastModified: source.lastModified, notModified: true };
10552
+ }
10553
+ if (!res.ok) {
10554
+ errors.push(`${sanitizeUrl(raw)}\uFF1AHTTP ${res.status}`);
10555
+ continue;
10556
+ }
10557
+ const text2 = await readBodyLimited(res, maxBytes);
10558
+ return {
10559
+ text: text2,
10560
+ url: sanitizeUrl(raw),
10561
+ etag: res.headers.get("etag") ?? source.etag,
10562
+ lastModified: res.headers.get("last-modified") ?? source.lastModified,
10563
+ notModified: false
10564
+ };
10565
+ } catch (err) {
10566
+ errors.push(`${sanitizeUrl(raw)}\uFF1A${err instanceof Error ? err.message : String(err)}`);
10567
+ }
10568
+ }
10569
+ throw new Error(errors.length > 0 ? errors.join("\uFF1B") : "\u6570\u636E\u6E90\u6CA1\u6709\u53EF\u7528\u94FE\u63A5");
10570
+ }
10571
+ function sanitizeUrl(raw) {
10572
+ try {
10573
+ const u = new URL(raw);
10574
+ return `${u.protocol}//${u.host}${u.pathname}`;
10575
+ } catch {
10576
+ return "<invalid-url>";
10577
+ }
10578
+ }
10579
+ var SOURCE_MAX_BYTES, SOURCE_TIMEOUT_MS, SOURCE_MAX_REDIRECTS, BLOCKED_HOSTS, REDIRECT_CODES;
10580
+ var init_fetch = __esm({
10581
+ "src/sources/fetch.ts"() {
10582
+ "use strict";
10583
+ init_github_mirrors();
10584
+ SOURCE_MAX_BYTES = 2 * 1024 * 1024;
10585
+ SOURCE_TIMEOUT_MS = 15e3;
10586
+ SOURCE_MAX_REDIRECTS = 3;
10587
+ BLOCKED_HOSTS = /* @__PURE__ */ new Set([
10588
+ "localhost",
10589
+ "metadata",
10590
+ "metadata.google.internal",
10591
+ "instance-data"
10592
+ ]);
10593
+ REDIRECT_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
10594
+ }
10595
+ });
10596
+
10597
+ // src/sources/providers.ts
10598
+ function isProviderId(value) {
10599
+ return value === "ripe-stat";
10600
+ }
10601
+ async function getJson(req, rawUrl) {
10602
+ const url = validateSourceUrl(rawUrl);
10603
+ const timeoutMs = req.timeoutMs ?? SOURCE_TIMEOUT_MS;
10604
+ const maxBytes = req.maxBytes ?? SOURCE_MAX_BYTES;
10605
+ const opts = {
10606
+ timeoutMs,
10607
+ maxBytes,
10608
+ allowHttp: false
10609
+ };
10610
+ const res = await fetchWithRedirects(url, {}, opts, 3, req.fetchImpl ?? fetch);
10611
+ if (!res.ok) {
10612
+ throw new Error(`HTTP ${res.status}\uFF08${sanitizeUrl(rawUrl)}\uFF09`);
10613
+ }
10614
+ const text2 = await readBodyLimited(res, maxBytes);
10615
+ try {
10616
+ return JSON.parse(text2);
10617
+ } catch {
10618
+ throw new Error(`\u54CD\u5E94\u4E0D\u662F\u5408\u6CD5 JSON\uFF08${sanitizeUrl(rawUrl)}\uFF09`);
10619
+ }
10620
+ }
10621
+ function representativeIp(prefix) {
10622
+ const [addr, bits] = prefix.trim().split("/");
10623
+ if (!addr || !bits) return null;
10624
+ if (addr.includes(":")) {
10625
+ if (bits !== "48") return null;
10626
+ const groups = addr.split(":").filter((g) => g !== "");
10627
+ if (groups.length < 3) return null;
10628
+ return `${groups[0]}:${groups[1]}:${groups[2]}::1`;
10629
+ }
10630
+ if (bits !== "24") return null;
10631
+ const parts = addr.split(".");
10632
+ if (parts.length !== 4) return null;
10633
+ return `${parts[0]}.${parts[1]}.${parts[2]}.130`;
10634
+ }
10635
+ function spread(items, bucketOf, limit) {
10636
+ const buckets = /* @__PURE__ */ new Map();
10637
+ for (const item of items) {
10638
+ const key = bucketOf(item);
10639
+ const list = buckets.get(key);
10640
+ if (list) list.push(item);
10641
+ else buckets.set(key, [item]);
10642
+ }
10643
+ const keys = [...buckets.keys()].sort();
10644
+ const out2 = [];
10645
+ for (let round = 0; out2.length < limit; round++) {
10646
+ let progressed = false;
10647
+ for (const key of keys) {
10648
+ if (out2.length >= limit) break;
10649
+ const value = buckets.get(key)[round];
10650
+ if (value !== void 0) {
10651
+ out2.push(value);
10652
+ progressed = true;
10653
+ }
10654
+ }
10655
+ if (!progressed) break;
10656
+ }
10657
+ return out2;
10658
+ }
10659
+ async function runRipeStat(req) {
10660
+ const asn = (req.source.query || PROVIDERS["ripe-stat"].defaultQuery).trim();
10661
+ if (!/^AS\d{1,10}$/i.test(asn)) {
10662
+ throw new Error(`RIPEstat \u7684 query \u5FC5\u987B\u662F ASN\uFF08\u5982 AS13335\uFF09\uFF0C\u6536\u5230\u300C${asn}\u300D`);
10663
+ }
10664
+ const rawUrl = `https://stat.ripe.net/data/announced-prefixes/data.json?resource=${encodeURIComponent(asn)}`;
10665
+ const data = await getJson(req, rawUrl);
10666
+ if (data.status && data.status !== "ok") {
10667
+ throw new Error(`RIPEstat \u8FD4\u56DE ${data.status}`);
10668
+ }
10669
+ const prefixes = (data.data?.prefixes ?? []).map((p) => typeof p.prefix === "string" ? p.prefix : "").filter(Boolean);
10670
+ const v4 = [];
10671
+ const v6 = [];
10672
+ for (const prefix of prefixes) {
10673
+ const ip = representativeIp(prefix);
10674
+ if (!ip || !isCloudflareEntryIp(ip)) continue;
10675
+ if (ip.includes(":")) v6.push(ip);
10676
+ else v4.push(ip);
10677
+ }
10678
+ const max = Math.max(1, Math.min(2e3, req.source.maxResults || PROVIDERS["ripe-stat"].defaultMaxResults));
10679
+ const v6Limit = Math.floor(max / 4);
10680
+ const picked = [
10681
+ ...spread(v4, (ip) => ip.split(".").slice(0, 2).join("."), max - v6Limit),
10682
+ ...spread(v6, (ip) => ip.split(":").slice(0, 2).join(":"), v6Limit)
10683
+ ];
10684
+ return {
10685
+ candidates: picked.map((ip) => ({ ip, port: 443 })),
10686
+ note: `${asn} \u5BA3\u544A ${prefixes.length} \u4E2A\u524D\u7F00\uFF08v4 ${v4.length} / v6 ${v6.length} \u53EF\u7528\uFF09\uFF0C\u6309\u7236\u6BB5\u5206\u6563\u53D6 ${picked.length} \u4E2A\u4EE3\u8868 IP`,
10687
+ upstreamCount: prefixes.length
10688
+ };
10689
+ }
10690
+ async function runProvider(req) {
10691
+ const provider = req.source.type;
10692
+ if (!isProviderId(provider)) {
10693
+ throw new Error(`\u672A\u77E5 Provider\uFF1A${provider}\uFF08\u5F53\u524D\u53EA\u652F\u6301 ripe-stat\uFF09`);
10694
+ }
10695
+ return runRipeStat(req);
10696
+ }
10697
+ function isApiSource(source) {
10698
+ return API_SOURCE_TYPES.includes(source.type);
10699
+ }
10700
+ var API_SOURCE_TYPES, PROVIDERS;
10701
+ var init_providers = __esm({
10702
+ "src/sources/providers.ts"() {
10703
+ "use strict";
10704
+ init_fetch();
10705
+ init_pool();
10706
+ API_SOURCE_TYPES = ["ripe-stat"];
10707
+ PROVIDERS = {
10708
+ "ripe-stat": {
10709
+ id: "ripe-stat",
10710
+ requiresKey: false,
10711
+ minIntervalMs: 2e3,
10712
+ defaultQuery: "AS13335",
10713
+ defaultIntervalHours: 24,
10714
+ defaultMaxResults: 200,
10715
+ label: "RIPEstat \u5BA3\u544A\u524D\u7F00\uFF08\u96F6 Key\uFF09"
10716
+ }
10717
+ };
10718
+ }
10719
+ });
10720
+
10721
+ // src/sources/normalizer.ts
10722
+ function objString(v, keys) {
10723
+ if (!v || typeof v !== "object") return null;
10724
+ const o = v;
10725
+ for (const k of keys) {
10726
+ if (typeof o[k] === "string" && o[k].trim()) return o[k].trim();
10727
+ }
10728
+ return null;
10729
+ }
10730
+ function objPort(v) {
10731
+ if (!v || typeof v !== "object") return null;
10732
+ const raw = v.port;
10733
+ if (typeof raw === "number" && Number.isInteger(raw) && raw >= 1 && raw <= 65535) return raw;
10734
+ if (typeof raw === "string" && /^\d{1,5}$/.test(raw)) {
10735
+ const n = Number(raw);
10736
+ if (n >= 1 && n <= 65535) return n;
10737
+ }
10738
+ return null;
10739
+ }
10740
+ function splitHostPort(token) {
10741
+ let t = token.trim();
10742
+ const hash = t.indexOf("#");
10743
+ if (hash >= 0) t = t.slice(0, hash).trim();
10744
+ if (!t) return null;
10745
+ if (t.startsWith("[")) {
10746
+ const end = t.indexOf("]");
10747
+ if (end < 0) return null;
10748
+ const host = t.slice(1, end);
10749
+ const rest = t.slice(end + 1);
10750
+ const port = /^:\d{1,5}$/.test(rest) ? Number(rest.slice(1)) : null;
10751
+ return { ip: host, port: port && port >= 1 && port <= 65535 ? port : null };
10752
+ }
10753
+ const m = new RegExp(`^(${IPV4}):(\\d{1,5})$`).exec(t);
10754
+ if (m) {
10755
+ const port = Number(m[2]);
10756
+ return { ip: m[1], port: port >= 1 && port <= 65535 ? port : null };
10757
+ }
10758
+ return { ip: t, port: null };
10759
+ }
10760
+ function collectPorts(text2) {
10761
+ const ports = /* @__PURE__ */ new Map();
10762
+ for (const rawLine of text2.split(/\r?\n/)) {
10763
+ const line = rawLine.trim();
10764
+ if (!line || line.startsWith("#")) continue;
10765
+ for (const m of line.matchAll(new RegExp(HOST_PORT, "g"))) {
10766
+ const host = m[1] ?? m[2] ?? m[3];
10767
+ const port = Number(m[4]);
10768
+ if (host && port >= 1 && port <= 65535 && !ports.has(host)) ports.set(host, port);
10769
+ }
10770
+ if (line.includes(",")) {
10771
+ const cols = line.split(",").map((c2) => c2.trim().replace(/^"|"$/g, "").replace(/#.*$/, "").trim());
10772
+ for (let i = 0; i < cols.length - 1; i++) {
10773
+ const host = cols[i];
10774
+ if (!new RegExp(`^(?:${IPV4}|\\[${IPV6}\\])$`).test(host)) continue;
10775
+ if (!/^\d{1,5}$/.test(cols[i + 1])) continue;
10776
+ const port = Number(cols[i + 1]);
10777
+ const clean = host.startsWith("[") ? host.slice(1, -1) : host;
10778
+ if (port >= 1 && port <= 65535 && !ports.has(clean)) ports.set(clean, port);
10779
+ }
10780
+ }
10781
+ }
10782
+ return ports;
10783
+ }
10784
+ function parseJson(text2) {
10785
+ let data;
10786
+ try {
10787
+ data = JSON.parse(text2);
10788
+ } catch {
10789
+ return null;
10790
+ }
10791
+ let list = data;
10792
+ if (data && typeof data === "object" && !Array.isArray(data)) {
10793
+ for (const k of LIST_KEYS) {
10794
+ const v = data[k];
10795
+ if (Array.isArray(v)) {
10796
+ list = v;
10797
+ break;
10798
+ }
10799
+ }
10800
+ }
10801
+ if (!Array.isArray(list)) return null;
10802
+ const out2 = [];
10803
+ for (const item of list) {
10804
+ if (typeof item === "string") {
10805
+ const parsed2 = splitHostPort(item);
10806
+ if (parsed2) out2.push(parsed2);
10807
+ continue;
10808
+ }
10809
+ const host = objString(item, IP_KEYS);
10810
+ if (!host) continue;
10811
+ const parsed = splitHostPort(host);
10812
+ if (!parsed) continue;
10813
+ out2.push({ ip: parsed.ip, port: objPort(item) ?? parsed.port });
10814
+ }
10815
+ return out2;
10816
+ }
10817
+ function parseSourcePayload(text2) {
10818
+ const trimmed = text2.trim();
10819
+ if (!trimmed) return [];
10820
+ if (trimmed.startsWith("[") || trimmed.startsWith("{")) {
10821
+ const json = parseJson(trimmed);
10822
+ if (json !== null) return json;
10823
+ }
10824
+ const hosts = readIpFile(text2);
10825
+ const ports = collectPorts(text2);
10826
+ return hosts.map((ip) => ({ ip, port: ports.get(ip) ?? null }));
10827
+ }
10828
+ function toCandidateInputs(parsed, sourceId) {
10829
+ return parsed.map((p) => ({
10830
+ ip: p.ip,
10831
+ ...p.port === null ? {} : { port: p.port },
10832
+ source: sourceId
10833
+ }));
10834
+ }
10835
+ var IPV4, IPV6, DOMAIN, HOST_PORT, IP_KEYS, LIST_KEYS;
10836
+ var init_normalizer = __esm({
10837
+ "src/sources/normalizer.ts"() {
10838
+ "use strict";
10839
+ init_ip_ranges();
10840
+ IPV4 = "\\d{1,3}(?:\\.\\d{1,3}){3}";
10841
+ IPV6 = "[0-9a-fA-F:.]+";
10842
+ DOMAIN = "[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+";
10843
+ HOST_PORT = new RegExp(`(?:\\[(${IPV6})\\]:|(${IPV4}):|(${DOMAIN}):)(\\d{1,5})`);
10844
+ IP_KEYS = ["ip", "address", "addr", "host", "target", "value"];
10845
+ LIST_KEYS = ["ips", "data", "list", "candidates", "result", "items", "records"];
10846
+ }
10847
+ });
10848
+
10849
+ // src/sources/manager.ts
10850
+ function failure(source, error, startedAt) {
10851
+ return {
10852
+ source,
10853
+ inputs: [],
10854
+ etag: source.etag,
10855
+ lastModified: source.lastModified,
10856
+ outcome: {
10857
+ sourceId: source.id,
10858
+ ok: false,
10859
+ added: 0,
10860
+ updated: 0,
10861
+ rejected: 0,
10862
+ reasons: {},
10863
+ notModified: false,
10864
+ error: error.slice(0, 300),
10865
+ durationMs: Date.now() - startedAt,
10866
+ // API 型源没有 url,别把空串渲染成 <invalid-url>
10867
+ url: source.url ? sanitizeUrl(source.url) : ""
10868
+ }
10869
+ };
10870
+ }
10871
+ async function syncSources(options = {}) {
10872
+ const now = options.now ?? Date.now();
10873
+ const configured = loadSources();
10874
+ const wanted = new Set(options.sourceIds ?? []);
10875
+ const targets = configured.sources.filter(
10876
+ (s) => s.enabled && (wanted.size === 0 || wanted.has(s.id))
10877
+ );
10878
+ const fetcher = options.fetcher ?? fetchSourceText;
10879
+ const fetched = [];
10880
+ const listTargets = targets.filter((s) => !isApiSource(s));
10881
+ const apiTargets = targets.filter(isApiSource);
10882
+ const listResults = await Promise.all(
10883
+ listTargets.map(async (source) => {
10884
+ const startedAt = Date.now();
10885
+ try {
10886
+ const res = await fetcher(source, {
10887
+ timeoutMs: options.timeoutMs,
10888
+ maxBytes: options.maxBytes,
10889
+ allowHttp: options.allowHttp
10890
+ });
10891
+ const outcome = {
10892
+ sourceId: source.id,
10893
+ ok: true,
10894
+ added: 0,
10895
+ updated: 0,
10896
+ rejected: 0,
10897
+ reasons: {},
10898
+ notModified: res.notModified,
10899
+ error: "",
10900
+ durationMs: Date.now() - startedAt,
10901
+ url: res.url
10902
+ };
10903
+ if (res.notModified) {
10904
+ return { source, outcome, inputs: [], etag: res.etag, lastModified: res.lastModified };
10905
+ }
10906
+ const parsed = parseSourcePayload(res.text);
10907
+ let inputs = toCandidateInputs(parsed, source.id);
10908
+ if (options.lightCheck && inputs.length > 0) inputs = await options.lightCheck(inputs);
10909
+ return { source, outcome, inputs, etag: res.etag, lastModified: res.lastModified };
10910
+ } catch (err) {
10911
+ return failure(source, err instanceof Error ? err.message : String(err), startedAt);
10912
+ }
10913
+ })
10914
+ );
10915
+ fetched.push(...listResults);
10916
+ if (apiTargets.length > 0) {
10917
+ let lastAt = 0;
10918
+ let lastType = "";
10919
+ for (const source of apiTargets) {
10920
+ const spec = PROVIDERS[source.type];
10921
+ if (spec && lastType === source.type) {
10922
+ const wait = spec.minIntervalMs - (Date.now() - lastAt);
10923
+ if (wait > 0) await new Promise((resolve4) => setTimeout(resolve4, wait));
10924
+ }
10925
+ lastType = source.type;
10926
+ lastAt = Date.now();
10927
+ const startedAt = Date.now();
10928
+ try {
10929
+ const result = await runProvider({
10930
+ source,
10931
+ timeoutMs: options.timeoutMs,
10932
+ maxBytes: options.maxBytes,
10933
+ fetchImpl: options.providerFetch
10934
+ });
10935
+ let inputs = toCandidateInputs(result.candidates, source.id);
10936
+ if (options.lightCheck && inputs.length > 0) inputs = await options.lightCheck(inputs);
10937
+ fetched.push({
10938
+ source,
10939
+ outcome: {
10940
+ sourceId: source.id,
10941
+ ok: true,
10942
+ added: 0,
10943
+ updated: 0,
10944
+ rejected: 0,
10945
+ reasons: {},
10946
+ notModified: false,
10947
+ error: "",
10948
+ durationMs: Date.now() - startedAt,
10949
+ // note 已经脱敏(不含 dork / key),可安全展示
10950
+ url: result.note
10951
+ },
10952
+ inputs,
10953
+ etag: "",
10954
+ lastModified: ""
10955
+ });
10956
+ } catch (err) {
10957
+ fetched.push(failure(source, err instanceof Error ? err.message : String(err), startedAt));
10958
+ }
10959
+ }
10960
+ }
10961
+ let poolCandidates = 0;
10962
+ await withConfigDirLock(async () => {
10963
+ const poolBefore = readPoolRaw();
10964
+ const pool2 = parsePool(poolBefore);
10965
+ const cfgBefore = readSourcesRaw();
10966
+ const cfg = parseSources(cfgBefore);
10967
+ for (const item of fetched) {
10968
+ const current = cfg.sources.find((s) => s.id === item.source.id);
10969
+ const outcome = item.outcome;
10970
+ if (current) {
10971
+ current.lastSyncAt = now;
10972
+ if (outcome.ok) {
10973
+ current.etag = item.etag;
10974
+ current.lastModified = item.lastModified;
10975
+ current.failCount = 0;
10976
+ current.lastError = "";
10977
+ } else {
10978
+ current.failCount += 1;
10979
+ current.lastError = outcome.error;
10980
+ }
10981
+ }
10982
+ if (outcome.ok && !outcome.notModified && item.inputs.length > 0) {
10983
+ const r = upsertCandidates(pool2, item.inputs, now);
10984
+ outcome.added = r.added;
10985
+ outcome.updated = r.updated;
10986
+ outcome.rejected = r.rejected;
10987
+ outcome.reasons = r.reasons;
10988
+ }
10989
+ const run = {
10990
+ at: now,
10991
+ sourceId: outcome.sourceId,
10992
+ ok: outcome.ok,
10993
+ added: outcome.added,
10994
+ updated: outcome.updated,
10995
+ rejected: outcome.rejected,
10996
+ error: outcome.error,
10997
+ durationMs: outcome.durationMs,
10998
+ notModified: outcome.notModified
10999
+ };
11000
+ appendRun(cfg, run);
11001
+ }
11002
+ const poolAfter = serializePool(pool2);
11003
+ if (poolAfter !== poolBefore) writePoolAtomic(poolAfter);
11004
+ const cfgAfter = serializeSources(cfg);
11005
+ if (cfgAfter !== cfgBefore) writeSourcesAtomic(cfgAfter);
11006
+ poolCandidates = pool2.candidates.length;
11007
+ });
11008
+ return { at: now, outcomes: fetched.map((f) => f.outcome), poolCandidates };
11009
+ }
11010
+ async function testSource(source, options = {}) {
11011
+ const startedAt = Date.now();
11012
+ const baseOutcome = (ok, added, url, error) => ({
11013
+ sourceId: source.id,
11014
+ ok,
11015
+ added,
11016
+ updated: 0,
11017
+ rejected: 0,
11018
+ reasons: {},
11019
+ notModified: false,
11020
+ error,
11021
+ durationMs: Date.now() - startedAt,
11022
+ url
11023
+ });
11024
+ if (isApiSource(source)) {
11025
+ try {
11026
+ const result = await runProvider({
11027
+ source,
11028
+ timeoutMs: options.timeoutMs,
11029
+ maxBytes: options.maxBytes,
11030
+ fetchImpl: options.providerFetch
11031
+ });
11032
+ return baseOutcome(true, result.candidates.length, result.note, "");
11033
+ } catch (err) {
11034
+ const msg = err instanceof Error ? err.message : String(err);
11035
+ return baseOutcome(false, 0, "", msg.slice(0, 300));
11036
+ }
11037
+ }
11038
+ const fetcher = options.fetcher ?? fetchSourceText;
11039
+ try {
11040
+ const res = await fetcher(source, {
11041
+ timeoutMs: options.timeoutMs,
11042
+ maxBytes: options.maxBytes,
11043
+ allowHttp: options.allowHttp
11044
+ });
11045
+ const parsed = res.notModified ? [] : parseSourcePayload(res.text);
11046
+ return {
11047
+ sourceId: source.id,
11048
+ ok: true,
11049
+ added: parsed.length,
11050
+ updated: 0,
11051
+ rejected: 0,
11052
+ reasons: {},
11053
+ notModified: res.notModified,
11054
+ error: "",
11055
+ durationMs: Date.now() - startedAt,
11056
+ url: res.url
11057
+ };
11058
+ } catch (err) {
11059
+ return {
11060
+ sourceId: source.id,
11061
+ ok: false,
11062
+ added: 0,
11063
+ updated: 0,
11064
+ rejected: 0,
11065
+ reasons: {},
11066
+ notModified: false,
11067
+ error: (err instanceof Error ? err.message : String(err)).slice(0, 300),
11068
+ durationMs: Date.now() - startedAt,
11069
+ url: sanitizeUrl(source.url)
11070
+ };
11071
+ }
11072
+ }
11073
+ var init_manager = __esm({
11074
+ "src/sources/manager.ts"() {
11075
+ "use strict";
11076
+ init_config2();
11077
+ init_fetch();
11078
+ init_normalizer();
11079
+ init_providers();
11080
+ init_pool();
11081
+ }
11082
+ });
11083
+
11084
+ // src/sources/light.ts
11085
+ var light_exports = {};
11086
+ __export(light_exports, {
11087
+ LIGHT_CONCURRENCY: () => LIGHT_CONCURRENCY,
11088
+ LIGHT_CONNECT_TIMEOUT_MS: () => LIGHT_CONNECT_TIMEOUT_MS,
11089
+ LIGHT_MAX_PER_SYNC: () => LIGHT_MAX_PER_SYNC,
11090
+ LIGHT_REFRESH_MS: () => LIGHT_REFRESH_MS,
11091
+ LIGHT_TOTAL_TIMEOUT_MS: () => LIGHT_TOTAL_TIMEOUT_MS,
11092
+ lightCheckCandidates: () => lightCheckCandidates,
11093
+ tcpProbeOnce: () => tcpProbeOnce
11094
+ });
11095
+ import { Socket as Socket3 } from "node:net";
11096
+ function tcpProbeOnce(ip, port, timeoutMs) {
11097
+ return new Promise((resolve4) => {
11098
+ const socket = new Socket3();
11099
+ let settled = false;
11100
+ const done = (ok) => {
11101
+ if (settled) return;
11102
+ settled = true;
11103
+ socket.destroy();
11104
+ resolve4(ok);
11105
+ };
11106
+ socket.setTimeout(timeoutMs, () => done(false));
11107
+ socket.once("error", () => done(false));
11108
+ socket.once("connect", () => done(true));
11109
+ try {
11110
+ socket.connect(port, ip);
11111
+ } catch {
11112
+ done(false);
11113
+ }
11114
+ });
11115
+ }
11116
+ async function defaultTlsProbe(ip, port, host, timeoutMs) {
11117
+ const r = await probeTlsHandshake(ip, port, host, timeoutMs);
11118
+ return { ok: !r.error, tlsMs: r.tlsMs };
11119
+ }
11120
+ function needsCheck(key, now, existing) {
11121
+ const found = existing.candidates.find((c2) => c2.key === key);
11122
+ if (!found || !found.lightCheck) return true;
11123
+ return now - found.lightCheck.at > LIGHT_REFRESH_MS;
11124
+ }
11125
+ async function lightCheckCandidates(inputs, options = {}) {
11126
+ const now = options.now ?? Date.now();
11127
+ const max = options.maxPerSync ?? LIGHT_MAX_PER_SYNC;
11128
+ const concurrency = Math.max(1, options.concurrency ?? LIGHT_CONCURRENCY);
11129
+ const connectTimeout = options.connectTimeoutMs ?? LIGHT_CONNECT_TIMEOUT_MS;
11130
+ const totalTimeout = options.totalTimeoutMs ?? LIGHT_TOTAL_TIMEOUT_MS;
11131
+ const sni = options.sni || loadConfig().dataHost || "cloudflare.com";
11132
+ const tcpProbe = options.tcpProbe ?? tcpProbeOnce;
11133
+ const tlsProbe = options.tlsProbe ?? defaultTlsProbe;
11134
+ const pool2 = parsePool(readPoolRaw());
11135
+ const out2 = inputs.map((i) => ({ ...i }));
11136
+ const pending = [];
11137
+ for (let i = 0; i < out2.length && pending.length < max; i++) {
11138
+ const input = out2[i];
11139
+ const key = normalizeCandidateKey(input.ip, input.port ?? 443);
11140
+ if (!key) continue;
11141
+ if (needsCheck(key, now, pool2)) pending.push(i);
11142
+ }
11143
+ const deadline = Date.now() + totalTimeout;
11144
+ let cursor = 0;
11145
+ const worker = async () => {
11146
+ for (; ; ) {
11147
+ if (Date.now() >= deadline) return;
11148
+ const idx = cursor++;
11149
+ if (idx >= pending.length) return;
11150
+ const input = out2[pending[idx]];
11151
+ const port = input.port ?? 443;
11152
+ const tcpOk = await tcpProbe(input.ip, port, connectTimeout);
11153
+ let tlsOk = false;
11154
+ let tlsMs = 0;
11155
+ if (tcpOk) {
11156
+ const tls7 = await tlsProbe(input.ip, port, sni, connectTimeout);
11157
+ tlsOk = tls7.ok;
11158
+ tlsMs = tls7.tlsMs;
11159
+ }
11160
+ const check = {
11161
+ tcpOk,
11162
+ tlsOk,
11163
+ // 字段顺序必须与 Go struct 一致:tlsMs 排在 at 之前
11164
+ ...tlsOk && tlsMs > 0 ? { tlsMs } : {},
11165
+ at: now
11166
+ };
11167
+ input.lightCheck = check;
11168
+ }
11169
+ };
11170
+ await Promise.all(Array.from({ length: Math.min(concurrency, pending.length) }, worker));
11171
+ return out2;
11172
+ }
11173
+ var LIGHT_MAX_PER_SYNC, LIGHT_CONCURRENCY, LIGHT_CONNECT_TIMEOUT_MS, LIGHT_TOTAL_TIMEOUT_MS, LIGHT_REFRESH_MS;
11174
+ var init_light = __esm({
11175
+ "src/sources/light.ts"() {
11176
+ "use strict";
11177
+ init_store();
11178
+ init_true_probe();
11179
+ init_pool();
11180
+ LIGHT_MAX_PER_SYNC = 100;
11181
+ LIGHT_CONCURRENCY = 8;
11182
+ LIGHT_CONNECT_TIMEOUT_MS = 2e3;
11183
+ LIGHT_TOTAL_TIMEOUT_MS = 3e4;
11184
+ LIGHT_REFRESH_MS = 7 * 24 * 60 * 60 * 1e3;
11185
+ }
11186
+ });
11187
+
11188
+ // src/sources/command.ts
11189
+ var command_exports3 = {};
11190
+ __export(command_exports3, {
11191
+ runSourceCommand: () => runSourceCommand
11192
+ });
11193
+ function out(text2) {
11194
+ process.stdout.write(`${text2}
11195
+ `);
11196
+ }
11197
+ function fail(text2) {
11198
+ process.stderr.write(`\u2717 ${text2}
11199
+ `);
11200
+ process.exit(1);
11201
+ }
11202
+ function parseType(raw) {
11203
+ if (raw === "github-raw" || raw === "custom-url" || raw === "ripe-stat") return raw;
11204
+ return fail(`--type \u53EA\u63A5\u53D7 github-raw / custom-url / ripe-stat\uFF0C\u6536\u5230\u300C${raw}\u300D`);
11205
+ }
11206
+ function isApiType(type) {
11207
+ return type === "ripe-stat";
11208
+ }
11209
+ function printList(file, asJson) {
11210
+ if (asJson) {
11211
+ out(JSON.stringify(file, null, 2));
11212
+ return;
11213
+ }
11214
+ if (file.sources.length === 0) {
11215
+ out("\u8FD8\u6CA1\u6709\u6570\u636E\u6E90\u3002\u7528 `cfpilot source add <id> --url <\u94FE\u63A5>` \u6DFB\u52A0\u3002");
11216
+ return;
11217
+ }
11218
+ out("\u5916\u90E8 IP \u6570\u636E\u6E90\uFF1A");
11219
+ for (const s of file.sources) {
11220
+ const status2 = s.enabled ? "\u542F\u7528" : "\u7981\u7528";
11221
+ const last = s.lastSyncAt ? new Date(s.lastSyncAt).toLocaleString() : "\u4ECE\u672A";
11222
+ out(` [${status2}] ${s.id} ${s.type} ${sanitizeUrl(s.url)}`);
11223
+ out(` \u95F4\u9694 ${s.intervalHours}h \xB7 \u4E0A\u6B21 ${last} \xB7 \u5931\u8D25 ${s.failCount}${s.lastError ? ` \xB7 ${s.lastError}` : ""}`);
11224
+ }
11225
+ if (file.runs.length > 0) {
11226
+ out("\n\u6700\u8FD1\u91C7\u96C6\u8BB0\u5F55\uFF1A");
11227
+ for (const r of file.runs.slice(-5).reverse()) {
11228
+ const tag = r.ok ? r.notModified ? "\u672A\u53D8\u66F4" : `+${r.added}/~${r.updated}/\xD7${r.rejected}` : `\u5931\u8D25\uFF1A${r.error}`;
11229
+ out(` ${new Date(r.at).toLocaleString()} ${r.sourceId} ${tag} ${r.durationMs}ms`);
11230
+ }
11231
+ }
11232
+ }
11233
+ function printSync(report, asJson) {
11234
+ if (asJson) {
11235
+ out(JSON.stringify(report, null, 2));
11236
+ return;
11237
+ }
11238
+ for (const r of report.outcomes) {
11239
+ if (!r.ok) {
11240
+ out(` \u2717 ${r.sourceId}\uFF1A${r.error}`);
11241
+ } else if (r.notModified) {
11242
+ out(` = ${r.sourceId}\uFF1A\u672A\u53D8\u66F4\uFF08304\uFF09`);
11243
+ } else {
11244
+ out(` \u2713 ${r.sourceId}\uFF1A\u65B0\u589E ${r.added} \xB7 \u5237\u65B0 ${r.updated} \xB7 \u62D2\u7EDD ${r.rejected}`);
11245
+ }
11246
+ }
11247
+ out(`\u672C\u5730\u5019\u9009\u6C60\u73B0\u6709 ${report.poolCandidates} \u6761\uFF08\u672A\u5199 KV\u3001\u672A\u56DE\u586B\u8BA2\u9605\uFF09`);
11248
+ }
11249
+ async function removeSource(id) {
11250
+ return withConfigDirLock(async () => {
11251
+ const cfgBefore = readSourcesRaw();
11252
+ const cfg = parseSources(cfgBefore);
11253
+ const before = cfg.sources.length;
11254
+ cfg.sources = cfg.sources.filter((s) => s.id !== id);
11255
+ if (cfg.sources.length === before) throw new Error(`\u6570\u636E\u6E90\u4E0D\u5B58\u5728\uFF1A${id}`);
11256
+ cfg.runs = cfg.runs.filter((r) => r.sourceId !== id);
11257
+ cfg.updatedAt = Date.now();
11258
+ const poolBefore = readPoolRaw();
11259
+ const pool2 = parsePool(poolBefore);
11260
+ let removed = 0;
11261
+ pool2.candidates = pool2.candidates.filter((c2) => {
11262
+ if (!c2.sources.includes(id)) return true;
11263
+ c2.sources = c2.sources.filter((s) => s !== id);
11264
+ if (c2.sources.length > 0 || c2.status === "disabled") return true;
11265
+ removed++;
11266
+ return false;
11267
+ });
11268
+ const cfgAfter = serializeSources(cfg);
11269
+ if (cfgAfter !== cfgBefore) writeSourcesAtomic(cfgAfter);
11270
+ const poolAfter = serializePool(pool2);
11271
+ if (poolAfter !== poolBefore) writePoolAtomic(poolAfter);
11272
+ return { removedCandidates: removed, keptCandidates: pool2.candidates.length };
11273
+ });
11274
+ }
11275
+ async function runSourceCommand(args) {
11276
+ const action = (args.positionals[0] ?? "list").toLowerCase();
11277
+ const asJson = flagBool(args, "json");
11278
+ if (flagBool(args, "h") || flagBool(args, "help") || action === "help") {
11279
+ out(HELP);
11280
+ return;
11281
+ }
11282
+ switch (action) {
11283
+ case "list": {
11284
+ printList(loadSources(), asJson);
11285
+ return;
11286
+ }
11287
+ case "add": {
11288
+ const id = (args.positionals[1] ?? "").trim();
11289
+ if (!id) fail("\u7528\u6CD5\uFF1Acfpilot source add <id> --type <\u7C7B\u578B> [--url <\u94FE\u63A5> | --query <\u4E32>]");
11290
+ const type = parseType(flagString(args, "type") || "custom-url");
11291
+ const url = flagString(args, "url").trim();
11292
+ if (!isApiType(type) && !url) fail("list \u578B\u6570\u636E\u6E90\u7F3A\u5C11 --url");
11293
+ if (isApiType(type) && url) fail("API \u578B\u6570\u636E\u6E90\u4E0D\u9700\u8981 --url\uFF0C\u8BF7\u7528 --query");
11294
+ if (url) {
11295
+ try {
11296
+ validateSourceUrl(url);
11297
+ } catch (err) {
11298
+ fail(err instanceof Error ? err.message : String(err));
11299
+ }
11300
+ }
11301
+ const spec = isApiType(type) ? PROVIDERS[type] : void 0;
11302
+ const query = flagString(args, "query").trim() || (spec ? spec.defaultQuery : "");
11303
+ if (type === "ripe-stat" && !/^AS\d{1,10}$/i.test(query)) {
11304
+ fail(`ripe-stat \u7684 --query \u5FC5\u987B\u662F ASN\uFF08\u5982 AS13335\uFF09\uFF0C\u6536\u5230\u300C${query}\u300D`);
11305
+ }
11306
+ const source = makeSource({
11307
+ id,
11308
+ name: flagString(args, "name") || id,
11309
+ type,
11310
+ url,
11311
+ mirrors: flagList(args, "mirror"),
11312
+ enabled: !flagBool(args, "disabled"),
11313
+ intervalHours: flagNumber(args, "interval-hours", 0) || void 0,
11314
+ query,
11315
+ maxResults: flagNumber(args, "max-results", spec?.defaultMaxResults ?? 200)
11316
+ });
11317
+ await withConfigDirLock(async () => {
11318
+ const before = readSourcesRaw();
11319
+ const file = parseSources(before);
11320
+ if (file.sources.some((s) => s.id === id)) fail(`\u6570\u636E\u6E90\u5DF2\u5B58\u5728\uFF1A${id}`);
11321
+ file.sources.push(source);
11322
+ file.updatedAt = Date.now();
11323
+ const after = serializeSources(file);
11324
+ if (after !== before) writeSourcesAtomic(after);
11325
+ });
11326
+ out(asJson ? JSON.stringify(source, null, 2) : `\u2713 \u5DF2\u6DFB\u52A0\u6570\u636E\u6E90 ${id}\uFF08${source.type}\uFF09`);
11327
+ return;
11328
+ }
11329
+ case "remove": {
11330
+ const id = (args.positionals[1] ?? "").trim();
11331
+ if (!id) fail("\u7528\u6CD5\uFF1Acfpilot source remove <id>");
11332
+ const r = await removeSource(id);
11333
+ out(asJson ? JSON.stringify({ id, ...r }, null, 2) : `\u2713 \u5DF2\u5220\u9664\u6570\u636E\u6E90 ${id}\uFF1B\u6E05\u7406\u65E0\u6765\u6E90\u5019\u9009 ${r.removedCandidates} \u6761\uFF0C\u6C60\u5185\u4FDD\u7559 ${r.keptCandidates} \u6761`);
11334
+ return;
11335
+ }
11336
+ case "test": {
11337
+ const id = (args.positionals[1] ?? "").trim();
11338
+ if (!id) fail("\u7528\u6CD5\uFF1Acfpilot source test <id>");
11339
+ const source = loadSources().sources.find((s) => s.id === id);
11340
+ if (!source) fail(`\u6570\u636E\u6E90\u4E0D\u5B58\u5728\uFF1A${id}`);
11341
+ const probe = { ...source, etag: "", lastModified: "" };
11342
+ const r = await testSource(probe, {
11343
+ allowHttp: flagBool(args, "allow-http"),
11344
+ timeoutMs: flagNumber(args, "timeout-ms", SOURCE_TIMEOUT_MS)
11345
+ });
11346
+ if (asJson) {
11347
+ out(JSON.stringify(r, null, 2));
11348
+ } else if (r.ok) {
11349
+ out(`\u2713 ${source.id} \u53EF\u7528\uFF1A\u89E3\u6790\u51FA ${r.added} \u6761\u5019\u9009\uFF08${r.durationMs}ms\uFF09
11350
+ \u6765\u81EA ${r.url}`);
11351
+ } else {
11352
+ out(`\u2717 ${source.id} \u4E0D\u53EF\u7528\uFF1A${r.error}`);
11353
+ }
11354
+ if (!r.ok) process.exitCode = 1;
11355
+ return;
11356
+ }
11357
+ case "sync": {
11358
+ const ids = args.positionals.slice(1).filter(Boolean);
11359
+ const options = {
11360
+ sourceIds: ids,
11361
+ allowHttp: flagBool(args, "allow-http"),
11362
+ timeoutMs: flagNumber(args, "timeout-ms", SOURCE_TIMEOUT_MS)
11363
+ };
11364
+ if (flagBool(args, "light")) {
11365
+ const { lightCheckCandidates: lightCheckCandidates2 } = await Promise.resolve().then(() => (init_light(), light_exports));
11366
+ options.lightCheck = lightCheckCandidates2;
11367
+ }
11368
+ const report = await syncSources(options);
11369
+ printSync(report, asJson);
11370
+ if (report.outcomes.some((r) => !r.ok)) process.exitCode = 1;
11371
+ return;
11372
+ }
11373
+ default:
11374
+ fail(`\u672A\u77E5\u52A8\u4F5C\uFF1A${action}
11375
+ ${HELP}`);
11376
+ }
11377
+ }
11378
+ var HELP;
11379
+ var init_command3 = __esm({
11380
+ "src/sources/command.ts"() {
11381
+ "use strict";
11382
+ init_args();
11383
+ init_config2();
11384
+ init_fetch();
11385
+ init_providers();
11386
+ init_manager();
11387
+ init_pool();
11388
+ HELP = `
11389
+ cfpilot source <\u52A8\u4F5C> [\u9009\u9879] \u5916\u90E8 IP \u6570\u636E\u6E90\u7BA1\u7406\uFF08\u672C\u5730\u6C60\uFF0C\u4E0D\u5199 KV\uFF09
11390
+
11391
+ \u52A8\u4F5C:
11392
+ list \u5217\u51FA\u6570\u636E\u6E90\u4E0E\u6700\u8FD1\u91C7\u96C6\u8BB0\u5F55
11393
+ add <id> \u65B0\u589E\u6570\u636E\u6E90\uFF08\u9ED8\u8BA4\u542F\u7528\uFF09
11394
+ remove <id> \u5220\u9664\u6570\u636E\u6E90\u5E76\u6E05\u7406\u6765\u6E90\u5173\u8054
11395
+ test <id> \u6D4B\u8BD5\u8FDE\u63A5\uFF08\u53EA\u62C9\u4E0D\u5199\u6C60\uFF09
11396
+ sync [id...] \u540C\u6B65\u5230 ~/.cfpilot/external-candidates.json
11397
+
11398
+ \u6765\u6E90\u7C7B\u578B\uFF08--type\uFF09:
11399
+ github-raw / custom-url GET \u4E00\u4EFD\u6E05\u5355\u6587\u672C\uFF08\u9700 --url\uFF09
11400
+ ripe-stat RIPEstat AS \u5BA3\u544A\u524D\u7F00\uFF0C\u96F6 Key\uFF08\u9ED8\u8BA4 AS13335\uFF09
11401
+
11402
+ \u9009\u9879:
11403
+ --type <\u7C7B\u578B> \u6765\u6E90\u7C7B\u578B\uFF08\u9ED8\u8BA4 custom-url\uFF09
11404
+ --url <\u94FE\u63A5> \u6E05\u5355 URL\uFF08list \u578B\u5FC5\u586B\uFF0CAPI \u578B\u4E0D\u7528\uFF09
11405
+ --query <\u4E32> API \u578B\u67E5\u8BE2\uFF1Aripe-stat \u7528 ASN\uFF08\u7F3A\u7701 AS13335\uFF09
11406
+ --max-results <n> API \u578B\u5355\u6B21\u6700\u591A\u5165\u6C60\u5019\u9009\uFF08\u9ED8\u8BA4 200\uFF09
11407
+ --name <\u540D\u79F0> \u663E\u793A\u540D\u79F0\uFF08\u9ED8\u8BA4\u540C id\uFF09
11408
+ --mirror <\u94FE\u63A5> \u955C\u50CF URL\uFF0C\u53EF\u91CD\u590D\uFF08\u4EC5 list \u578B\uFF09
11409
+ --interval-hours <\u5C0F\u65F6> \u5EFA\u8BAE\u540C\u6B65\u95F4\u9694
11410
+ --disabled \u65B0\u589E\u540E\u4FDD\u6301\u7981\u7528
11411
+ --allow-http \u5141\u8BB8 http\uFF08\u4EC5\u672C\u5730\u81EA\u5EFA\u6D4B\u8BD5\u6E90\uFF0C\u751F\u4EA7\u8BF7\u7528 HTTPS\uFF09
11412
+ --timeout-ms <\u6BEB\u79D2> \u5355\u6E90\u8D85\u65F6\uFF08\u9ED8\u8BA4 ${SOURCE_TIMEOUT_MS}\uFF09
11413
+ --light \u540C\u6B65\u540E\u5BF9\u65B0\u589E\u5019\u9009\u505A TCP/TLS \u8F7B\u91CF\u6821\u9A8C
11414
+ --json \u4EE5 JSON \u8F93\u51FA
11415
+ -h, --help \u663E\u793A\u672C\u5E2E\u52A9
11416
+
11417
+ \u793A\u4F8B:
11418
+ cfpilot source add ripe --type ripe-stat --query AS13335 --max-results 200
11419
+ cfpilot source sync ripe --json
11420
+
11421
+ \u26A0\uFE0F \u540C\u6B65\u53EA\u5199\u672C\u5730\u78C1\u76D8\uFF1A\u4E0D\u89E6\u53D1 WS \u6821\u9A8C\u3001\u4E0D\u6D4B\u901F\u3001\u4E0D\u56DE\u586B\u8BA2\u9605\u3002
11422
+ \u8981\u66F4\u65B0\u8BA2\u9605\u8BF7\u7528 cfpilot scan --from-pool\uFF08\u5B8C\u6574\u4F18\u9009 + \u56DE\u586B\uFF09\u3002
11423
+ `;
11424
+ }
11425
+ });
11426
+
9789
11427
  // src/scan/single.ts
9790
11428
  import * as net6 from "node:net";
9791
11429
  function probeTcp(ip, port, timeoutMs) {
@@ -9927,13 +11565,13 @@ function printStage(result) {
9927
11565
  }
9928
11566
  async function runTestCommand(args) {
9929
11567
  if (flagBool(args, "h") || flagBool(args, "help")) {
9930
- process.stdout.write(HELP);
11568
+ process.stdout.write(HELP2);
9931
11569
  return;
9932
11570
  }
9933
11571
  const host = flagString(args, "host").trim();
9934
11572
  const ip = flagString(args, "ip").trim();
9935
11573
  if (!host || !ip) {
9936
- process.stderr.write("\u7F3A\u5C11\u53C2\u6570\uFF1A--host \u4E0E --ip \u90FD\u662F\u5FC5\u586B\n\n" + HELP);
11574
+ process.stderr.write("\u7F3A\u5C11\u53C2\u6570\uFF1A--host \u4E0E --ip \u90FD\u662F\u5FC5\u586B\n\n" + HELP2);
9937
11575
  process.exitCode = 1;
9938
11576
  return;
9939
11577
  }
@@ -9981,14 +11619,14 @@ async function runTestCommand(args) {
9981
11619
  }
9982
11620
  if (results.some((r) => !r.ok)) process.exitCode = 1;
9983
11621
  }
9984
- var HELP;
11622
+ var HELP2;
9985
11623
  var init_single_command = __esm({
9986
11624
  "src/scan/single-command.ts"() {
9987
11625
  "use strict";
9988
11626
  init_args();
9989
11627
  init_version();
9990
11628
  init_single();
9991
- HELP = `
11629
+ HELP2 = `
9992
11630
  ${NAME} test \u2014\u2014 \u6D4B\u8BD5\u5355\u4E2A IP \u7684\u5B8C\u6574\u94FE\u8DEF
9993
11631
 
9994
11632
  \u7528\u6CD5:
@@ -10025,7 +11663,7 @@ ${NAME} test \u2014\u2014 \u6D4B\u8BD5\u5355\u4E2A IP \u7684\u5B8C\u6574\u94FE\u
10025
11663
  import * as net7 from "node:net";
10026
11664
  import * as tls5 from "node:tls";
10027
11665
  import * as https from "node:https";
10028
- function fail(code, error) {
11666
+ function fail2(code, error) {
10029
11667
  return { ok: false, code, error };
10030
11668
  }
10031
11669
  function isPublicIp(value) {
@@ -10165,7 +11803,7 @@ function identifyEgress(options) {
10165
11803
  if (Buffer.byteLength(user) > 255 || Buffer.byteLength(password) > 255 || !user && password) throw new Error();
10166
11804
  }
10167
11805
  } catch {
10168
- return Promise.resolve(fail("config", "\u8BC6\u522B\u914D\u7F6E\u65E0\u6548\uFF1A\u9700\u8981 HTTPS\u3001\u6709\u6548\u77ED\u671F\u4EE4\u724C\u548C\u53EF\u9009 SOCKS5 \u5730\u5740"));
11806
+ return Promise.resolve(fail2("config", "\u8BC6\u522B\u914D\u7F6E\u65E0\u6548\uFF1A\u9700\u8981 HTTPS\u3001\u6709\u6548\u77ED\u671F\u4EE4\u724C\u548C\u53EF\u9009 SOCKS5 \u5730\u5740"));
10169
11807
  }
10170
11808
  return new Promise((resolve4) => {
10171
11809
  let settled = false;
@@ -10181,12 +11819,12 @@ function identifyEgress(options) {
10181
11819
  agent.destroy();
10182
11820
  resolve4(result);
10183
11821
  };
10184
- const timer = setTimeout(() => finish(fail("timeout", "\u51FA\u53E3\u8BC6\u522B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97")), timeoutMs);
11822
+ const timer = setTimeout(() => finish(fail2("timeout", "\u51FA\u53E3\u8BC6\u522B\u8D85\u8FC7\u603B\u8D85\u65F6\u9884\u7B97")), timeoutMs);
10185
11823
  if (proxy) {
10186
11824
  const selectedProxy = proxy;
10187
11825
  agent.createConnection = (_connectionOptions, callback) => {
10188
11826
  socket = net7.connect({ host: selectedProxy.hostname.replace(/^\[|\]$/g, ""), port: Number(selectedProxy.port || 1080) });
10189
- socket.once("error", () => finish(fail("transport", "SOCKS5 \u8FDE\u63A5\u5931\u8D25")));
11827
+ socket.once("error", () => finish(fail2("transport", "SOCKS5 \u8FDE\u63A5\u5931\u8D25")));
10190
11828
  socket.once("connect", () => {
10191
11829
  const raw = socket;
10192
11830
  void negotiateSocks(raw, selectedProxy, target).then(() => {
@@ -10194,9 +11832,9 @@ function identifyEgress(options) {
10194
11832
  const hostname = target.hostname.replace(/^\[|\]$/g, "");
10195
11833
  const secure = tls5.connect({ socket: raw, host: hostname, servername: net7.isIP(hostname) ? void 0 : hostname, rejectUnauthorized: true });
10196
11834
  socket = secure;
10197
- secure.once("error", () => finish(fail("transport", "\u8BC6\u522B\u670D\u52A1 TLS \u8FDE\u63A5\u5931\u8D25")));
11835
+ secure.once("error", () => finish(fail2("transport", "\u8BC6\u522B\u670D\u52A1 TLS \u8FDE\u63A5\u5931\u8D25")));
10198
11836
  callback?.(null, secure);
10199
- }).catch(() => finish(fail("transport", "SOCKS5 \u63E1\u624B\u5931\u8D25")));
11837
+ }).catch(() => finish(fail2("transport", "SOCKS5 \u63E1\u624B\u5931\u8D25")));
10200
11838
  });
10201
11839
  return void 0;
10202
11840
  };
@@ -10208,16 +11846,16 @@ function identifyEgress(options) {
10208
11846
  headers: { Accept: "application/json", "Accept-Encoding": "identity", "Cache-Control": "no-store", ...options.token ? { Authorization: `Bearer ${options.token}` } : {} }
10209
11847
  }, (response) => {
10210
11848
  if (response.statusCode !== 200) {
10211
- finish(fail("http", `\u8BC6\u522B\u670D\u52A1\u8FD4\u56DE HTTP ${response.statusCode ?? 0}`));
11849
+ finish(fail2("http", `\u8BC6\u522B\u670D\u52A1\u8FD4\u56DE HTTP ${response.statusCode ?? 0}`));
10212
11850
  return;
10213
11851
  }
10214
11852
  if (!/^application\/json(?:\s*;|$)/i.test(response.headers["content-type"] ?? "") || response.headers["content-encoding"] && response.headers["content-encoding"] !== "identity") {
10215
- finish(fail("response", "\u8BC6\u522B\u670D\u52A1\u5FC5\u987B\u8FD4\u56DE\u672A\u538B\u7F29\u7684 JSON"));
11853
+ finish(fail2("response", "\u8BC6\u522B\u670D\u52A1\u5FC5\u987B\u8FD4\u56DE\u672A\u538B\u7F29\u7684 JSON"));
10216
11854
  return;
10217
11855
  }
10218
11856
  const declared = response.headers["content-length"];
10219
11857
  if (declared && (!/^\d+$/.test(declared) || Number(declared) > MAX_IDENTITY_BYTES)) {
10220
- finish(fail("size", "\u8BC6\u522B\u54CD\u5E94\u8D85\u8FC7 16 KiB"));
11858
+ finish(fail2("size", "\u8BC6\u522B\u54CD\u5E94\u8D85\u8FC7 16 KiB"));
10221
11859
  return;
10222
11860
  }
10223
11861
  const chunks = [];
@@ -10225,28 +11863,28 @@ function identifyEgress(options) {
10225
11863
  response.on("data", (chunk) => {
10226
11864
  bytes += chunk.length;
10227
11865
  if (bytes > MAX_IDENTITY_BYTES) {
10228
- finish(fail("size", "\u8BC6\u522B\u54CD\u5E94\u8D85\u8FC7 16 KiB"));
11866
+ finish(fail2("size", "\u8BC6\u522B\u54CD\u5E94\u8D85\u8FC7 16 KiB"));
10229
11867
  return;
10230
11868
  }
10231
11869
  chunks.push(chunk);
10232
11870
  });
10233
- response.once("error", () => finish(fail("transport", "\u8BC6\u522B\u54CD\u5E94\u4F20\u8F93\u5931\u8D25")));
11871
+ response.once("error", () => finish(fail2("transport", "\u8BC6\u522B\u54CD\u5E94\u4F20\u8F93\u5931\u8D25")));
10234
11872
  response.once("end", () => {
10235
11873
  if (settled) return;
10236
11874
  try {
10237
11875
  const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks)));
10238
11876
  const observation = validateIdentityResponse(value, Date.now());
10239
11877
  if (!observation) {
10240
- finish(fail("response", "\u8BC6\u522B\u7ED3\u679C\u5B57\u6BB5\u6216\u516C\u7F51\u5730\u5740\u65E0\u6548"));
11878
+ finish(fail2("response", "\u8BC6\u522B\u7ED3\u679C\u5B57\u6BB5\u6216\u516C\u7F51\u5730\u5740\u65E0\u6548"));
10241
11879
  return;
10242
11880
  }
10243
11881
  finish({ ok: true, observation: { ...observation, sourceUrl: target.origin + target.pathname, transport: proxy ? "socks5" : "direct" } });
10244
11882
  } catch {
10245
- finish(fail("response", "\u8BC6\u522B\u54CD\u5E94\u4E0D\u662F\u6709\u6548 UTF-8 JSON"));
11883
+ finish(fail2("response", "\u8BC6\u522B\u54CD\u5E94\u4E0D\u662F\u6709\u6548 UTF-8 JSON"));
10246
11884
  }
10247
11885
  });
10248
11886
  });
10249
- request3.once("error", () => finish(fail("transport", "\u8BC6\u522B\u8BF7\u6C42\u8FDE\u63A5\u5931\u8D25")));
11887
+ request3.once("error", () => finish(fail2("transport", "\u8BC6\u522B\u8BF7\u6C42\u8FDE\u63A5\u5931\u8D25")));
10250
11888
  request3.end();
10251
11889
  });
10252
11890
  }
@@ -10268,7 +11906,7 @@ __export(egress_command_exports, {
10268
11906
  });
10269
11907
  async function runEgressIdentityCommand(args) {
10270
11908
  if (flagBool(args, "help") || flagBool(args, "h")) {
10271
- process.stdout.write(HELP2);
11909
+ process.stdout.write(HELP3);
10272
11910
  return;
10273
11911
  }
10274
11912
  const url = flagString(args, "url");
@@ -10288,13 +11926,13 @@ async function runEgressIdentityCommand(args) {
10288
11926
  `);
10289
11927
  if (!result.ok) process.exitCode = 1;
10290
11928
  }
10291
- var HELP2;
11929
+ var HELP3;
10292
11930
  var init_egress_command = __esm({
10293
11931
  "src/experimental/egress-command.ts"() {
10294
11932
  "use strict";
10295
11933
  init_args();
10296
11934
  init_egress_identity();
10297
- HELP2 = `
11935
+ HELP3 = `
10298
11936
  \u5B9E\u9A8C\u6027\u51FA\u53E3\u8BC6\u522B\uFF08\u4E0D\u53C2\u4E0E\u9ED8\u8BA4 scan \u6216\u5019\u9009\u6392\u5E8F\uFF09
10299
11937
 
10300
11938
  \u7528\u6CD5\uFF1Acfpilot egress-identify --url https://\u81EA\u6709\u670D\u52A1/identify [--proxy socks5://127.0.0.1:10808]
@@ -10499,7 +12137,7 @@ __export(website_command_exports, {
10499
12137
  });
10500
12138
  async function runWebsiteCommand(args) {
10501
12139
  if (flagBool(args, "help") || flagBool(args, "h")) {
10502
- process.stdout.write(HELP3);
12140
+ process.stdout.write(HELP4);
10503
12141
  return;
10504
12142
  }
10505
12143
  if (!flagString(args, "url") || args.flags["expected-text"] !== void 0 && typeof args.flags["expected-text"] !== "string" || args.flags.timeout !== void 0 && typeof args.flags.timeout !== "string") {
@@ -10516,13 +12154,13 @@ async function runWebsiteCommand(args) {
10516
12154
  `);
10517
12155
  if (targets.some((result) => result.status !== "ok")) process.exitCode = 1;
10518
12156
  }
10519
- var HELP3;
12157
+ var HELP4;
10520
12158
  var init_website_command = __esm({
10521
12159
  "src/experimental/website-command.ts"() {
10522
12160
  "use strict";
10523
12161
  init_args();
10524
12162
  init_website_compatibility();
10525
- HELP3 = `
12163
+ HELP4 = `
10526
12164
  \u5B9E\u9A8C\u6027\u7F51\u7AD9\u517C\u5BB9\u6027\u68C0\u6D4B\uFF08\u4E0D\u53C2\u4E0E\u9ED8\u8BA4 scan \u6216\u6392\u5E8F\uFF09
10527
12165
 
10528
12166
  \u7528\u6CD5\uFF1Acfpilot website-check --url https://\u7528\u6237\u6307\u5B9A\u7F51\u7AD9/ [--proxy socks5://127.0.0.1:10808]
@@ -10603,12 +12241,12 @@ var init_token_command = __esm({
10603
12241
  });
10604
12242
 
10605
12243
  // src/vps/command.ts
10606
- var command_exports3 = {};
10607
- __export(command_exports3, {
12244
+ var command_exports4 = {};
12245
+ __export(command_exports4, {
10608
12246
  runVpsCommand: () => runVpsCommand
10609
12247
  });
10610
12248
  import { spawn } from "node:child_process";
10611
- import { existsSync as existsSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
12249
+ import { existsSync as existsSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
10612
12250
  import { dirname as dirname4, resolve as resolve3 } from "node:path";
10613
12251
  import { fileURLToPath as fileURLToPath3 } from "node:url";
10614
12252
  function loadScript() {
@@ -10618,7 +12256,7 @@ function loadScript() {
10618
12256
  resolve3(here, "../../assets/vps-socks5.sh")
10619
12257
  ];
10620
12258
  for (const path of candidates) {
10621
- if (existsSync2(path)) return readFileSync5(path, "utf8");
12259
+ if (existsSync4(path)) return readFileSync7(path, "utf8");
10622
12260
  }
10623
12261
  throw new Error("\u5185\u7F6E\u811A\u672C\u7F3A\u5931\uFF08assets/vps-socks5.sh\uFF09\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6216\u5347\u7EA7 cfpilot");
10624
12262
  }
@@ -10650,7 +12288,7 @@ ssh \u542F\u52A8\u5931\u8D25\uFF1A${err.message}
10650
12288
  }
10651
12289
  async function runVpsCommand(args) {
10652
12290
  if (flagBool(args, "h") || flagBool(args, "help")) {
10653
- process.stdout.write(HELP4);
12291
+ process.stdout.write(HELP5);
10654
12292
  return;
10655
12293
  }
10656
12294
  const port = flagNumber(args, "port", 0);
@@ -10674,11 +12312,11 @@ async function runVpsCommand(args) {
10674
12312
  }
10675
12313
  return;
10676
12314
  }
10677
- const out = resolve3(process.cwd(), flagString(args, "out") ?? "cfpilot-vps-socks5.sh");
10678
- writeFileSync3(out, script, { mode: 493 });
12315
+ const out2 = resolve3(process.cwd(), flagString(args, "out") ?? "cfpilot-vps-socks5.sh");
12316
+ writeFileSync5(out2, script, { mode: 493 });
10679
12317
  process.stdout.write(
10680
12318
  `
10681
- \u5DF2\u751F\u6210\u811A\u672C\uFF1A${out}
12319
+ \u5DF2\u751F\u6210\u811A\u672C\uFF1A${out2}
10682
12320
 
10683
12321
  \u63A5\u4E0B\u6765\u4E8C\u9009\u4E00\uFF1A
10684
12322
 
@@ -10697,13 +12335,13 @@ async function runVpsCommand(args) {
10697
12335
  `
10698
12336
  );
10699
12337
  }
10700
- var HELP4;
10701
- var init_command3 = __esm({
12338
+ var HELP5;
12339
+ var init_command4 = __esm({
10702
12340
  "src/vps/command.ts"() {
10703
12341
  "use strict";
10704
12342
  init_args();
10705
12343
  init_version();
10706
- HELP4 = `
12344
+ HELP5 = `
10707
12345
  ${NAME} vps \u2014\u2014 \u5728\u81EA\u5DF1\u7684 VPS \u4E0A\u90E8\u7F72 SOCKS5 \u843D\u5730\u4EE3\u7406
10708
12346
 
10709
12347
  \u7528\u6CD5:
@@ -10736,7 +12374,7 @@ ${NAME} vps \u2014\u2014 \u5728\u81EA\u5DF1\u7684 VPS \u4E0A\u90E8\u7F72 SOCKS5
10736
12374
  // src/cli.ts
10737
12375
  init_args();
10738
12376
  init_version();
10739
- var HELP5 = `
12377
+ var HELP6 = `
10740
12378
  ${NAME} v${VERSION}
10741
12379
  Cloudflare Pages \u4EE3\u7406\u90E8\u7F72\u4E0E\u4F18\u9009\u5DE5\u5177
10742
12380
 
@@ -10744,6 +12382,7 @@ Cloudflare Pages \u4EE3\u7406\u90E8\u7F72\u4E0E\u4F18\u9009\u5DE5\u5177
10744
12382
  ${NAME} \u4EA4\u4E92\u83DC\u5355\uFF08\u63A8\u8350\u9996\u6B21\u4F7F\u7528\uFF09
10745
12383
  ${NAME} deploy [\u9009\u9879] \u90E8\u7F72 Pages \u53CC\u9879\u76EE
10746
12384
  ${NAME} scan [\u9009\u9879] \u672C\u5730\u771F\u8FDE\u63A5\u4F18\u9009
12385
+ ${NAME} source <\u52A8\u4F5C> \u5916\u90E8 IP \u6570\u636E\u6E90\u4E0E\u672C\u5730\u5019\u9009\u6C60\u7BA1\u7406
10747
12386
  ${NAME} test [\u9009\u9879] \u6D4B\u8BD5\u5355\u4E2A IP \u7684\u5B8C\u6574\u94FE\u8DEF
10748
12387
  ${NAME} egress-identify \u5B9E\u9A8C\u6027\u6307\u5B9A\u4F20\u8F93\u8DEF\u5F84\u51FA\u53E3\u8BC6\u522B
10749
12388
  ${NAME} website-check \u5B9E\u9A8C\u6027\u7F51\u7AD9\u517C\u5BB9\u6027\u68C0\u6D4B
@@ -10772,11 +12411,11 @@ async function main() {
10772
12411
  return;
10773
12412
  }
10774
12413
  if (!command && (flagBool(args, "h") || flagBool(args, "help"))) {
10775
- process.stdout.write(HELP5);
12414
+ process.stdout.write(HELP6);
10776
12415
  return;
10777
12416
  }
10778
12417
  if (command === "help") {
10779
- process.stdout.write(HELP5);
12418
+ process.stdout.write(HELP6);
10780
12419
  return;
10781
12420
  }
10782
12421
  switch (command) {
@@ -10796,6 +12435,11 @@ async function main() {
10796
12435
  await runScanCommand2(args);
10797
12436
  return;
10798
12437
  }
12438
+ case "source": {
12439
+ const { runSourceCommand: runSourceCommand2 } = await Promise.resolve().then(() => (init_command3(), command_exports3));
12440
+ await runSourceCommand2(args);
12441
+ return;
12442
+ }
10799
12443
  case "test": {
10800
12444
  const { runTestCommand: runTestCommand2 } = await Promise.resolve().then(() => (init_single_command(), single_command_exports));
10801
12445
  await runTestCommand2(args);
@@ -10827,7 +12471,7 @@ async function main() {
10827
12471
  return;
10828
12472
  }
10829
12473
  case "vps": {
10830
- const { runVpsCommand: runVpsCommand2 } = await Promise.resolve().then(() => (init_command3(), command_exports3));
12474
+ const { runVpsCommand: runVpsCommand2 } = await Promise.resolve().then(() => (init_command4(), command_exports4));
10831
12475
  await runVpsCommand2(args);
10832
12476
  return;
10833
12477
  }
@@ -10835,7 +12479,7 @@ async function main() {
10835
12479
  process.stderr.write(`\u672A\u77E5\u547D\u4EE4\uFF1A${command}
10836
12480
 
10837
12481
  `);
10838
- process.stderr.write(HELP5);
12482
+ process.stderr.write(HELP6);
10839
12483
  process.exitCode = 1;
10840
12484
  }
10841
12485
  }