cfpilot 0.7.2 → 0.8.0

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
@@ -1,12 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined") return require.apply(this, arguments);
8
- throw Error('Dynamic require of "' + x + '" is not supported');
9
- });
10
4
  var __esm = (fn, res) => function __init() {
11
5
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
6
  };
@@ -93,7 +87,7 @@ var VERSION, NAME;
93
87
  var init_version = __esm({
94
88
  "src/shared/version.ts"() {
95
89
  "use strict";
96
- VERSION = "0.7.2";
90
+ VERSION = "0.8.0";
97
91
  NAME = "cfpilot";
98
92
  }
99
93
  });
@@ -1360,6 +1354,317 @@ var init_token_check = __esm({
1360
1354
  }
1361
1355
  });
1362
1356
 
1357
+ // src/shared/version-util.ts
1358
+ function parseVersion(input) {
1359
+ const text = input.trim();
1360
+ if (!text) return null;
1361
+ const matched = VERSION_RE.exec(text);
1362
+ if (!matched) return null;
1363
+ const major = Number(matched[1]);
1364
+ const minor = matched[2] === void 0 ? 0 : Number(matched[2]);
1365
+ const patch = matched[3] === void 0 ? 0 : Number(matched[3]);
1366
+ if (!Number.isFinite(major) || !Number.isFinite(minor) || !Number.isFinite(patch)) {
1367
+ return null;
1368
+ }
1369
+ const rest = matched[4] ?? "";
1370
+ let prerelease = [];
1371
+ if (rest === "") {
1372
+ } else if (rest.startsWith("-")) {
1373
+ const pre = rest.slice(1);
1374
+ if (!pre) return null;
1375
+ prerelease = pre.split(".");
1376
+ } else if (rest.startsWith("+")) {
1377
+ } else {
1378
+ return null;
1379
+ }
1380
+ return { major, minor, patch, prerelease };
1381
+ }
1382
+ function compareSemver(a, b) {
1383
+ const va = parseVersion(a);
1384
+ const vb = parseVersion(b);
1385
+ if (!va && !vb) return 0;
1386
+ if (!va) return -1;
1387
+ if (!vb) return 1;
1388
+ if (va.major !== vb.major) return va.major > vb.major ? 1 : -1;
1389
+ if (va.minor !== vb.minor) return va.minor > vb.minor ? 1 : -1;
1390
+ if (va.patch !== vb.patch) return va.patch > vb.patch ? 1 : -1;
1391
+ return comparePrerelease(va.prerelease, vb.prerelease);
1392
+ }
1393
+ function comparePrerelease(a, b) {
1394
+ if (a.length === 0 && b.length === 0) return 0;
1395
+ if (a.length === 0) return 1;
1396
+ if (b.length === 0) return -1;
1397
+ const len = Math.max(a.length, b.length);
1398
+ for (let i = 0; i < len; i++) {
1399
+ const x = a[i];
1400
+ const y = b[i];
1401
+ if (x === void 0) return -1;
1402
+ if (y === void 0) return 1;
1403
+ const c2 = comparePrereleaseIdentifier(x, y);
1404
+ if (c2 !== 0) return c2;
1405
+ }
1406
+ return 0;
1407
+ }
1408
+ function comparePrereleaseIdentifier(a, b) {
1409
+ const aNumeric = /^\d+$/.test(a);
1410
+ const bNumeric = /^\d+$/.test(b);
1411
+ if (aNumeric && bNumeric) {
1412
+ const na = Number(a);
1413
+ const nb = Number(b);
1414
+ if (na !== nb) return na > nb ? 1 : -1;
1415
+ return 0;
1416
+ }
1417
+ if (aNumeric) return -1;
1418
+ if (bNumeric) return 1;
1419
+ if (a === b) return 0;
1420
+ return a < b ? -1 : 1;
1421
+ }
1422
+ var VERSION_RE;
1423
+ var init_version_util = __esm({
1424
+ "src/shared/version-util.ts"() {
1425
+ "use strict";
1426
+ VERSION_RE = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(.*)$/;
1427
+ }
1428
+ });
1429
+
1430
+ // src/deploy/kernel-remote.ts
1431
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
1432
+ import { homedir as homedir2 } from "node:os";
1433
+ import { dirname, join as join2, resolve } from "node:path";
1434
+ import { fileURLToPath } from "node:url";
1435
+ function versionFromTag(tag) {
1436
+ const text = tag.trim();
1437
+ for (const prefix of ["desktop-v", "gui-v", "v"]) {
1438
+ if (text.startsWith(prefix)) {
1439
+ const rest = text.slice(prefix.length);
1440
+ return /^\d+\.\d+\.\d+/.test(rest) ? rest : "";
1441
+ }
1442
+ }
1443
+ return "";
1444
+ }
1445
+ async function fetchRemoteKernelInfo(options = {}) {
1446
+ if (isRemoteDisabled()) return null;
1447
+ let releases;
1448
+ try {
1449
+ const response = await fetch(`${RELEASES_API}?per_page=20`, {
1450
+ headers: {
1451
+ Accept: "application/vnd.github+json",
1452
+ "User-Agent": "CFPilot-CLI"
1453
+ },
1454
+ signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
1455
+ });
1456
+ if (!response.ok) return null;
1457
+ const payload = await response.json();
1458
+ if (!Array.isArray(payload)) return null;
1459
+ releases = payload.filter(isGitHubRelease);
1460
+ } catch {
1461
+ return null;
1462
+ }
1463
+ const sorted = releases.filter((release) => !release.draft && !release.prerelease).map((release) => ({ release, version: versionFromTag(release.tag_name) })).filter((item) => item.version !== "").sort((a, b) => compareSemver(b.version, a.version));
1464
+ for (const item of sorted) {
1465
+ const controlUrl = findAssetUrl(item.release.assets ?? [], CONTROL_ASSET_NAME);
1466
+ const dataUrl = findAssetUrl(item.release.assets ?? [], DATA_ASSET_NAME);
1467
+ if (!controlUrl || !dataUrl) {
1468
+ continue;
1469
+ }
1470
+ return { version: item.version, controlUrl, dataUrl };
1471
+ }
1472
+ return null;
1473
+ }
1474
+ function findAssetUrl(assets, name) {
1475
+ for (const asset of assets) {
1476
+ if (asset.name.trim().toLowerCase() === name) return asset.browser_download_url;
1477
+ }
1478
+ return "";
1479
+ }
1480
+ function isRemoteDisabled() {
1481
+ const raw = process.env[REMOTE_OFF_ENV]?.trim().toLowerCase();
1482
+ if (!raw) return false;
1483
+ return ["0", "false", "no", "off"].includes(raw);
1484
+ }
1485
+ function isGitHubRelease(value) {
1486
+ if (typeof value !== "object" || value === null) return false;
1487
+ const item = value;
1488
+ if (typeof item.tag_name !== "string") return false;
1489
+ if (item.assets !== void 0 && !Array.isArray(item.assets)) return false;
1490
+ return true;
1491
+ }
1492
+ async function downloadAsset(url, timeoutMs) {
1493
+ if (!url.trim()) throw new Error("\u4E0B\u8F7D\u5730\u5740\u4E3A\u7A7A");
1494
+ const response = await fetch(url, {
1495
+ headers: { "User-Agent": "CFPilot-CLI" },
1496
+ signal: AbortSignal.timeout(timeoutMs)
1497
+ });
1498
+ if (!response.ok) {
1499
+ throw new Error(`\u4E0B\u8F7D\u5931\u8D25\uFF1AHTTP ${response.status}`);
1500
+ }
1501
+ const declared = response.headers.get("content-length");
1502
+ if (declared) {
1503
+ const size = Number(declared);
1504
+ if (Number.isFinite(size) && size > MAX_ASSET_BYTES) {
1505
+ throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
1506
+ }
1507
+ }
1508
+ return await readBodyWithLimit(response);
1509
+ }
1510
+ async function readBodyWithLimit(response) {
1511
+ const body = response.body;
1512
+ if (!body) {
1513
+ const text = await response.text();
1514
+ if (Buffer.byteLength(text) > MAX_ASSET_BYTES) {
1515
+ throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
1516
+ }
1517
+ return text;
1518
+ }
1519
+ const reader = body.getReader();
1520
+ const decoder = new TextDecoder();
1521
+ let total = 0;
1522
+ let out = "";
1523
+ try {
1524
+ for (; ; ) {
1525
+ const { done, value } = await reader.read();
1526
+ if (done) break;
1527
+ if (!value) continue;
1528
+ const chunk = value;
1529
+ total += chunk.byteLength;
1530
+ if (total > MAX_ASSET_BYTES) {
1531
+ await reader.cancel().catch(() => void 0);
1532
+ throw new Error(`\u5185\u6838\u4EA7\u7269\u8D85\u8FC7 ${MAX_ASSET_BYTES} \u5B57\u8282\u4E0A\u9650\uFF0C\u7591\u4F3C\u5F02\u5E38\u5185\u5BB9`);
1533
+ }
1534
+ out += decoder.decode(chunk, { stream: true });
1535
+ }
1536
+ } finally {
1537
+ reader.releaseLock();
1538
+ }
1539
+ out += decoder.decode();
1540
+ return out;
1541
+ }
1542
+ function cacheRoot() {
1543
+ const override = process.env[CACHE_DIR_ENV]?.trim();
1544
+ if (override) return override;
1545
+ return join2(homedir2(), ".cfpilot", "kernel");
1546
+ }
1547
+ function cacheDir(version) {
1548
+ return join2(cacheRoot(), version);
1549
+ }
1550
+ async function readCached(path) {
1551
+ try {
1552
+ const text = await readFile(path, "utf8");
1553
+ return text.length > 0 ? text : null;
1554
+ } catch {
1555
+ return null;
1556
+ }
1557
+ }
1558
+ async function writeCached(path, content) {
1559
+ await mkdir(dirname(path), { recursive: true });
1560
+ const tmp = `${path}.tmp`;
1561
+ await writeFile(tmp, content, "utf8");
1562
+ try {
1563
+ await rename(tmp, path);
1564
+ } catch {
1565
+ await writeFile(path, content, "utf8").catch(() => void 0);
1566
+ }
1567
+ }
1568
+ function moduleDir() {
1569
+ try {
1570
+ const meta = import.meta;
1571
+ if (meta && typeof meta.url === "string") return dirname(fileURLToPath(meta.url));
1572
+ } catch {
1573
+ }
1574
+ return typeof __dirname === "string" ? __dirname : process.cwd();
1575
+ }
1576
+ async function loadBuiltinBundle(fileName) {
1577
+ const override = process.env[LOCAL_DIR_ENV]?.trim();
1578
+ const candidates = override ? [resolve(override, fileName)] : [
1579
+ resolve(moduleDir(), `../worker-core/dist/${fileName}`),
1580
+ resolve(moduleDir(), `../../worker-core/dist/${fileName}`),
1581
+ resolve(moduleDir(), `../assets/${fileName}`),
1582
+ resolve(moduleDir(), `../../assets/${fileName}`),
1583
+ resolve(process.cwd(), `packages/worker-core/dist/${fileName}`)
1584
+ ];
1585
+ for (const candidate of candidates) {
1586
+ try {
1587
+ const text = await readFile(candidate, "utf8");
1588
+ if (text.length > 0) return text;
1589
+ } catch {
1590
+ }
1591
+ }
1592
+ throw new Error(
1593
+ `\u672A\u627E\u5230 ${fileName}\uFF0C\u8BF7\u5148\u6267\u884C npm run build -w @cfpilot/worker-core`
1594
+ );
1595
+ }
1596
+ function extractBuildVersion(source) {
1597
+ const matched = BUILD_RE.exec(source);
1598
+ if (matched?.[1]) return matched[1];
1599
+ const numeric = BUILD_NUMERIC_RE.exec(source);
1600
+ if (numeric?.[1]) return numeric[1];
1601
+ return "";
1602
+ }
1603
+ async function loadKernelBundle(currentVersion, options = {}) {
1604
+ const log = options.log ?? (() => {
1605
+ });
1606
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
1607
+ const remote = await fetchRemoteKernelInfo({ timeoutMs });
1608
+ if (remote && compareSemver(remote.version, currentVersion) > 0) {
1609
+ try {
1610
+ const bundle = await fetchRemoteKernel(remote, timeoutMs);
1611
+ return {
1612
+ control: bundle.control,
1613
+ data: bundle.data,
1614
+ version: remote.version,
1615
+ source: `\u8FDC\u7A0B ${remote.version}`
1616
+ };
1617
+ } catch (err) {
1618
+ log(
1619
+ `\xB7 \u8FDC\u7A0B\u5185\u6838 ${remote.version} \u83B7\u53D6\u5931\u8D25\uFF0C\u6539\u7528\u5185\u7F6E\u5185\u6838\uFF1A` + (err instanceof Error ? err.message : String(err))
1620
+ );
1621
+ }
1622
+ }
1623
+ const control = await loadBuiltinBundle("control.js");
1624
+ const data = await loadBuiltinBundle("dataplane.js");
1625
+ return {
1626
+ control,
1627
+ data,
1628
+ version: currentVersion,
1629
+ source: `\u5185\u7F6E ${currentVersion}`
1630
+ };
1631
+ }
1632
+ async function fetchRemoteKernel(info, timeoutMs) {
1633
+ const dir = cacheDir(info.version);
1634
+ const controlPath = join2(dir, "control.js");
1635
+ const dataPath = join2(dir, "dataplane.js");
1636
+ const cachedControl = await readCached(controlPath);
1637
+ const cachedData = await readCached(dataPath);
1638
+ if (cachedControl && cachedData) {
1639
+ return { control: cachedControl, data: cachedData };
1640
+ }
1641
+ const control = cachedControl ?? await downloadAsset(info.controlUrl, timeoutMs);
1642
+ const data = cachedData ?? await downloadAsset(info.dataUrl, timeoutMs);
1643
+ if (!control.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u63A7\u5236\u9762\u4EA7\u7269\u4E3A\u7A7A");
1644
+ if (!data.trim()) throw new Error("\u4E0B\u8F7D\u5230\u7684\u6570\u636E\u9762\u4EA7\u7269\u4E3A\u7A7A");
1645
+ await writeCached(controlPath, control).catch(() => void 0);
1646
+ await writeCached(dataPath, data).catch(() => void 0);
1647
+ return { control, data };
1648
+ }
1649
+ var CONTROL_ASSET_NAME, DATA_ASSET_NAME, REPO, RELEASES_API, DEFAULT_TIMEOUT_MS, MAX_ASSET_BYTES, CACHE_DIR_ENV, LOCAL_DIR_ENV, REMOTE_OFF_ENV, BUILD_RE, BUILD_NUMERIC_RE;
1650
+ var init_kernel_remote = __esm({
1651
+ "src/deploy/kernel-remote.ts"() {
1652
+ "use strict";
1653
+ init_version_util();
1654
+ CONTROL_ASSET_NAME = "cfpilot-kernel-control.js";
1655
+ DATA_ASSET_NAME = "cfpilot-kernel-dataplane.js";
1656
+ REPO = "xmwengxing/CFPilot";
1657
+ RELEASES_API = process.env.CFPILOT_KERNEL_API_BASE ?? `https://api.github.com/repos/${REPO}/releases`;
1658
+ DEFAULT_TIMEOUT_MS = 2e4;
1659
+ MAX_ASSET_BYTES = 10 * 1024 * 1024;
1660
+ CACHE_DIR_ENV = "CFPILOT_KERNEL_CACHE_DIR";
1661
+ LOCAL_DIR_ENV = "CFPILOT_KERNEL_DIR";
1662
+ REMOTE_OFF_ENV = "CFPILOT_KERNEL_REMOTE";
1663
+ BUILD_RE = /["']([0-9a-f]{7,10}-(?:[0-9a-f]{4,16}|[0-9]{12}))["']/;
1664
+ BUILD_NUMERIC_RE = /["'](\d{10,14})["']/;
1665
+ }
1666
+ });
1667
+
1363
1668
  // src/deploy/pages-deploy.ts
1364
1669
  var pages_deploy_exports = {};
1365
1670
  __export(pages_deploy_exports, {
@@ -1370,9 +1675,6 @@ __export(pages_deploy_exports, {
1370
1675
  listCfPilotNamespaces: () => listCfPilotNamespaces,
1371
1676
  readManifest: () => readManifest
1372
1677
  });
1373
- import { readFile } from "node:fs/promises";
1374
- import { dirname, resolve } from "node:path";
1375
- import { fileURLToPath } from "node:url";
1376
1678
  import { randomBytes as randomBytes2, randomUUID } from "node:crypto";
1377
1679
  async function readManifest(client, accountId, namespaceId) {
1378
1680
  try {
@@ -1504,31 +1806,55 @@ async function writeEffectiveConfig(client, accountId, namespaceId, effective, o
1504
1806
  );
1505
1807
  }
1506
1808
  }
1507
- function moduleDir() {
1508
- try {
1509
- const meta = import.meta;
1510
- if (meta && typeof meta.url === "string") return dirname(fileURLToPath(meta.url));
1511
- } catch {
1512
- }
1513
- return typeof __dirname === "string" ? __dirname : process.cwd();
1514
- }
1515
- async function loadBundle(fileName) {
1516
- const here = moduleDir();
1517
- const candidates = [
1518
- resolve(here, `../worker-core/dist/${fileName}`),
1519
- resolve(here, `../../worker-core/dist/${fileName}`),
1520
- resolve(here, `../assets/${fileName}`),
1521
- resolve(process.cwd(), `packages/worker-core/dist/${fileName}`)
1522
- ];
1523
- for (const candidate of candidates) {
1809
+ async function resolveKernel(options, log, warnings) {
1810
+ const explicitControl = options.bundles?.control ?? "";
1811
+ const explicitData = options.bundles?.data ?? "";
1812
+ if (explicitControl || explicitData) {
1524
1813
  try {
1525
- return await readFile(candidate, "utf8");
1526
- } catch {
1814
+ const control = explicitControl || await loadBuiltinBundle("control.js");
1815
+ const data = explicitData || await loadBuiltinBundle("dataplane.js");
1816
+ return {
1817
+ control,
1818
+ data,
1819
+ version: options.kernelVersion ?? "",
1820
+ build: extractBuildVersion(control),
1821
+ source: "\u8C03\u7528\u65B9\u6307\u5B9A"
1822
+ };
1823
+ } catch (err) {
1824
+ warnings.push(
1825
+ `\u5185\u6838\u4EA7\u7269\u52A0\u8F7D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
1826
+ );
1827
+ return {
1828
+ control: explicitControl,
1829
+ data: explicitData,
1830
+ version: options.kernelVersion ?? "",
1831
+ build: extractBuildVersion(explicitControl),
1832
+ source: "\u4E0D\u53EF\u7528"
1833
+ };
1527
1834
  }
1528
1835
  }
1529
- throw new Error(
1530
- `\u672A\u627E\u5230 ${fileName}\uFF0C\u8BF7\u5148\u6267\u884C npm run build -w @cfpilot/worker-core`
1531
- );
1836
+ try {
1837
+ const bundle = await loadKernelBundle(VERSION, { log });
1838
+ log(`\xB7 \u5185\u6838\u6765\u6E90\uFF1A${bundle.source}`);
1839
+ return {
1840
+ control: bundle.control,
1841
+ data: bundle.data,
1842
+ version: options.kernelVersion ?? bundle.version,
1843
+ build: extractBuildVersion(bundle.control),
1844
+ source: bundle.source
1845
+ };
1846
+ } catch (err) {
1847
+ warnings.push(
1848
+ `\u5185\u6838\u4EA7\u7269\u52A0\u8F7D\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
1849
+ );
1850
+ return {
1851
+ control: "",
1852
+ data: "",
1853
+ version: options.kernelVersion ?? "",
1854
+ build: "",
1855
+ source: "\u4E0D\u53EF\u7528"
1856
+ };
1857
+ }
1532
1858
  }
1533
1859
  function validateOptions(options) {
1534
1860
  const problems = [];
@@ -1602,6 +1928,8 @@ async function deployPagesSplit(options) {
1602
1928
  warnings
1603
1929
  };
1604
1930
  const kv = { KV: { namespace_id: options.kvNamespaceId } };
1931
+ const kernel = await resolveKernel(options, log, warnings);
1932
+ const effectiveBuild = kernel.build || (options.localBuild ?? "").trim();
1605
1933
  const manifest = await readManifest(client, options.accountId, options.kvNamespaceId);
1606
1934
  let effective = {
1607
1935
  panelPath: options.panelPath,
@@ -1634,16 +1962,29 @@ async function deployPagesSplit(options) {
1634
1962
  log(` \xB7 UUID\uFF1A${effective.uuid}`);
1635
1963
  log(` \xB7 WS \u8DEF\u5F84\uFF1A${effective.wsPath}`);
1636
1964
  }
1637
- if (skipSameVersion && options.localBuild && manifest.build === options.localBuild) {
1638
- log(`\u2705 \u7EBF\u4E0A\u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF08${options.localBuild}\uFF09\uFF0C\u8DF3\u8FC7\u90E8\u7F72`);
1965
+ const onlineBuild = manifest.build?.trim() ?? "";
1966
+ const onlineVersion = manifest.kernelVersion?.trim() ?? "";
1967
+ const sameBuild = !!effectiveBuild && onlineBuild === effectiveBuild;
1968
+ const wouldDowngrade = !!onlineVersion && !!kernel.version && compareSemver(kernel.version, onlineVersion) < 0;
1969
+ if (skipSameVersion && (sameBuild || wouldDowngrade)) {
1970
+ if (wouldDowngrade && !sameBuild) {
1971
+ log(
1972
+ `\u2705 \u7EBF\u4E0A\u5185\u6838 ${onlineVersion} \u6BD4\u672C\u6B21\u53EF\u7528\u5185\u6838 ${kernel.version} \u66F4\u65B0\uFF0C\u8DF3\u8FC7\u90E8\u7F72\uFF08\u907F\u514D\u964D\u7EA7\uFF09`
1973
+ );
1974
+ } else {
1975
+ log(`\u2705 \u7EBF\u4E0A\u5DF2\u662F\u6700\u65B0\u7248\u672C\uFF08${effectiveBuild}\uFF09\uFF0C\u8DF3\u8FC7\u90E8\u7F72`);
1976
+ }
1639
1977
  result.panelPath = effective.panelPath;
1640
1978
  result.uuid = effective.uuid;
1641
1979
  result.wsPath = effective.wsPath;
1642
1980
  result.panelPassword = effective.panelPassword;
1643
1981
  return result;
1644
1982
  }
1645
- if (manifest.build && options.localBuild && manifest.build !== options.localBuild) {
1646
- log(`\xB7 \u7248\u672C\u53D8\u5316\uFF1A${manifest.build} \u2192 ${options.localBuild}`);
1983
+ if (onlineBuild && effectiveBuild && onlineBuild !== effectiveBuild) {
1984
+ log(`\xB7 \u7248\u672C\u53D8\u5316\uFF1A${onlineBuild} \u2192 ${effectiveBuild}`);
1985
+ }
1986
+ if (onlineVersion && kernel.version && onlineVersion !== kernel.version) {
1987
+ log(`\xB7 \u5185\u6838\u7248\u672C\u53D8\u5316\uFF1A${onlineVersion} \u2192 ${kernel.version}`);
1647
1988
  }
1648
1989
  } else if (manifest && mode === "fresh") {
1649
1990
  log("\xB7 \u6307\u5B9A\u4E86\u9996\u6B21\u90E8\u7F72\u6A21\u5F0F\uFF0C\u5FFD\u7565\u5DF2\u6709\u6E05\u5355");
@@ -1715,22 +2056,8 @@ async function deployPagesSplit(options) {
1715
2056
  warnings,
1716
2057
  log
1717
2058
  );
1718
- let dataCode = options.bundles?.data ?? "";
1719
- let controlCode = options.bundles?.control ?? "";
1720
- if (!dataCode) {
1721
- try {
1722
- dataCode = await loadBundle("dataplane.js");
1723
- } catch (err) {
1724
- warnings.push(err instanceof Error ? err.message : String(err));
1725
- }
1726
- }
1727
- if (!controlCode) {
1728
- try {
1729
- controlCode = await loadBundle("control.js");
1730
- } catch (err) {
1731
- warnings.push(err instanceof Error ? err.message : String(err));
1732
- }
1733
- }
2059
+ const dataCode = kernel.data;
2060
+ const controlCode = kernel.control;
1734
2061
  let dataCustomDomain = "";
1735
2062
  if (previousDataProject) {
1736
2063
  const isCustom = (d) => typeof d === "string" && !d.endsWith(".pages.dev");
@@ -1807,7 +2134,8 @@ async function deployPagesSplit(options) {
1807
2134
  result.control.subdomain = controlAttempt.subdomain;
1808
2135
  }
1809
2136
  if (result.control.subdomain && result.data.subdomain) {
1810
- const build = (options.localBuild ?? "").trim();
2137
+ const build = effectiveBuild;
2138
+ const kernelVersion = kernel.version.trim();
1811
2139
  await writeManifest(client, options.accountId, options.kvNamespaceId, {
1812
2140
  v: 1,
1813
2141
  kvNamespaceId: options.kvNamespaceId,
@@ -1818,6 +2146,7 @@ async function deployPagesSplit(options) {
1818
2146
  // 自定义域名:本次迁过来的,或旧项目上原有的(下次更新还要靠它迁移)
1819
2147
  dataCustomDomain: dataCustomDomain || manifest?.dataCustomDomain || "",
1820
2148
  build,
2149
+ kernelVersion,
1821
2150
  at: (/* @__PURE__ */ new Date()).toISOString(),
1822
2151
  credentials: {
1823
2152
  panelPath: effective.panelPath,
@@ -1967,6 +2296,9 @@ var init_pages_deploy = __esm({
1967
2296
  "use strict";
1968
2297
  init_cf_api();
1969
2298
  init_utils();
2299
+ init_kernel_remote();
2300
+ init_version_util();
2301
+ init_version();
1970
2302
  MANIFEST_KEY = "CFP_DEPLOY_MANIFEST";
1971
2303
  }
1972
2304
  });
@@ -2056,14 +2388,17 @@ async function listKvInstances(client, accountId) {
2056
2388
  `);
2057
2389
  const instances = await listCfPilotNamespaces(client, accountId);
2058
2390
  const instanceIds = new Set(instances.map((i) => i.id));
2391
+ const remote = await fetchRemoteKernelInfo({ timeoutMs: 8e3 });
2059
2392
  for (const ns of namespaces) {
2060
2393
  const instance = instances.find((i) => i.id === ns.id);
2061
2394
  if (instance) {
2395
+ const online = instance.manifest.kernelVersion?.trim() || "\u672A\u77E5";
2062
2396
  process.stdout.write(
2063
2397
  ` \u25CF ${ns.id} ${ns.title}
2064
2398
  \u5B9E\u4F8B\uFF1A\u63A7\u5236\u9762 ${instance.manifest.controlProject} / \u6570\u636E\u9762 ${instance.manifest.dataProject}
2065
2399
  \u57DF\u540D\uFF1A${instance.manifest.controlSubdomain} / ${instance.manifest.dataSubdomain}
2066
2400
  \u90E8\u7F72\u4E8E ${instance.manifest.at}\uFF0C\u7248\u672C ${instance.manifest.build}
2401
+ \u5185\u6838\u7248\u672C\uFF1A\u7EBF\u4E0A ${online} \uFF5C \u5185\u7F6E ${VERSION} \uFF5C \u8FDC\u7A0B ${remote?.version ?? "\u672A\u77E5"}
2067
2402
  `
2068
2403
  );
2069
2404
  } else {
@@ -2071,6 +2406,13 @@ async function listKvInstances(client, accountId) {
2071
2406
  `);
2072
2407
  }
2073
2408
  }
2409
+ if (remote) {
2410
+ const cmp = compareSemver(remote.version, VERSION);
2411
+ const hint = cmp > 0 ? `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u6BD4\u5185\u7F6E ${VERSION} \u66F4\u65B0\uFF0C\u90E8\u7F72\u65F6\u4F1A\u81EA\u52A8\u4F7F\u7528\u8FDC\u7A0B\u5185\u6838\u3002` : cmp === 0 ? `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u4E0E\u5185\u7F6E\u7248\u672C\u4E00\u81F4\u3002` : `\u8FDC\u7A0B\u5185\u6838 ${remote.version} \u6BD4\u5185\u7F6E ${VERSION} \u65E7\uFF0C\u5C06\u4F7F\u7528\u5185\u7F6E\u5185\u6838\u3002`;
2412
+ process.stdout.write(`
2413
+ ${hint}
2414
+ `);
2415
+ }
2074
2416
  process.stdout.write(
2075
2417
  `
2076
2418
  \u5171 ${instances.length} \u4E2A CFPilot \u5B9E\u4F8B\u3002
@@ -2217,23 +2559,8 @@ ${"\u2500".repeat(52)}
2217
2559
  }
2218
2560
  async function readLocalBuild() {
2219
2561
  try {
2220
- const { readFile: readFile2 } = await import("node:fs/promises");
2221
- const { dirname: dirname2, resolve: resolve2 } = await import("node:path");
2222
- const { fileURLToPath: fileURLToPath2 } = await import("node:url");
2223
- const here = dirname2(fileURLToPath2(import.meta.url));
2224
- const candidates = [
2225
- resolve2(here, "../worker-core/dist/control.js"),
2226
- resolve2(here, "../../worker-core/dist/control.js"),
2227
- resolve2(process.cwd(), "packages/worker-core/dist/control.js")
2228
- ];
2229
- for (const candidate of candidates) {
2230
- try {
2231
- const code = await readFile2(candidate, "utf8");
2232
- const m = /["']([0-9a-f]{7,10}-\d{12})["']/.exec(code);
2233
- if (m) return m[1];
2234
- } catch {
2235
- }
2236
- }
2562
+ const code = await loadBuiltinBundle("control.js");
2563
+ return extractBuildVersion(code) || void 0;
2237
2564
  } catch {
2238
2565
  }
2239
2566
  return void 0;
@@ -2244,8 +2571,11 @@ var init_command = __esm({
2244
2571
  init_args();
2245
2572
  init_cf_api();
2246
2573
  init_pages_deploy();
2574
+ init_kernel_remote();
2247
2575
  init_utils();
2248
2576
  init_help();
2577
+ init_version_util();
2578
+ init_version();
2249
2579
  }
2250
2580
  });
2251
2581
 
@@ -2803,7 +3133,9 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2803
3133
  let headerEnd = -1;
2804
3134
  let received = 0;
2805
3135
  let settled = false;
2806
- let buffer = "";
3136
+ let headerBuf = Buffer.alloc(0);
3137
+ let status2 = 0;
3138
+ const minPayload = Math.min(bytes, 32 * 1024);
2807
3139
  const finish = (result) => {
2808
3140
  if (settled) return;
2809
3141
  settled = true;
@@ -2814,11 +3146,21 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2814
3146
  }
2815
3147
  resolve2({ ...result, ms: Date.now() - started });
2816
3148
  };
3149
+ const judge = () => {
3150
+ if (status2 !== 200) {
3151
+ return { ok: false, error: status2 === 0 ? "\u672A\u6536\u5230\u54CD\u5E94\u5934" : `HTTP ${status2}` };
3152
+ }
3153
+ if (received < minPayload) {
3154
+ return { ok: false, error: `\u8F7D\u8377\u4E0D\u8DB3\uFF08${received}/${minPayload} \u5B57\u8282\uFF09` };
3155
+ }
3156
+ return { ok: true };
3157
+ };
2817
3158
  const request = [
2818
3159
  `GET ${path}?bytes=${bytes} HTTP/1.1`,
2819
3160
  `Host: ${host}`,
2820
3161
  `User-Agent: ${USER_AGENT}`,
2821
- `Accept: */*`,
3162
+ "Accept: */*",
3163
+ "Accept-Encoding: identity",
2822
3164
  "",
2823
3165
  ""
2824
3166
  ].join("\r\n");
@@ -2836,20 +3178,22 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2836
3178
  );
2837
3179
  const timer = setTimeout(() => {
2838
3180
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
3181
+ const v = judge();
2839
3182
  finish({
2840
- ok: received > 0,
3183
+ ok: v.ok,
2841
3184
  bytes: received,
2842
- speedMBps: received / 1024 / 1024 / seconds,
2843
- error: received > 0 ? void 0 : "\u6D4B\u901F\u8D85\u65F6"
3185
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
3186
+ error: v.ok ? void 0 : v.error ?? "\u4E0B\u8F7D\u8D85\u65F6"
2844
3187
  });
2845
3188
  }, timeoutMs);
2846
3189
  socket.setTimeout(timeoutMs, () => {
2847
3190
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
3191
+ const v = judge();
2848
3192
  finish({
2849
- ok: received > 0,
3193
+ ok: v.ok,
2850
3194
  bytes: received,
2851
- speedMBps: received / 1024 / 1024 / seconds,
2852
- error: received > 0 ? void 0 : "\u6D4B\u901F\u8D85\u65F6"
3195
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
3196
+ error: v.ok ? void 0 : v.error ?? "\u4E0B\u8F7D\u8D85\u65F6"
2853
3197
  });
2854
3198
  });
2855
3199
  socket.on("error", (err) => {
@@ -2858,20 +3202,34 @@ function measureDownload(ip, port, host, bytes, timeoutMs = 12e3, path = "/__edg
2858
3202
  const settle = () => {
2859
3203
  if (settled) return;
2860
3204
  const seconds = Math.max(1e-3, (Date.now() - started) / 1e3);
2861
- finish({ ok: received > 0, bytes: received, speedMBps: received / 1024 / 1024 / seconds });
3205
+ const v = judge();
3206
+ finish({
3207
+ ok: v.ok,
3208
+ bytes: received,
3209
+ speedMBps: v.ok ? received / 1024 / 1024 / seconds : 0,
3210
+ error: v.ok ? void 0 : v.error ?? "\u672A\u6536\u5230\u5B8C\u6574\u54CD\u5E94"
3211
+ });
2862
3212
  };
2863
3213
  socket.on("data", (chunk) => {
2864
3214
  if (headerEnd < 0) {
2865
- buffer += chunk.toString("latin1");
2866
- const idx = buffer.indexOf("\r\n\r\n");
3215
+ headerBuf = headerBuf.length === 0 ? chunk : Buffer.concat([headerBuf, chunk]);
3216
+ const idx = headerBuf.indexOf("\r\n\r\n");
2867
3217
  if (idx < 0) {
2868
- if (buffer.length > 8192) finish({ ok: false, bytes: 0, speedMBps: 0, error: "\u54CD\u5E94\u5934\u5F02\u5E38" });
3218
+ if (headerBuf.length > 8192) finish({ ok: false, bytes: 0, speedMBps: 0, error: "\u54CD\u5E94\u5934\u5F02\u5E38" });
3219
+ return;
3220
+ }
3221
+ const head = headerBuf.subarray(0, idx).toString("latin1");
3222
+ const code = /^HTTP\/1\.[01]\s+(\d{3})/.exec(head)?.[1];
3223
+ status2 = code ? Number(code) : 0;
3224
+ if (status2 !== 200) {
3225
+ finish({ ok: false, bytes: 0, speedMBps: 0, error: `HTTP ${status2 || "?"}` });
2869
3226
  return;
2870
3227
  }
2871
3228
  headerEnd = idx + 4;
2872
- const body = Buffer.from(buffer, "latin1").subarray(headerEnd);
3229
+ const body = headerBuf.subarray(headerEnd);
2873
3230
  received += body.byteLength;
2874
3231
  headerEnd = 0;
3232
+ headerBuf = Buffer.alloc(0);
2875
3233
  } else {
2876
3234
  received += chunk.byteLength;
2877
3235
  }
@@ -2947,7 +3305,7 @@ function measureThroughput(options) {
2947
3305
  ].join("\r\n");
2948
3306
  const openOne = () => {
2949
3307
  let headerDone = false;
2950
- let headerBuffer = "";
3308
+ let headerBuffer = Buffer.alloc(0);
2951
3309
  const socket = tls.connect(
2952
3310
  {
2953
3311
  host: ip,
@@ -2973,7 +3331,7 @@ function measureThroughput(options) {
2973
3331
  });
2974
3332
  socket.on("data", (chunk) => {
2975
3333
  if (!headerDone) {
2976
- headerBuffer += chunk.toString("latin1");
3334
+ headerBuffer = headerBuffer.length === 0 ? chunk : Buffer.concat([headerBuffer, chunk]);
2977
3335
  const idx = headerBuffer.indexOf("\r\n\r\n");
2978
3336
  if (idx < 0) {
2979
3337
  if (headerBuffer.length > 8192) {
@@ -2982,7 +3340,7 @@ function measureThroughput(options) {
2982
3340
  }
2983
3341
  return;
2984
3342
  }
2985
- const head = headerBuffer.slice(0, idx);
3343
+ const head = headerBuffer.subarray(0, idx).toString("latin1");
2986
3344
  const status2 = /^HTTP\/1\.[01]\s+(\d{3})/.exec(head)?.[1];
2987
3345
  if (status2 !== "200") {
2988
3346
  lastError = `HTTP ${status2 ?? "?"}`;
@@ -2990,10 +3348,10 @@ function measureThroughput(options) {
2990
3348
  return;
2991
3349
  }
2992
3350
  headerDone = true;
2993
- const body = Buffer.from(headerBuffer, "latin1").subarray(idx + 4);
3351
+ const body = headerBuffer.subarray(idx + 4);
2994
3352
  totalBytes += body.byteLength;
2995
3353
  windowBytes += body.byteLength;
2996
- headerBuffer = "";
3354
+ headerBuffer = Buffer.alloc(0);
2997
3355
  } else {
2998
3356
  totalBytes += chunk.byteLength;
2999
3357
  windowBytes += chunk.byteLength;
@@ -3028,12 +3386,13 @@ var USER_AGENT;
3028
3386
  var init_true_probe = __esm({
3029
3387
  "src/scan/true-probe.ts"() {
3030
3388
  "use strict";
3031
- USER_AGENT = "CFPilot-Scanner/1.0 (+https://github.com/xmwengxing/CFPilot)";
3389
+ USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
3032
3390
  }
3033
3391
  });
3034
3392
 
3035
3393
  // src/scan/speed-url.ts
3036
3394
  import * as tls2 from "node:tls";
3395
+ import * as net from "node:net";
3037
3396
  function parseSpeedUrl(raw, fallbackScheme = "https") {
3038
3397
  const value = (raw ?? "").trim();
3039
3398
  if (!value) throw new Error("\u6D4B\u901F\u5730\u5740\u4E3A\u7A7A");
@@ -3104,8 +3463,7 @@ function checkSpeedUrlAvailable(parsed, timeoutMs = 6e3) {
3104
3463
  const socket = parsed.scheme === "https" ? tls2.connect(connectOptions, () => socket.write(request)) : (
3105
3464
  // http 明文:用 net 连接
3106
3465
  (() => {
3107
- const net3 = __require("node:net");
3108
- const s = net3.connect({ host: parsed.host, port: 80 }, () => s.write(request));
3466
+ const s = net.connect({ host: parsed.host, port: 80 }, () => s.write(request));
3109
3467
  return s;
3110
3468
  })()
3111
3469
  );
@@ -3157,17 +3515,17 @@ var init_speed_url = __esm({
3157
3515
  { url: "cf.090227.xyz/__down?bytes=104857600", label: "CM \u63D0\u4F9B" }
3158
3516
  ];
3159
3517
  DEFAULT_SPEED_URL = SPEED_URL_PRESETS[0].url;
3160
- USER_AGENT_FOR_CHECK = "CFPilot-Scanner/1.0 (+https://github.com/xmwengxing/CFPilot)";
3518
+ USER_AGENT_FOR_CHECK = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
3161
3519
  }
3162
3520
  });
3163
3521
 
3164
3522
  // src/scan/scan.ts
3165
- import * as net from "node:net";
3523
+ import * as net2 from "node:net";
3166
3524
  async function tcpPing(ip, port, timeoutMs) {
3167
3525
  return new Promise((resolve2) => {
3168
3526
  const started = Date.now();
3169
3527
  let settled = false;
3170
- const socket = new net.Socket();
3528
+ const socket = new net2.Socket();
3171
3529
  const done = (ok) => {
3172
3530
  if (settled) return;
3173
3531
  settled = true;
@@ -3183,11 +3541,12 @@ async function tcpPing(ip, port, timeoutMs) {
3183
3541
  socket.connect(port, ip);
3184
3542
  });
3185
3543
  }
3186
- async function pool(items, concurrency, worker) {
3544
+ async function pool(items, concurrency, worker, shouldStop) {
3187
3545
  const out = new Array(items.length);
3188
3546
  let cursor = 0;
3189
3547
  const runners = Array.from({ length: Math.max(1, Math.min(concurrency, items.length)) }, async () => {
3190
3548
  for (; ; ) {
3549
+ if (shouldStop?.()) return;
3191
3550
  const index = cursor++;
3192
3551
  if (index >= items.length) return;
3193
3552
  out[index] = await worker(items[index], index);
@@ -3196,12 +3555,17 @@ async function pool(items, concurrency, worker) {
3196
3555
  await Promise.all(runners);
3197
3556
  return out;
3198
3557
  }
3199
- async function withRetry(attempts, fn, isOk = (r) => r.ok === true) {
3558
+ function isTimeoutError(error) {
3559
+ if (!error) return false;
3560
+ return /超时|timeout|timed out|ETIMEDOUT/i.test(error);
3561
+ }
3562
+ async function withRetry(attempts, fn, isOk = (r) => r.ok === true, shouldRetry = () => true) {
3200
3563
  const total = Math.max(1, Math.floor(attempts));
3201
3564
  let last;
3202
3565
  for (let i = 0; i < total; i++) {
3203
3566
  last = await fn();
3204
3567
  if (isOk(last)) return last;
3568
+ if (!shouldRetry(last)) return last;
3205
3569
  }
3206
3570
  return last;
3207
3571
  }
@@ -3211,7 +3575,7 @@ async function runScan(options) {
3211
3575
  const tcpTimeoutMs = options.tcpTimeoutMs ?? 1200;
3212
3576
  const retries = options.retries ?? 2;
3213
3577
  const tlsConcurrency = options.tlsConcurrency ?? 64;
3214
- const tlsTimeoutMs = options.tlsTimeoutMs ?? 4e3;
3578
+ const tlsTimeoutMs = options.tlsTimeoutMs ?? 2e3;
3215
3579
  const maxLatencyMs = options.maxLatencyMs ?? 0;
3216
3580
  const probeLimit = options.probeLimit ?? 120;
3217
3581
  const probeConcurrency = options.probeConcurrency ?? 24;
@@ -3221,6 +3585,9 @@ async function runScan(options) {
3221
3585
  const speedTimeoutMs = options.speedTimeoutMs ?? 12e3;
3222
3586
  const speedBytes = options.speedBytes ?? 5 * 1024 * 1024;
3223
3587
  const top = options.top ?? 15;
3588
+ const countryFilter = normalizeCountryFilter(options.countries ?? []);
3589
+ const hasCountryFilter = countryFilter.length > 0;
3590
+ const effectiveProbeLimit = hasCountryFilter ? Math.max(probeLimit * 4, 500) : probeLimit;
3224
3591
  const candidates = options.candidates;
3225
3592
  const report = options.onProgress ?? (() => {
3226
3593
  });
@@ -3242,30 +3609,37 @@ async function runScan(options) {
3242
3609
  });
3243
3610
  const tcpOk = tcpResults.filter((r) => r.ok);
3244
3611
  const filtered = maxLatencyMs > 0 ? tcpOk.filter((r) => r.latency <= maxLatencyMs) : tcpOk;
3245
- report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: filtered.length });
3612
+ const tlsCandidateLimit = Math.max(effectiveProbeLimit * 4, 600);
3613
+ const tlsInput = filtered.slice().sort((a, b) => a.latency - b.latency).slice(0, tlsCandidateLimit);
3614
+ report({ type: "stage", stage: 1, name: "TLS \u63E1\u624B\u7B5B\u9009", total: tlsInput.length });
3246
3615
  let tlsDone = 0;
3247
- const tlsResults = await pool(filtered, tlsConcurrency, async (item) => {
3616
+ const tlsResults = await pool(tlsInput, tlsConcurrency, async (item) => {
3248
3617
  const probe = await withRetry(
3249
3618
  retries,
3250
3619
  () => probeTlsHandshake(item.ip, options.port, options.host, tlsTimeoutMs),
3251
- (r) => r.tlsMs > 0
3620
+ (r) => r.tlsMs > 0,
3621
+ // 第 4 个参数:上次失败原因是超时就不要再试
3622
+ (r) => !isTimeoutError(r.error)
3252
3623
  );
3253
3624
  tlsDone++;
3254
- if (tlsDone % 200 === 0 || tlsDone === filtered.length) {
3625
+ if (tlsDone % 200 === 0 || tlsDone === tlsInput.length) {
3255
3626
  report({
3256
3627
  type: "progress",
3257
3628
  stage: 1,
3258
3629
  done: tlsDone,
3259
- total: filtered.length,
3260
- message: `TLS \u63E1\u624B ${tlsDone}/${filtered.length}${probe.tlsMs > 0 ? ` ${probe.tlsMs}ms` : " \u2717"}`
3630
+ total: tlsInput.length,
3631
+ message: `TLS \u63E1\u624B ${tlsDone}/${tlsInput.length}${probe.tlsMs > 0 ? ` ${probe.tlsMs}ms` : " \u2717"}`
3261
3632
  });
3262
3633
  }
3263
3634
  return { ...item, tls: probe };
3264
3635
  });
3265
3636
  const tlsOk = tlsResults.filter((r) => r.tls.tlsMs > 0);
3266
- const stage1 = tlsOk.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency).slice(0, probeLimit);
3637
+ const stage1 = tlsOk.sort((a, b) => a.tls.tlsMs - b.tls.tlsMs || a.latency - b.latency).slice(0, effectiveProbeLimit);
3267
3638
  const strictProbe = options.verifyPayload !== false;
3268
- const strictProbePath = "/__edge_probe";
3639
+ const explicitProbePath = options.probePath?.trim();
3640
+ const explicitWsPath = options.wsPath?.trim();
3641
+ const strictProbePath = explicitProbePath || // 用户的 wsPath 以 /__edge_probe 开头 → 视为探针端点
3642
+ (explicitWsPath?.startsWith("/__edge_probe") ? explicitWsPath : "") || "/__edge_probe";
3269
3643
  report({
3270
3644
  type: "stage",
3271
3645
  stage: 2,
@@ -3274,29 +3648,46 @@ async function runScan(options) {
3274
3648
  });
3275
3649
  let probeDone = 0;
3276
3650
  let verifiedCount = 0;
3277
- const probeResults = await pool(stage1, probeConcurrency, async (item) => {
3278
- const probeFn = strictProbe ? probeWsPing : probeWs101;
3279
- const probePath = strictProbe ? strictProbePath : options.wsPath ?? "/__edge_probe";
3280
- const result = await withRetry(
3281
- retries,
3282
- () => probeFn(item.ip, options.port, options.host, probeTimeoutMs, probePath)
3283
- );
3284
- probeDone++;
3285
- if (result.pongVerified) verifiedCount++;
3286
- report({
3287
- type: "progress",
3288
- stage: 2,
3289
- done: probeDone,
3290
- total: stage1.length,
3291
- message: strictProbe ? `101+PING \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : result.pongVerified === false ? " \u2717 \u65E0\u54CD\u5E94" : ""}` : `101 \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : ""}`
3292
- });
3293
- return { ...item, probe: result };
3294
- });
3651
+ const earlyExitTarget = hasCountryFilter ? Math.ceil(speedLimit * 1.5) : Infinity;
3652
+ let matchedCount = 0;
3653
+ let stoppedEarly = false;
3654
+ const probeResults = await pool(
3655
+ stage1,
3656
+ probeConcurrency,
3657
+ async (item) => {
3658
+ const probeFn = strictProbe ? probeWsPing : probeWs101;
3659
+ const probePath = strictProbe ? strictProbePath : explicitWsPath || "/__edge_probe";
3660
+ const result = await withRetry(
3661
+ retries,
3662
+ () => probeFn(item.ip, options.port, options.host, probeTimeoutMs, probePath)
3663
+ );
3664
+ probeDone++;
3665
+ if (result.pongVerified) verifiedCount++;
3666
+ if (hasCountryFilter && result.ok && countryFilter.includes(countryOfColo(result.colo || ""))) {
3667
+ matchedCount++;
3668
+ }
3669
+ report({
3670
+ type: "progress",
3671
+ stage: 2,
3672
+ done: probeDone,
3673
+ total: stage1.length,
3674
+ message: strictProbe ? `101+PING \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : result.pongVerified === false ? " \u2717 \u65E0\u54CD\u5E94" : ""}` : `101 \u6821\u9A8C ${probeDone}/${stage1.length}${result.ok ? ` \u2713 ${result.colo}` : ""}`
3675
+ });
3676
+ return { ...item, probe: result };
3677
+ },
3678
+ () => {
3679
+ if (matchedCount >= earlyExitTarget) {
3680
+ stoppedEarly = true;
3681
+ return true;
3682
+ }
3683
+ return false;
3684
+ }
3685
+ );
3295
3686
  const wsOk = strictProbe ? probeResults.filter((r) => r.probe.ok && r.probe.pongVerified === true) : probeResults.filter((r) => r.probe.ok);
3296
- const countryFilter = normalizeCountryFilter(options.countries ?? []);
3297
3687
  let wsFiltered = wsOk;
3298
3688
  let appliedCountries = [];
3299
- if (countryFilter.length > 0 && wsOk.length > 0) {
3689
+ let countryFilterRelaxed = false;
3690
+ if (hasCountryFilter && wsOk.length > 0) {
3300
3691
  const matched = wsOk.filter((r) => countryFilter.includes(countryOfColo(r.probe.colo || "")));
3301
3692
  if (matched.length > 0) {
3302
3693
  wsFiltered = matched;
@@ -3309,12 +3700,13 @@ async function runScan(options) {
3309
3700
  message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")}\uFF1A\u4FDD\u7559 ${matched.length}/${wsOk.length}\uFF0C\u8FDB\u5165\u6D4B\u901F`
3310
3701
  });
3311
3702
  } else {
3703
+ countryFilterRelaxed = true;
3312
3704
  report({
3313
3705
  type: "progress",
3314
3706
  stage: 2,
3315
3707
  done: wsOk.length,
3316
3708
  total: wsOk.length,
3317
- message: `\u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")} \u540E\u65E0\u5019\u9009\uFF0C\u5DF2\u5FFD\u7565\uFF08\u91C7\u6837\u592A\u5C0F\uFF1F\u8C03\u5230 500~1000 \u518D\u8BD5\uFF09`
3709
+ message: `\u26A0\uFE0F \u56FD\u5BB6\u7B5B\u9009 ${countryFilter.join("/")} \u540E\u65E0\u5019\u9009 \u2014\u2014 \u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\uFF08${wsOk.length} \u6761\uFF09\u3002\u53EF\u52A0\u5927 --sample \u6216\u6362\u5730\u533A\u91CD\u8BD5`
3318
3710
  });
3319
3711
  }
3320
3712
  }
@@ -3360,7 +3752,7 @@ async function runScan(options) {
3360
3752
  options.host,
3361
3753
  speedBytes,
3362
3754
  speedTimeoutMs,
3363
- options.probePath ?? "/__edge_probe"
3755
+ strictProbePath
3364
3756
  );
3365
3757
  speedDone++;
3366
3758
  report({
@@ -3397,17 +3789,26 @@ async function runScan(options) {
3397
3789
  speedOk: entries.length,
3398
3790
  elapsedMs: Date.now() - started,
3399
3791
  countries: appliedCountries,
3400
- wsFiltered: wsFiltered.length
3792
+ wsFiltered: wsFiltered.length,
3793
+ /** 国家筛选未命中任何候选、已放宽为全量 */
3794
+ countryFilterRelaxed,
3795
+ /** 因已攒够目标国家节点而提前结束阶段二 */
3796
+ stoppedEarly
3401
3797
  }
3402
3798
  };
3403
3799
  report({ type: "done", count: entries.length });
3404
3800
  return summary;
3405
3801
  }
3802
+ function formatHost(ip) {
3803
+ return ip.includes(":") ? `[${ip}]` : ip;
3804
+ }
3406
3805
  function formatCopyable(entries) {
3407
- return entries.map((e) => `${e.ip}:${e.port}#${e.colo}`).join("\n");
3806
+ return entries.map((e) => `${formatHost(e.ip)}:${e.port}#${e.colo}`).join("\n");
3408
3807
  }
3409
3808
  function formatEntries(entries) {
3410
- return entries.map((e) => `${e.ip}:${e.port}#${e.colo}_${e.latency}_${e.speed}`);
3809
+ return entries.map(
3810
+ (e) => `${formatHost(e.ip)}:${e.port}#${e.colo}_${e.latency}_${e.speed}`
3811
+ );
3411
3812
  }
3412
3813
  var init_scan = __esm({
3413
3814
  "src/scan/scan.ts"() {
@@ -3513,16 +3914,14 @@ function cidrWeight(cidr) {
3513
3914
  if (!parsed || parsed.family !== 4) return DEFAULT_CIDR_WEIGHT;
3514
3915
  let bestPrefix = -1;
3515
3916
  let bestWeight = DEFAULT_CIDR_WEIGHT;
3516
- for (const [tableCidr, weight] of Object.entries(IPV4_CIDR_WEIGHTS)) {
3517
- const tableParsed = parseCidr(tableCidr);
3518
- if (!tableParsed || tableParsed.family !== 4) continue;
3519
- if (tableParsed.prefix > parsed.prefix) continue;
3520
- const parsedNorm = parsed.base >> BigInt(32 - tableParsed.prefix);
3521
- const tableNorm = tableParsed.base >> BigInt(32 - tableParsed.prefix);
3917
+ for (const entry of WEIGHT_TABLE) {
3918
+ if (entry.prefix > parsed.prefix) continue;
3919
+ const parsedNorm = parsed.base >> BigInt(32 - entry.prefix);
3920
+ const tableNorm = entry.base >> BigInt(32 - entry.prefix);
3522
3921
  if (parsedNorm !== tableNorm) continue;
3523
- if (tableParsed.prefix > bestPrefix) {
3524
- bestPrefix = tableParsed.prefix;
3525
- bestWeight = weight;
3922
+ if (entry.prefix > bestPrefix) {
3923
+ bestPrefix = entry.prefix;
3924
+ bestWeight = entry.weight;
3526
3925
  }
3527
3926
  }
3528
3927
  return bestWeight;
@@ -3737,12 +4136,20 @@ function expandCidrs(cidrs, options = {}) {
3737
4136
  continue;
3738
4137
  }
3739
4138
  const step = Math.floor(Number(cidr.size) / count);
3740
- const offset = Math.floor(random() * step);
3741
4139
  for (let i = 0; i < count; i++) {
3742
- const offsetValue = BigInt(offset + Math.floor(i * step));
3743
- if (offsetValue >= cidr.size) break;
3744
- const value = cidr.base + offsetValue;
3745
- out.push(family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
4140
+ const jitter = Math.floor(random() * step);
4141
+ let offsetValue = BigInt(i * step + jitter);
4142
+ if (offsetValue >= cidr.size) offsetValue = cidr.size - 1n;
4143
+ let value = cidr.base + offsetValue;
4144
+ if (cidr.family === 4) {
4145
+ const lastOctet = value & 0xffn;
4146
+ if (lastOctet === 0n) value += 1n;
4147
+ else if (lastOctet === 255n) value -= 1n;
4148
+ if (value < cidr.base || value >= cidr.base + cidr.size) {
4149
+ value = cidr.base + offsetValue;
4150
+ }
4151
+ }
4152
+ out.push(cidr.family === 4 ? bigIntToIpv4(value) : bigIntToIpv6(value));
3746
4153
  }
3747
4154
  }
3748
4155
  }
@@ -3775,7 +4182,7 @@ function readIpFile(text) {
3775
4182
  }
3776
4183
  return out;
3777
4184
  }
3778
- var BUILTIN_IPV4_CIDRS, IPV4_CIDR_WEIGHTS, DEFAULT_CIDR_WEIGHT, BUILTIN_IPV6_CIDRS;
4185
+ var BUILTIN_IPV4_CIDRS, IPV4_CIDR_WEIGHTS, DEFAULT_CIDR_WEIGHT, WEIGHT_TABLE, BUILTIN_IPV6_CIDRS;
3779
4186
  var init_ip_ranges = __esm({
3780
4187
  "src/scan/ip-ranges.ts"() {
3781
4188
  "use strict";
@@ -3828,6 +4235,15 @@ var init_ip_ranges = __esm({
3828
4235
  "131.0.72.0/22": 0
3829
4236
  };
3830
4237
  DEFAULT_CIDR_WEIGHT = 0.2;
4238
+ WEIGHT_TABLE = (() => {
4239
+ const out = [];
4240
+ for (const [cidr, weight] of Object.entries(IPV4_CIDR_WEIGHTS)) {
4241
+ const parsed = parseCidr(cidr);
4242
+ if (!parsed || parsed.family !== 4) continue;
4243
+ out.push({ base: parsed.base, prefix: parsed.prefix, weight });
4244
+ }
4245
+ return out;
4246
+ })();
3831
4247
  BUILTIN_IPV6_CIDRS = [
3832
4248
  "2400:cb00::/32",
3833
4249
  "2606:4700::/32",
@@ -3841,11 +4257,11 @@ var init_ip_ranges = __esm({
3841
4257
  });
3842
4258
 
3843
4259
  // src/scan/net-env.ts
3844
- import * as net2 from "node:net";
4260
+ import * as net3 from "node:net";
3845
4261
  import { execFile } from "node:child_process";
3846
4262
  function isPortListening(port, timeoutMs = 400) {
3847
4263
  return new Promise((resolve2) => {
3848
- const socket = new net2.Socket();
4264
+ const socket = new net3.Socket();
3849
4265
  let settled = false;
3850
4266
  const done = (open) => {
3851
4267
  if (settled) return;
@@ -4071,7 +4487,8 @@ __export(server_exports, {
4071
4487
  BRIDGE_VERSION: () => BRIDGE_VERSION,
4072
4488
  DEFAULT_BRIDGE_PORT: () => DEFAULT_BRIDGE_PORT,
4073
4489
  resolveScanCandidates: () => resolveScanCandidates,
4074
- startBridge: () => startBridge
4490
+ startBridge: () => startBridge,
4491
+ validateCallbackUrl: () => validateCallbackUrl
4075
4492
  });
4076
4493
  import { createServer } from "node:http";
4077
4494
  function normalizeSample(value) {
@@ -4105,6 +4522,25 @@ function describePlan(plan) {
4105
4522
  if (plan.source === "request") return `\u4F7F\u7528\u8BF7\u6C42\u643A\u5E26\u7684 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
4106
4523
  return `\u5DF2\u81EA\u52A8\u751F\u6210 ${plan.candidates.length} \u4E2A\u5019\u9009 IP`;
4107
4524
  }
4525
+ function pruneJobs() {
4526
+ const now = Date.now();
4527
+ for (const [id, job] of jobs) {
4528
+ if (job.finished && now - job.startedAt > JOB_TTL_MS) {
4529
+ jobs.delete(id);
4530
+ }
4531
+ }
4532
+ const sorted = [...jobs.values()].sort((a, b) => a.startedAt - b.startedAt);
4533
+ while (jobs.size > MAX_JOBS && sorted.length > 0) {
4534
+ const oldest = sorted.shift();
4535
+ jobs.delete(oldest.id);
4536
+ }
4537
+ }
4538
+ function hasRunningJob() {
4539
+ for (const job of jobs.values()) {
4540
+ if (!job.finished) return job;
4541
+ }
4542
+ return null;
4543
+ }
4108
4544
  function corsHeaders() {
4109
4545
  return {
4110
4546
  "Access-Control-Allow-Origin": "*",
@@ -4113,6 +4549,24 @@ function corsHeaders() {
4113
4549
  "Access-Control-Max-Age": "86400"
4114
4550
  };
4115
4551
  }
4552
+ function validateCallbackUrl(raw) {
4553
+ if (!raw || !raw.trim()) return { ok: true };
4554
+ let url;
4555
+ try {
4556
+ url = new URL(raw.trim());
4557
+ } catch {
4558
+ return { ok: false, error: "callback \u4E0D\u662F\u5408\u6CD5 URL" };
4559
+ }
4560
+ if (url.protocol !== "https:") {
4561
+ return { ok: false, error: "callback \u5FC5\u987B\u662F https \u5730\u5740" };
4562
+ }
4563
+ const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
4564
+ const isLocal = host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "0.0.0.0" || host.endsWith(".local") || host.endsWith(".internal") || /^10\./.test(host) || /^192\.168\./.test(host) || /^172\.(1[6-9]|2\d|3[01])\./.test(host) || /^100\.(6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./.test(host) || /^169\.254\./.test(host);
4565
+ if (isLocal) {
4566
+ return { ok: false, error: "callback \u4E0D\u80FD\u6307\u5411\u672C\u673A\u6216\u5185\u7F51\u5730\u5740" };
4567
+ }
4568
+ return { ok: true };
4569
+ }
4116
4570
  function sendJson(res, status2, data) {
4117
4571
  const body = JSON.stringify(data);
4118
4572
  res.writeHead(status2, {
@@ -4239,6 +4693,21 @@ async function handleRequest(req, res) {
4239
4693
  sendJson(res, 400, { ok: false, error: "\u7F3A\u5C11 host \u53C2\u6570" });
4240
4694
  return;
4241
4695
  }
4696
+ const running = hasRunningJob();
4697
+ if (running) {
4698
+ sendJson(res, 409, {
4699
+ ok: false,
4700
+ error: `\u5DF2\u6709\u626B\u63CF\u4EFB\u52A1\u5728\u8FD0\u884C\uFF08${running.id}\uFF09\uFF0C\u8BF7\u7B49\u5B83\u7ED3\u675F`,
4701
+ jobId: running.id
4702
+ });
4703
+ return;
4704
+ }
4705
+ const callbackCheck = validateCallbackUrl(body.callback);
4706
+ if (!callbackCheck.ok) {
4707
+ sendJson(res, 400, { ok: false, error: callbackCheck.error });
4708
+ return;
4709
+ }
4710
+ pruneJobs();
4242
4711
  const job = {
4243
4712
  id: `job-${Date.now()}-${++jobCounter}`,
4244
4713
  startedAt: Date.now(),
@@ -4273,6 +4742,17 @@ async function handleRequest(req, res) {
4273
4742
  // 国家过滤(可多选):不传 = 全量;无效代码在 normalizeCountryFilter 里被丢弃
4274
4743
  countries: Array.isArray(body.countries) ? body.countries : void 0,
4275
4744
  top: body.top ?? 15,
4745
+ // ⚠️ 必须透传这些参数,否则桥接服务永远用默认值:
4746
+ // wsPath / probePath —— 对接第三方项目(路径不是 /__edge_probe)时,
4747
+ // 阶段二会硬连默认探针路径 → 全军覆没
4748
+ // verifyPayload —— 目标没有探针端点时,内容校验必然失败,
4749
+ // 应自动退回纯 101 校验
4750
+ // speedMode / speedUrl —— 面板可以指定用探针端点还是公开测速地址
4751
+ wsPath: body.wsPath,
4752
+ probePath: body.probePath,
4753
+ verifyPayload: body.verifyPayload,
4754
+ speedMode: body.speedMode,
4755
+ speedUrl: body.speedUrl,
4276
4756
  onProgress: (event) => broadcast(job, event)
4277
4757
  });
4278
4758
  job.result = summary.entries;
@@ -4337,7 +4817,7 @@ async function handleRequest(req, res) {
4337
4817
  }
4338
4818
  sendJson(res, 404, { ok: false, error: "\u63A5\u53E3\u4E0D\u5B58\u5728" });
4339
4819
  }
4340
- var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter;
4820
+ var BRIDGE_VERSION, DEFAULT_BRIDGE_PORT, jobs, jobCounter, JOB_TTL_MS, MAX_JOBS;
4341
4821
  var init_server = __esm({
4342
4822
  "src/scan/server.ts"() {
4343
4823
  "use strict";
@@ -4348,6 +4828,8 @@ var init_server = __esm({
4348
4828
  DEFAULT_BRIDGE_PORT = 19527;
4349
4829
  jobs = /* @__PURE__ */ new Map();
4350
4830
  jobCounter = 0;
4831
+ JOB_TTL_MS = 10 * 60 * 1e3;
4832
+ MAX_JOBS = 5;
4351
4833
  }
4352
4834
  });
4353
4835
 
@@ -4383,6 +4865,8 @@ scan \u9009\u9879:
4383
4865
  --path <path> \u9636\u6BB5\u4E8C\u6821\u9A8C\u7684 WebSocket \u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
4384
4866
  \uFF08\u5BF9\u63A5\u5176\u5B83\u9879\u76EE\u65F6\u586B\u5B83\u81EA\u5DF1\u7684 WS \u8DEF\u5F84\uFF0C\u4F8B\u5982 /vless \u6216 /<uuid>\uFF09
4385
4867
  --probe-path <path> probe \u6A21\u5F0F\u7684\u6D4B\u901F\u8DEF\u5F84\uFF0C\u9ED8\u8BA4 /__edge_probe
4868
+ \u663E\u5F0F\u6307\u5B9A\u540E\uFF0C\u9636\u6BB5\u4E8C\u7684\u5185\u5BB9\u6821\u9A8C\u4E5F\u4F1A\u8D70\u8FD9\u4E2A\u8DEF\u5F84
4869
+ \uFF08\u5BF9\u63A5\u7B2C\u4E09\u65B9\u9879\u76EE\u65F6\u7528\uFF1B\u63A2\u9488\u7AEF\u70B9\u4E0D\u662F /__edge_probe \u65F6\u5FC5\u586B\uFF09
4386
4870
  --speed-mode <mode> \u6D4B\u901F\u65B9\u5F0F\uFF1Aauto\uFF08\u9ED8\u8BA4\uFF09/ probe / url
4387
4871
  auto = \u76EE\u6807\u6709\u63A2\u9488\u7AEF\u70B9\u5C31\u7528\u5B83\uFF0C\u5426\u5219\u81EA\u52A8\u6539\u7528\u516C\u5F00\u6D4B\u901F\u5730\u5740
4388
4872
  probe = \u53EA\u7528\u76EE\u6807\u9879\u76EE\u7684\u63A2\u9488\u7AEF\u70B9\uFF08\u6700\u5FE0\u5B9E\uFF0C\u8981\u6C42\u5BF9\u65B9\u6709\u8BE5\u7AEF\u70B9\uFF09
@@ -4396,6 +4880,7 @@ scan \u9009\u9879:
4396
4880
  \u771F\u673A\u5076\u53D1\u5931\u8D25\u7387 3~5%\uFF0C\u91CD\u8BD5\u53D6\u7B2C\u4E00\u6B21\u6210\u529F\u7684\u7ED3\u679C
4397
4881
  --no-verify \u9636\u6BB5\u4E8C\u53EA\u505A 101 \u63E1\u624B\uFF0C\u8DF3\u8FC7\u54CD\u5E94\u4F53\u6821\u9A8C
4398
4882
  \uFF08\u9ED8\u8BA4\u6821\u9A8C\uFF1A\u53D1 PING \u5E76\u9A8C\u8BC1\u6570\u636E\u9762\u56DE {"pong":true}\uFF09
4883
+ \u76EE\u6807\u6CA1\u6709\u63A2\u9488\u7AEF\u70B9\u65F6\u4F1A\u81EA\u52A8\u964D\u7EA7\u4E3A\u7EAF 101 \u6821\u9A8C
4399
4884
  --no-speed \u8DF3\u8FC7\u6D4B\u901F\uFF0C\u53EA\u6309\u5EF6\u8FDF\u6392\u5E8F
4400
4885
  --top <n> \u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 15
4401
4886
  --concurrency <n> \u9636\u6BB5\u4E00 TCP \u5E76\u53D1\uFF0C\u9ED8\u8BA4 300
@@ -4405,13 +4890,18 @@ scan \u9009\u9879:
4405
4890
  \u5EFA\u8BAE 6556 \u8D77\uFF1A\u9636\u6BB5\u4E00\u6309 TLS \u63E1\u624B\u8017\u65F6\u7B5B\u9009\uFF0C\u800C\u63E1\u624B\u5FEB\u6162
4406
4891
  \u4E0E TCP \u5EF6\u8FDF\u51E0\u4E4E\u65E0\u5173\uFF08\u5B9E\u6D4B TCP 9ms \u7684 IP \u53EF\u80FD\u8981 3.5 \u79D2\uFF09\uFF0C
4407
4892
  \u91C7\u6837\u5C0F\u4E86\u6839\u672C\u78B0\u4E0D\u5230\u63E1\u624B\u5FEB\u7684 IP
4408
- --countries <a,b> \u56FD\u5BB6 / \u5730\u533A\u8FC7\u6EE4\uFF08\u53EF\u591A\u9009\uFF0C\u9017\u53F7\u5206\u9694\uFF0C\u5982 HK,JP,SG\uFF09
4409
- \u4E0D\u9009 = \u5168\u91CF\u3002\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\uFF1B\u7B5B\u5B8C\u4E3A\u7A7A\u4F1A\u81EA\u52A8\u5FFD\u7565
4893
+ --countries <a,b> \u56FD\u5BB6 / \u5730\u533A\u8FC7\u6EE4\uFF08\u53EF\u591A\u9009\uFF0C\u9017\u53F7\u5206\u9694\uFF0C\u5982 US,JP,SG\uFF09
4894
+ \u4E0D\u9009 = \u5168\u91CF\u3002\u673A\u623F\u6765\u81EA 101 \u63E1\u624B\u54CD\u5E94\u3002
4895
+ \u5E26\u6B64\u53C2\u6570\u4F1A\u81EA\u52A8\u6269\u5927 101 \u6821\u9A8C\u7684\u5019\u9009\u6C60\uFF08120 \u2192 \u6700\u591A 500\uFF09\uFF0C
4896
+ \u5426\u5219\u76EE\u6807\u5730\u533A\u53EF\u80FD\u56E0\u5EF6\u8FDF\u6392\u5E8F\u88AB\u63D0\u524D\u622A\u65AD\uFF1B
4897
+ \u7B5B\u4E0D\u5230\u65F6\u4F1A\u660E\u786E\u63D0\u793A\u300C\u5DF2\u653E\u5BBD\u4E3A\u5168\u91CF\u300D\u800C\u4E0D\u662F\u9759\u9ED8\u5FFD\u7565
4410
4898
  --cidr <a,b> \u81EA\u5B9A\u4E49\u7F51\u6BB5\uFF08\u53EF\u91CD\u590D\uFF0C\u7528\u9017\u53F7\u5206\u9694\uFF09
4411
4899
  --ip-file <path> \u4F7F\u7528\u672C\u5730 IP \u5217\u8868\u6587\u4EF6
4412
4900
  --max-latency <ms> \u9636\u6BB5\u4E00 TCP \u5EF6\u8FDF\u4E0A\u9650\uFF0C\u9ED8\u8BA4 0\uFF08\u4E0D\u9650\uFF09
4413
- --tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 4000
4901
+ --tls-timeout <ms> \u9636\u6BB5\u4E00 TLS \u63E1\u624B\u8D85\u65F6\uFF0C\u9ED8\u8BA4 2000
4902
+ \u8D85\u65F6\u4E0D\u518D\u91CD\u8BD5\uFF08\u8BE5 IP \u5728\u5F53\u524D\u7F51\u7EDC\u4E0B\u5C31\u662F\u4E0D\u53EF\u7528\uFF09
4414
4903
  --probe-limit <n> \u8FDB\u5165 101 \u6821\u9A8C\u7684\u5019\u9009\u6570\uFF0C\u9ED8\u8BA4 120
4904
+ \u5E26 --countries \u65F6\u81EA\u52A8\u653E\u5927\u5230 max(120*4, 500)
4415
4905
  --speed-limit <n> \u8FDB\u5165\u6D4B\u901F\u7684\u5019\u9009\u6570\uFF0C\u9ED8\u8BA4 30
4416
4906
  --speed-bytes <n> \u6D4B\u901F\u5B57\u8282\u6570\uFF0C\u9ED8\u8BA4 5242880
4417
4907
  --timeout <ms> \u9636\u6BB5\u4E00\u8D85\u65F6\uFF0C\u9ED8\u8BA4 1200
@@ -4511,7 +5001,7 @@ function printTable(entries) {
4511
5001
  process.stdout.write("\u2500".repeat(66) + "\n");
4512
5002
  entries.forEach((entry, index) => {
4513
5003
  const rank = String(index + 1).padStart(2, " ");
4514
- const address = `${entry.ip}:${entry.port}`.padEnd(24, " ");
5004
+ const address = `${formatHost(entry.ip)}:${entry.port}`.padEnd(24, " ");
4515
5005
  const colo = (entry.colo || "UNK").padEnd(6, " ");
4516
5006
  const tls3 = String(entry.tlsMs).padStart(7, " ");
4517
5007
  const latency = String(entry.latency).padStart(7, " ");
@@ -4576,7 +5066,6 @@ async function runScanCommand(args) {
4576
5066
  const wsPath = normalizeWsPath(flagString(args, "path"), "/__edge_probe");
4577
5067
  const probePath = normalizeWsPath(flagString(args, "probe-path"), "/__edge_probe");
4578
5068
  const noSpeed = flagBool(args, "no-speed");
4579
- const verifyPayload = !flagBool(args, "no-verify");
4580
5069
  const countries = normalizeCountryFilter(flagList(args, "countries"));
4581
5070
  const panelHost = flagString(args, "panel");
4582
5071
  const panelPassword = flagString(args, "panel-password");
@@ -4646,6 +5135,22 @@ ${NAME} v${VERSION}
4646
5135
  let skipSpeed = noSpeed;
4647
5136
  let speedMode = "probe";
4648
5137
  let speedUrl = flagString(args, "speed-url", DEFAULT_SPEED_URL);
5138
+ let verifyPayload = !flagBool(args, "no-verify");
5139
+ let hasProbeEndpoint = null;
5140
+ const detectProbeEndpoint = async () => {
5141
+ try {
5142
+ const probe = await fetch(`https://${host}${probePath}?bytes=1024`, {
5143
+ method: "GET",
5144
+ signal: AbortSignal.timeout(8e3)
5145
+ });
5146
+ return Boolean(probe.headers.get("x-probe-bytes"));
5147
+ } catch {
5148
+ return null;
5149
+ }
5150
+ };
5151
+ if (verifyPayload) {
5152
+ hasProbeEndpoint = await detectProbeEndpoint();
5153
+ }
4649
5154
  if (!skipSpeed) {
4650
5155
  const forcedMode = flagString(args, "speed-mode");
4651
5156
  if (forcedMode === "url") {
@@ -4655,16 +5160,10 @@ ${NAME} v${VERSION}
4655
5160
  } else if (forcedMode === "probe") {
4656
5161
  speedMode = "probe";
4657
5162
  } else {
4658
- let hasProbe = false;
4659
- try {
4660
- const probe = await fetch(`https://${host}${probePath}?bytes=1024`, {
4661
- method: "GET",
4662
- signal: AbortSignal.timeout(8e3)
4663
- });
4664
- hasProbe = Boolean(probe.headers.get("x-probe-bytes"));
4665
- } catch {
4666
- hasProbe = false;
5163
+ if (hasProbeEndpoint === null) {
5164
+ hasProbeEndpoint = await detectProbeEndpoint();
4667
5165
  }
5166
+ const hasProbe = hasProbeEndpoint;
4668
5167
  if (hasProbe) {
4669
5168
  speedMode = "probe";
4670
5169
  if (!quiet) process.stdout.write("\u6D4B\u901F\u65B9\u5F0F\uFF1A\u9879\u76EE\u63A2\u9488\u7AEF\u70B9\uFF08\u6700\u5FE0\u5B9E\uFF09\n");
@@ -4684,6 +5183,12 @@ ${NAME} v${VERSION}
4684
5183
  }
4685
5184
  }
4686
5185
  }
5186
+ if (hasProbeEndpoint === false && verifyPayload) {
5187
+ verifyPayload = false;
5188
+ if (!quiet) {
5189
+ process.stdout.write("\n\u63D0\u793A\uFF1A\u76EE\u6807\u65E0\u63A2\u9488\u7AEF\u70B9\uFF0C\u5DF2\u81EA\u52A8\u5173\u95ED\u54CD\u5E94\u4F53\u6821\u9A8C\uFF08\u9000\u56DE\u7EAF 101 \u6821\u9A8C\uFF09\n");
5190
+ }
5191
+ }
4687
5192
  const summary = await runScan({
4688
5193
  host,
4689
5194
  port,
@@ -4697,7 +5202,7 @@ ${NAME} v${VERSION}
4697
5202
  retries: flagNumber(args, "retries", 2),
4698
5203
  tcpTimeoutMs: flagNumber(args, "timeout", 1200),
4699
5204
  tlsConcurrency: flagNumber(args, "tls-concurrency", 64),
4700
- tlsTimeoutMs: flagNumber(args, "tls-timeout", 4e3),
5205
+ tlsTimeoutMs: flagNumber(args, "tls-timeout", 2e3),
4701
5206
  maxLatencyMs: flagNumber(args, "max-latency", 0),
4702
5207
  probeLimit: flagNumber(args, "probe-limit", 120),
4703
5208
  probeTimeoutMs: flagNumber(args, "probe-timeout", 3e3),