dsh-mobile-plugin 0.5.132 → 0.5.133

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/lib/mobile/git.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // 本次改动:给手机上会显示的中文错误补稳定机器码(JSON 请求体单独成码),中文只做日志兜底。
2
+ // 本次改动:仓库摘要一并回传宿主已识别的仓库清单,手机端据此切换仓库。
2
3
  'use strict';
3
4
 
4
5
  /**
@@ -151,7 +152,7 @@ async function resolveTarget(ctx, params) {
151
152
  if (!marker.repos.some((repo) => repo.root === repoRoot)) {
152
153
  throw fail('FORBIDDEN', '这个仓库不在该项目的识别结果里');
153
154
  }
154
- return { projectPath, repoRoot };
155
+ return { projectPath, repoRoot, marker };
155
156
  }
156
157
 
157
158
  /** HEAD 是否存在:空仓库(还没有第一个提交)时很多命令的行为不一样。 */
@@ -205,7 +206,14 @@ async function handleGitRepo(ctx, req, res) {
205
206
  workspaceId: params.get('workspaceId'),
206
207
  repo: params.get('repo'),
207
208
  });
208
- sendJson(res, 200, { ok: true, ...(await read.repoOf(target.repoRoot)) });
209
+ // 仓库清单是识别层已经算好的(同一份也用来校验 repo 参数):跟着摘要一起回,
210
+ // 手机端才有得切。工作区清单继续保持精简,不为每个条目都带这份数组。
211
+ sendJson(res, 200, {
212
+ ok: true,
213
+ ...(await read.repoOf(target.repoRoot)),
214
+ repos: target.marker.repos,
215
+ truncated: target.marker.truncated,
216
+ });
209
217
  }
210
218
 
211
219
  /** GET git/status:四个分组,带每个文件的增删与二进制标记。 */
@@ -1,3 +1,4 @@
1
+ // 反馈 1569:插件跑在容器里时容器内网 eth0 不进局域网候选(按容器标记判,不按 172 地址段)。
1
2
  // 反馈 1012:172.17/16 是真实 Wi-Fi 可用的私网段,容器 / 虚拟网卡改由网卡名黑名单挡。
2
3
  // 反馈 1562:节点小宝 NodeBabyLink 是第三方穿透 VPN 虚拟网卡,按网卡名挡,不进局域网候选。
3
4
  // 没有已监听端口时不产出可连接候选。
@@ -12,6 +13,7 @@
12
13
  */
13
14
  'use strict'
14
15
 
16
+ const fsSync = require('node:fs')
15
17
  const os = require('node:os')
16
18
  // 私有地址判断搬到 shared/private-address.js:内核也要用它,不能反过来让内核依赖这个会频繁变的文件。
17
19
  const { isPrivateLanAddress } = require('../shared/private-address.js')
@@ -148,14 +150,19 @@ function toCandidates(list, port, family = 'IPv4') {
148
150
  // Structured view of the usable LAN endpoints. The app's `candidateUrls()` accepts
149
151
  // this shape, so callers that want interface metadata (for diagnostics or smarter
150
152
  // ordering) should prefer it.
151
- function lanInterfaces(port, interfaces = os.networkInterfaces()) {
153
+ // `opts.inContainer` 只给测试注入容器现场;生产走 isContainerRuntime() 的只读探测。
154
+ function lanInterfaces(port, interfaces = os.networkInterfaces(), opts = {}) {
155
+ const inContainer = typeof opts.inContainer === 'boolean' ? opts.inContainer : isContainerRuntime()
156
+ // 容器里那块 eth0 是容器内网、手机拨不进来;整条私网清单不产出,二维码与 /connection-info
157
+ // 转而走公网候选 + 手填地址。不动 isLanCandidateAddress 的地址段判据(172.x 真实 Wi-Fi 照旧)。
158
+ if (inContainer) return []
152
159
  return toCandidates(collectEndpoints(interfaces, isLanCandidateAddress), port)
153
160
  }
154
- function lanUrls(port, interfaces = os.networkInterfaces()) {
155
- return lanInterfaces(port, interfaces).map((candidate) => candidate.url)
161
+ function lanUrls(port, interfaces = os.networkInterfaces(), opts = {}) {
162
+ return lanInterfaces(port, interfaces, opts).map((candidate) => candidate.url)
156
163
  }
157
- function lanCandidates(port, interfaces = os.networkInterfaces()) {
158
- return lanInterfaces(port, interfaces)
164
+ function lanCandidates(port, interfaces = os.networkInterfaces(), opts = {}) {
165
+ return lanInterfaces(port, interfaces, opts)
159
166
  }
160
167
 
161
168
  /**
@@ -307,6 +314,27 @@ function ipv6Candidates(port, interfaces = os.networkInterfaces()) {
307
314
  }
308
315
  }
309
316
 
317
+ // 反馈 1569:插件自己跑在容器里时,os.networkInterfaces() 只有 lo + eth0(容器内网地址),
318
+ // 手机永远拨不进来。这里按「进程是不是在容器里」判,而不是按地址段 —— 172.x 可能是真实
319
+ // Wi-Fi(反馈 1012 已拍板),不能因为地址落在私网段就排除。容器标记都是只读文件,读不到
320
+ // 一律当不在容器;结果按进程缓存,容器身份在进程生命周期内不会变。
321
+ let containerHint
322
+ function isContainerRuntime() {
323
+ if (containerHint !== undefined) return containerHint
324
+ let hit = false
325
+ try {
326
+ for (const marker of ['/.dockerenv', '/run/.containerenv']) {
327
+ if (fsSync.existsSync(marker)) { hit = true; break }
328
+ }
329
+ if (!hit) {
330
+ const cgroup = fsSync.readFileSync('/proc/1/cgroup', 'utf8')
331
+ hit = /(?:docker|containerd|kubepods|lxc[/])/.test(cgroup)
332
+ }
333
+ } catch { /* 非 Linux / 读不到标记:当不在容器 */ }
334
+ containerHint = hit
335
+ return hit
336
+ }
337
+
310
338
  /**
311
339
  * 对外公布的候选地址:**先私网,一个都没有时才退到公网**。
312
340
  *
@@ -317,9 +345,9 @@ function ipv6Candidates(port, interfaces = os.networkInterfaces()) {
317
345
  * 取不到网卡(异常)时回空清单、绝不抛:它喂的是二维码与移动端的连接信息,
318
346
  * 让它把整条控制面拖下水不值得。
319
347
  */
320
- function advertisedCandidates(port, interfaces = os.networkInterfaces()) {
348
+ function advertisedCandidates(port, interfaces = os.networkInterfaces(), opts = {}) {
321
349
  try {
322
- const lan = lanCandidates(port, interfaces)
350
+ const lan = lanCandidates(port, interfaces, opts)
323
351
  if (lan.length > 0) return lan
324
352
  return publicCandidates(port, interfaces)
325
353
  } catch {
@@ -508,6 +536,7 @@ module.exports = {
508
536
  isVpnInterface,
509
537
  isVirtualInterface,
510
538
  interfaceRank,
539
+ isContainerRuntime,
511
540
  lanInterfaces,
512
541
  lanUrls,
513
542
  lanCandidates,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-plugin",
3
- "version": "0.5.132",
3
+ "version": "0.5.133",
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",
@@ -117,22 +117,23 @@
117
117
  "yaml": "2.9.1"
118
118
  },
119
119
  "dshMobileReleaseNotes": {
120
- "version": "0.5.132",
120
+ "version": "0.5.133",
121
121
  "kinds": [
122
- "fix"
122
+ "fix",
123
+ "feature"
123
124
  ],
124
125
  "notes": {
125
- "zh-Hans": "- 回环端口被占用、地址遭遮蔽时,兜底隧道会重新指向当前可用的端口,不再停在失效地址上。\n- 首选局域网地址现在在设备概况和配对回包里也排在最前,各处线路列表的顺序一致。\n- 节点小宝的虚拟网卡不再混进局域网候选,选路时不会误提到它。\n- 回环来源的网络通道改标为隧道,不再冒充局域网线路。",
126
- "zh-Hant": "- 回環連接埠被佔用、位址遭遮蔽時,兜底隧道會重新指向目前可用的連接埠,不再停在失效位址上。\n- 優先區域網路位址現在在裝置概況和配對回包裡也排在最前,各處線路清單的順序一致。\n- 節點小寶的虛擬網卡不再混進區域網路候選,選路時不會誤提到它。\n- 回環來源的網路通道改標為隧道,不再冒充區域網路線路。",
127
- "en": "- When a loopback port is taken and the address is shadowed, the fallback tunnel now repoints to the currently available port instead of staying on a dead address.\n- Your preferred LAN address now also comes first in the device overview and pairing replies, so route lists are ordered consistently everywhere.\n- The JDXB virtual network adapter is no longer mixed into LAN candidates, so route selection won't pick it by mistake.\n- Network channels coming from loopback are now labeled as tunnels instead of being shown as LAN routes.",
128
- "ja": "- ループバックポートが占有されてアドレスが隠された場合、フォールバックトンネルは無効なアドレスに留まらず、現在使えるポートへ切り替えます。\n- 優先する LAN アドレスが端末の概要とペアリングの応答でも先頭に表示されるようになり、どのルート一覧でも並び順が同じになりました。\n- ノード小宝の仮想ネットワークアダプターが LAN 候補に混じらなくなり、ルート選択で誤って選ばれることがありません。\n- ループバック由来のネットワークチャネルは LAN 回線ではなくトンネルと表示されるようになりました。",
129
- "ko": "- 루프백 포트가 점유되어 주소가 가려지면, 대체 터널이 죽은 주소에 머무르지 않고 현재 사용 가능한 포트로 다시 연결됩니다.\n- 기본 설정한 LAN 주소가 기기 개요와 페어링 응답에서도 맨 앞에 표시되어, 모든 경로 목록의 순서가 일치합니다.\n- 노드 샤오바오의 가상 네트워크 어댑터가 더 이상 LAN 후보에 섞이지 않아 경로 선택에서 잘못 선택되지 않습니다.\n- 루프백에서 오는 네트워크 채널은 이제 LAN 경로가 아닌 터널로 표시됩니다.",
130
- "de": "- Wenn ein Loopback-Port belegt und die Adresse verdeckt ist, zeigt der Fallback-Tunnel jetzt auf den aktuell verfügbaren Port statt auf einer ungültigen Adresse zu bleiben.\n- Die bevorzugte LAN-Adresse steht nun auch in der Geräteübersicht und in Pairing-Antworten an erster Stelle, sodass Routenlisten überall gleich sortiert sind.\n- Die virtuelle Netzwerkkarte von JDXB taucht nicht mehr unter LAN-Kandidaten auf, damit die Routenwahl sie nicht versehentlich auswählt.\n- Netzwerkkanäle aus dem Loopback werden jetzt als Tunnel gekennzeichnet und nicht mehr als LAN-Route ausgegeben.",
131
- "es": "- Cuando un puerto de bucle local está ocupado y la dirección queda oculta, el túnel de respaldo ahora apunta al puerto disponible actual en lugar de quedarse en una dirección inactiva.\n- Tu dirección LAN preferida también aparece primero en el resumen del dispositivo y en las respuestas de emparejamiento, para que las listas de rutas estén ordenadas igual en todas partes.\n- La tarjeta virtual de JDXB ya no se mezcla con los candidatos LAN, de modo que la selección de rutas no la elige por error.\n- Los canales de red que vienen del bucle local ahora se etiquetan como túneles en vez de mostrarse como rutas LAN.",
132
- "fr": "- Lorsqu'un port de bouclage est occupé et l'adresse masquée, le tunnel de secours pointe désormais vers le port disponible actuel au lieu de rester sur une adresse inactive.\n- Votre adresse LAN préférée figure aussi en tête dans la vue d'appareil et dans les réponses d'appariement, afin que les listes de routes soient ordonnées de la même façon partout.\n- La carte réseau virtuelle de JDXB n'apparaît plus parmi les candidats LAN, ce qui évite à la sélection de route de la choisir par erreur.\n- Les canaux réseau issus du bouclage sont désormais étiquetés comme tunnels et non plus affichés comme routes LAN.",
133
- "pt": "- Quando uma porta de loopback está ocupada e o endereço fica oculto, o túnel de reserva agora aponta para a porta disponível atual em vez de permanecer num endereço inativo.\n- O seu endereço LAN preferido também vem primeiro na visão geral do dispositivo e nas respostas de emparelhamento, para que as listas de rotas fiquem ordenadas igualmente em todos os lugares.\n- A placa de rede virtual da JDXB não entra mais nos candidatos LAN, evitando que a seleção de rota a escolha por engano.\n- Os canais de rede vindos do loopback passam a ser marcados como túnel, em vez de aparecerem como rotas LAN.",
134
- "ru": "- Если порт петлевого интерфейса занят и адрес перекрыт, резервный туннель теперь указывает на доступный порт, а не остаётся на нерабочем адресе.\n- Предпочитаемый адрес локальной сети теперь стоит первым и в обзоре устройства, и в ответах на сопряжение, поэтому списки маршрутов везде отсортированы одинаково.\n- Виртуальный сетевой адаптер JDXB больше не попадает в кандидаты локальной сети, и выбор маршрута не может случайно выбрать его.\n- Сетевые каналы от петлевого интерфейса теперь помечаются как туннель, а не показываются как маршрут локальной сети.",
135
- "tr": "- Bir geri döngü (loopback) portu meşgulse ve adres gölgede kalırsa, yedek tünel artık ölü bir adreste kalmak yerine o anda kullanılabilir porta yönlenir.\n- Tercih ettiğiniz yerel ağ adresi artık cihaz genel bakışında ve eşleştirme yanıtlarında da en başta gelir; böylece rota listeleri her yerde aynı sıralanır.\n- JDXB'nin sanal ağ kartı artık yerel ağ adaylarına karışmıyor, rota seçimi onu yanlışlıkla seçmiyor.\n- Geri döngüden gelen ağ kanalları artık yerel ağ rotası olarak değil tünel olarak etiketleniyor."
126
+ "zh-Hans": "- 插件跑在容器里时,配对二维码不再给出拨不通的容器内网地址,改用公网候选或手填地址。\n- 仓库摘要现在带出项目里的全部仓库根,手机上可以切换到并列仓库、子模块和工作树。",
127
+ "zh-Hant": "- 外掛在容器裡執行時,配對二維碼不再給出連不上的容器內網位址,改採公網候選或手填位址。\n- 倉庫摘要現在帶出專案裡的全部倉庫根,手機上可以切換到並列倉庫、子模組與工作樹。",
128
+ "en": "- When the plugin runs inside a container, the pairing QR code no longer leads with an unreachable container-internal address; it falls back to public candidates or a manually entered address.\n- The repository summary now includes every repository root in the project, so you can switch to sibling repositories, submodules, and worktrees on your phone.",
129
+ "ja": "- プラグインがコンテナ内で動いている場合、ペアリング用QRコードに接続できないコンテナ内網アドレスが表示されなくなり、公開アドレス候補または手入力アドレスに切り替わります。\n- リポジトリの概要にプロジェクト内のすべてのリポジトリルートが含まれるようになり、スマートフォンで並列リポジトリ、サブモジュール、ワークツリーに切り替えられます。",
130
+ "ko": "- 플러그인이 컨테이너 안에서 실행될 때, 페어링 QR 코드에 연결할 수 없는 컨테이너 내부 주소가 더 이상 표시되지 않고 공개 후보 주소나 직접 입력한 주소를 사용합니다.\n- 저장소 요약에 프로젝트의 모든 저장소 루트가 포함되어, 휴대폰에서 나란한 저장소, 서브모듈, 워크트리로 전환할 수 있습니다.",
131
+ "de": "- Wenn das Plugin in einem Container läuft, zeigt der Pairing-QR-Code keine nicht erreichbaren Container-internen Adressen mehr an, sondern greift auf öffentliche Kandidaten oder eine manuell eingegebene Adresse zurück.\n- Die Repository-Übersicht enthält jetzt alle Repository-Wurzeln im Projekt, damit Sie auf dem Telefon zu parallelen Repositories, Submodulen und Worktrees wechseln können.",
132
+ "es": "- Cuando el plugin se ejecuta dentro de un contenedor, el código QR de emparejamiento ya no muestra direcciones internas del contenedor a las que no se puede conectar; usa candidatos públicos o una dirección introducida manualmente.\n- El resumen del repositorio ahora incluye todas las raíces de repositorios del proyecto, para que puedas cambiar a repositorios paralelos, submódulos y worktrees desde el teléfono.",
133
+ "fr": "- Lorsque le plugin s'exécute dans un conteneur, le code QR d'appariement n'affiche plus d'adresses internes du conteneur inaccessibles ; il repasse sur les candidats publics ou une adresse saisie manuellement.\n- Le résumé du dépôt inclut désormais toutes les racines de dépôts du projet, afin de pouvoir basculer vers les dépôts parallèles, les sous-modules et les worktrees depuis le téléphone.",
134
+ "pt": "- Quando o plugin corre dentro de um contentor, o código QR de emparelhamento deixa de mostrar endereços internos do contentor inacessíveis e passa a usar candidatos públicos ou um endereço introduzido manualmente.\n- O resumo do repositório agora inclui todas as raízes de repositórios do projeto, para que possa mudar para repositórios paralelos, submódulos e worktrees no telemóvel.",
135
+ "ru": "- Когда плагин работает внутри контейнера, QR-код сопряжения больше не показывает недоступные внутренние адреса контейнера и использует публичные кандидаты или введённый вручную адрес.\n- Сводка репозитория теперь включает все корни репозиториев проекта, чтобы на телефоне можно было переключаться на параллельные репозитории, подмодули и рабочие копии.",
136
+ "tr": "- Eklenti bir konteyner içinde çalıştığında, eşleştirme QR kodu artık erişilemeyen konteyner içi adresleri göstermiyor; genel adaylara veya elle girilen bir adrese geçiyor.\n- Depo özeti artık projedeki tüm depo köklerini içeriyor; böylece telefondan yan depolara, alt modüllere ve worktree'lere geçebilirsiniz."
136
137
  }
137
138
  }
138
139
  }