dsh-mobile-ios 0.2.10 → 0.2.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-ios",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "type": "module",
5
5
  "description": "DSH iOS移动伴侣:iPhone/iPad 扫码连接 DSH 桌面端,局域网直连 + Cloudflare Tunnel 固定域名远程两种通道",
6
6
  "main": "entries/plugin.mjs",
@@ -23,7 +23,7 @@ import { promisify } from 'node:util';
23
23
  import { fail } from './protocol.mjs';
24
24
  import { deriveSubdomain, isValidLabel } from './dns-label.mjs';
25
25
  import { dnsWarningFor, evaluateDnsAnswer, probeDns, resolveNs } from './dns-probe.mjs';
26
- import { cnameBelongsTo } from './zone-health.mjs';
26
+ import { cnameBelongsTo, readZoneCert } from './zone-health.mjs';
27
27
 
28
28
  const execFileAsync = promisify(nodeExecFile);
29
29
  const CLI_TIMEOUT_MS = 45_000;
@@ -268,8 +268,30 @@ export class LocalProvisioner {
268
268
 
269
269
  async ensure({ port, force = false } = {}) {
270
270
  if (!Number.isInteger(port) || port <= 0) throw fail(4400, '开通隧道需要有效端口');
271
- const cached = this.state;
272
- if (!force && cached?.hostname && cached.port === port) {
271
+ // 授权账号可能变过(域名迁移到另一个 Cloudflare 账号后重新 login 就是这种情况):
272
+ // 旧 tunnel 属于上一个账号,继续拿它的 id 去 route dns 只会得到
273
+ // "tunnel not found" 或更糟的静默失败。账号变了就当新装:重建隧道、保留同一个子域
274
+ // (地址不变,用户不用重新记/重新扫)。
275
+ const account = readZoneCert({ homeDir: this.homeDir })?.accountId || null;
276
+ let cached = this.state;
277
+ let accountChanged = false;
278
+ if (cached?.account && account && cached.account !== account) {
279
+ this.log(`tunnel 授权账号已变更(${cached.account.slice(0, 8)}… → ${account.slice(0, 8)}…),重建隧道`);
280
+ accountChanged = true;
281
+ cached = {
282
+ ...cached,
283
+ account,
284
+ tunnelId: null,
285
+ credentialsFile: null,
286
+ configFile: null,
287
+ dnsOk: null,
288
+ dnsTampered: false,
289
+ zone: null,
290
+ };
291
+ }
292
+ // 账号变了就必须走完整开通:缓存里的 port/hostname 看着都可用,
293
+ // 但它们描述的是上一个账号的隧道,跳过缓存才不会「解析通了就以为没事」。
294
+ if (!force && !accountChanged && cached?.hostname && cached.port === port) {
273
295
  // 与 BaseProvisioner 同策略:没确认过就现场验一次(含防篡改评估)
274
296
  if (cached.dnsOk !== true) {
275
297
  const { verdict, zone } = await this.#evaluate(cached.hostname, cached.tunnelId);
@@ -404,6 +426,8 @@ export class LocalProvisioner {
404
426
  const next = {
405
427
  ...cached,
406
428
  installationId,
429
+ // 记下这本证书属于哪个 Cloudflare 账号:下次若换了账号,能识别出「旧隧道不再可用」
430
+ account: account || cached?.account || null,
407
431
  subdomain: label,
408
432
  hostname,
409
433
  tunnelId,