dsh-mobile-plugin 0.5.71 → 0.5.73

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.
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * 盘符层:Windows 上「此电脑」里那一排盘,供手机端「添加工作区」跨盘浏览。
4
+ * 盘符层:被控端那一排可跳的根,供手机端「添加工作区」跨盘浏览。
5
5
  *
6
- * 为什么需要这一层:宿主 browse 后端只列**某一层目录的内容**、从不枚举盘符,而目录浏览器
7
- * 一打开就落在被控端主目录 —— Windows 上它永远在 C 盘。于是 D/E 盘从来不是「读不到」,
8
- * 而是客户端根本没有任何入口能跳过去(手输完整路径能进,但那条路藏起来了)。
6
+ * 为什么需要这一层:宿主 browse 后端只列**某一层目录的内容**、从不枚举盘符/挂载卷,而目录
7
+ * 浏览器一打开就落在被控端主目录,面包屑又只回得到「主目录」上不去根 —— Windows 上它永远
8
+ * 在 C 盘,Mac 上永远在 /Users/<name>。于是别的盘从来不是「读不到」,而是客户端根本没有任何
9
+ * 入口能跳过去(手输完整路径能进,但那条路藏起来了)。
9
10
  *
10
- * 为什么是探而不是查:本插件没有 shell 能力面,也不该为了 26 次 stat 去开一个。A–Z 逐个
11
- * `stat('X:\\')`,能 stat 成目录的才算那块盘存在;不存在的盘符会很快返回 ENOENT,整个过程
12
- * 只有一次网络请求的开销。
11
+ * Windows 是 A–Z 逐个 `stat('X:\\')` 探盘符(本插件没有 shell 能力面,也不该为了 26 次 stat
12
+ * 去开一个);macOS 是列 `/Volumes` 下挂的卷(外接硬盘、磁盘镜像都挂这儿)。
13
13
  *
14
- * 非 Windows 返回根目录一项:调用方只需处理「一排根」这一种形状,不必自己判平台;只有一项
15
- * 时客户端不显示这一层,所以 Mac/Linux 的界面一个像素都不变。
14
+ * Linux 等其余平台返回根目录一项:调用方只需处理「一排根」这一种形状,不必自己判平台;只有
15
+ * 一项时客户端不显示这一层,所以这些平台的界面一个像素都不变。
16
16
  */
17
17
 
18
- const { stat } = require('node:fs/promises');
18
+ const { readdir, stat } = require('node:fs/promises');
19
19
 
20
20
  /** 盘符顺序取 A–Z,`Promise.all` 保序,所以结果天然按字母排。 */
21
21
  const DRIVE_LETTERS = Object.freeze('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''));
@@ -46,14 +46,45 @@ async function listWindowsRoots({ statFile = stat } = {}) {
46
46
  }
47
47
 
48
48
  /**
49
- * 这台被控端可跳的根:Windows 是各块盘,其余平台是文件系统根。
49
+ * macOS:外接硬盘、磁盘镜像都挂在 `/Volumes` 下。逐个列出来,跳过点开头的隐藏项和符号链接
50
+ * (引导卷的别名 `Macintosh HD -> /` 就是一条符号链接,跳过它才不会和下面的根重复)。
51
+ * `/Volumes` 读不出来(权限/异常)时退回只有根一项,不让这条路由整体失败。
50
52
  *
51
- * @param {{ platform?: string, statFile?: typeof stat }} [options] 平台与 stat 注入点(测试用)。
53
+ * @param {{ readdirFile?: typeof readdir, statFile?: typeof stat }} [options] 注入点,测试用。
54
+ * @returns 根行数组:文件系统根 + 各挂载卷
55
+ */
56
+ async function listMacRoots({ readdirFile = readdir, statFile = stat } = {}) {
57
+ const roots = [{ name: '/', path: '/', hidden: false }];
58
+ let entries;
59
+ try {
60
+ entries = await readdirFile('/Volumes', { withFileTypes: true });
61
+ } catch {
62
+ return roots;
63
+ }
64
+ for (const entry of entries) {
65
+ if (entry.name.startsWith('.') || entry.isSymbolicLink()) continue;
66
+ const path = `/Volumes/${entry.name}`;
67
+ try {
68
+ if (!(await statFile(path)).isDirectory()) continue;
69
+ } catch {
70
+ continue;
71
+ }
72
+ roots.push({ name: entry.name, path, hidden: false });
73
+ }
74
+ return roots;
75
+ }
76
+
77
+ /**
78
+ * 这台被控端可跳的根:Windows 是各块盘,macOS 是根 + 各挂载卷,其余平台是文件系统根。
79
+ *
80
+ * @param {{ platform?: string, statFile?: typeof stat, readdirFile?: typeof readdir }} [options]
81
+ * 平台与 fs 注入点(测试用)。
52
82
  * @returns 根行数组
53
83
  */
54
- async function listRoots({ platform = process.platform, statFile = stat } = {}) {
84
+ async function listRoots({ platform = process.platform, statFile = stat, readdirFile = readdir } = {}) {
55
85
  if (platform === 'win32') return listWindowsRoots({ statFile });
86
+ if (platform === 'darwin') return listMacRoots({ readdirFile, statFile });
56
87
  return [{ name: '/', path: '/', hidden: false }];
57
88
  }
58
89
 
59
- module.exports = { DRIVE_LETTERS, listRoots, listWindowsRoots };
90
+ module.exports = { DRIVE_LETTERS, listMacRoots, listRoots, listWindowsRoots };
@@ -168,9 +168,10 @@ async function handleListDirectory(ctx, req, res) {
168
168
 
169
169
  /**
170
170
  * GET /api/mobile/v1/directory/roots(token)
171
- * 「添加工作区」的盘符层:宿主 browse 后端只列某一层目录的内容、从不枚举盘符,而手机端的
172
- * 目录浏览器一打开就落在被控端主目录 —— Windows 上它永远在 C 盘,别的盘没有任何入口。
173
- * Windows 回真实存在的盘符,其余平台回文件系统根;只有一项时 App 不显示这一层。
171
+ * 「添加工作区」的盘符层:宿主 browse 后端只列某一层目录的内容、从不枚举盘符/挂载卷,而手机端
172
+ * 的目录浏览器一打开就落在被控端主目录 —— Windows 上它永远在 C 盘、Mac 上永远在主目录,别的盘
173
+ * 没有任何入口。Windows 回真实存在的盘符,macOS 回根 + `/Volumes` 下的挂载卷,其余平台回文件
174
+ * 系统根;只有一项时 App 不显示这一层。
174
175
  *
175
176
  * 不走宿主:host.listDirectory 只认路径、给不出一份根清单,而枚举本身与目录选择器的部署
176
177
  * 形态无关(browse / native 两种宿主下答案一样)。
@@ -57,6 +57,23 @@ const MAX_DESKTOP_READ_IDS = 200;
57
57
  /** 公用中转测速的单项超时:远端多半在境外,给足 6 秒但别让整页干等。 */
58
58
  const RELAY_PROBE_TIMEOUT_MS = 6000;
59
59
 
60
+ /**
61
+ * `preferredLanAddress` 是不是其实是一枚中转地址的 host。
62
+ *
63
+ * 面板「网络配置」的局域网地址栏回显它。户外选路曾把中转地址误写进手机的局域网地址、手机再
64
+ * 存成 preferred 传回来,于是面板会显示出一枚用户没填过的中转地址。这里认出「它是个中转地址」
65
+ * 就不再回显,让界面退回网卡候选;判据只认会话里那组中转地址与公用中转,不碰别的配置。
66
+ */
67
+ function preferredIsRelayHost(preferred, state) {
68
+ const text = typeof preferred === 'string' ? preferred.trim().toLowerCase() : '';
69
+ if (!text) return false;
70
+ if (core.isPublicRelayUrl(`http://${text}`)) return true;
71
+ const endpoints = [...core.relayAddressesOf(state).relayUrls, state.relayUrl || ''];
72
+ return endpoints.some((url) => {
73
+ try { return new URL(String(url).trim()).host.toLowerCase() === text; } catch { return false; }
74
+ });
75
+ }
76
+
60
77
  function createWebAccessWindow({ now = Date.now, monotonicNow = () => performance.now() } = {}) {
61
78
  let deadline = 0;
62
79
  let expiresAt = 0;
@@ -445,6 +462,8 @@ function registerControlPlaneRoutes(deps) {
445
462
  registerRoute({ kind: 'exact', path: '/api/relay/addresses', handler: localOnly('GET', async (_req, res) => {
446
463
  const port = lanPortInUse()
447
464
  const preferred = typeof state.preferredLanAddress === 'string' ? state.preferredLanAddress : ''
465
+ // 「优先局域网地址」只能是网卡地址:混进来的中转地址不回显(见 preferredIsRelayHost)。
466
+ const preferredLan = preferredIsRelayHost(preferred, state) ? '' : preferred
448
467
  // `manual` 是用户手填的直连地址(内网穿透域名):网卡扫不出来,所以单列一格让面板回显与修改。
449
468
  const manual = typeof state.manualLanUrl === 'string' ? state.manualLanUrl : ''
450
469
  // `manualIpv6` 是同一件事的 IPv6 版:面板回显它,同时把它缀进 `ipv6` 候选最后
@@ -455,7 +474,7 @@ function registerControlPlaneRoutes(deps) {
455
474
  sendJson(res, 200, {
456
475
  ok: true,
457
476
  port,
458
- preferred,
477
+ preferred: preferredLan,
459
478
  manual,
460
479
  manualIpv6,
461
480
  manualTcp,
@@ -222,16 +222,26 @@ function installationProblem(profileNodeModules, name, version) {
222
222
  }
223
223
  }
224
224
 
225
+ /** 声明里写的是不是精确版本(`1.1.4` / `1.1.4-rc.1`),不是范围、标签或 git/url。 */
226
+ function exactDeclaredVersion(spec) {
227
+ if (typeof spec !== 'string') return null;
228
+ const trimmed = spec.trim();
229
+ return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(trimmed) ? trimmed : null;
230
+ }
231
+
225
232
  /**
226
- * 这次装完后,插件「按当前平台装上的」可选依赖(例如 tailcat 平台包)各自的实际版本。
233
+ * 这次装完后,插件声明的可选依赖(例如 tailcat 平台包)各自要登记进排除清单的版本。
227
234
  *
228
235
  * 它们和插件本体一样可能刚发布就被装进来,登记排除清单时要一并写 —— 否则这些包自己的
229
- * 锁条目会把后续的安装挡在 24 小时冷却窗口里(漏的正是刚发的那几个平台包)。只统计真的
230
- * 落在 node_modules 里的那些:os / cpu 不匹配被包管理器跳过的平台包不登记。
236
+ * 锁条目会把后续的安装挡在 24 小时冷却窗口里。**必须按声明补齐所有平台**:pnpm 11 在任何
237
+ * add / remove 之前校验的是**整份 lockfile**,lockfile 锁了全部 os / cpu 变体,所以
238
+ * 「os / cpu 不匹配、没落到盘上」的平台包,其锁条目照样参与校验 —— 跳过安装不等于跳过校验。
231
239
  *
232
- * 读不到插件清单或读不到某个依赖都只跳过、不抛 —— 登记是善后,不该把装好的版本说成没装上。
240
+ * 版本取值:声明里是精确版本就直接用(本项目这些平台包就钉死版本);写的是范围之类解析不出的,
241
+ * 退回读实际装上的那份;两样都拿不到就跳过这条,不猜。读不到插件清单也只跳过、不抛 ——
242
+ * 登记是善后,不该把装好的版本说成没装上。
233
243
  */
234
- function installedOptionalDeps(profileNodeModules, name = DEFAULT_NAME) {
244
+ function optionalDepsToExclude(profileNodeModules, name = DEFAULT_NAME) {
235
245
  const readVersion = (dir) => {
236
246
  try {
237
247
  const raw = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
@@ -249,8 +259,10 @@ function installedOptionalDeps(profileNodeModules, name = DEFAULT_NAME) {
249
259
  }
250
260
  if (!optional || typeof optional !== 'object') return out;
251
261
  for (const depName of Object.keys(optional)) {
252
- // hoisted 布局在 profile/node_modules 顶层;严格布局下在插件自己的 node_modules 里。
253
- const version = readVersion(path.join(profileNodeModules, depName))
262
+ // 精确版本覆盖所有平台(有些平台没装上也照样要登记);范围类才回落到盘上装的那份。
263
+ const version = exactDeclaredVersion(optional[depName])
264
+ // hoisted 布局在 profile/node_modules 顶层;严格布局下在插件自己的 node_modules 里。
265
+ || readVersion(path.join(profileNodeModules, depName))
254
266
  || readVersion(path.join(profileNodeModules, name, 'node_modules', depName));
255
267
  if (version) out.push({ name: depName, version });
256
268
  }
@@ -785,7 +797,7 @@ async function installLatest({
785
797
  // 插件按平台带出来的可选依赖(如 tailcat 平台包)也是刚发就可能刚装上的,同批登记,
786
798
  // 否则这些包自己的锁条目会把后续安装挡在冷却窗口里。逐条尽力写,失败不影响主结果。
787
799
  if (changed) {
788
- for (const dep of installedOptionalDeps(profileNodeModules, name)) {
800
+ for (const dep of optionalDepsToExclude(profileNodeModules, name)) {
789
801
  recordReleaseAgeExclusion(profileDir, dep.name, dep.version);
790
802
  }
791
803
  }
@@ -931,7 +943,7 @@ module.exports = {
931
943
  installLatest,
932
944
  installLatestIfNeeded,
933
945
  installedVersion,
934
- installedOptionalDeps,
946
+ optionalDepsToExclude,
935
947
  declaredSource,
936
948
  // 「Windows 上怎么起包管理器」在本机跑不起来,守卫只能验拼好的那一行,所以这两样露出来。
937
949
  cmdInvocation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-plugin",
3
- "version": "0.5.71",
3
+ "version": "0.5.73",
4
4
  "description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
5
5
  "license": "MIT",
6
6
  "icon": "./icon.png",