dsh-remote 0.8.91 → 0.8.93

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.
Files changed (181) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +369 -368
  3. package/README.md +354 -353
  4. package/cordis.patch.yml +9 -9
  5. package/lib/audit.js +45 -45
  6. package/lib/binding.js +172 -172
  7. package/lib/client.js +4647 -4550
  8. package/lib/credential.js +270 -263
  9. package/lib/errors.js +141 -141
  10. package/lib/exec-job.js +242 -242
  11. package/lib/file-reference.js +457 -457
  12. package/lib/forwards.js +258 -258
  13. package/lib/host-api.js +822 -822
  14. package/lib/hostkey.js +108 -108
  15. package/lib/http-transport.js +201 -201
  16. package/lib/ignore.js +202 -202
  17. package/lib/index.js +4488 -4394
  18. package/lib/instructions-dynamic.js +415 -415
  19. package/lib/instructions.js +288 -288
  20. package/lib/open-folder.js +56 -56
  21. package/lib/openssh.js +940 -881
  22. package/lib/paths.js +292 -292
  23. package/lib/pool.js +1029 -970
  24. package/lib/posix-shell.cjs +34 -0
  25. package/lib/registry.js +296 -296
  26. package/lib/remote-fs.js +173 -173
  27. package/lib/remote-sandbox.js +183 -183
  28. package/lib/remote-shell-child.cjs +397 -400
  29. package/lib/remote-shell.js +697 -697
  30. package/lib/remote-skills.js +312 -0
  31. package/lib/routes-audit.js +58 -58
  32. package/lib/routes-forwards.js +72 -72
  33. package/lib/routes-fs.js +251 -245
  34. package/lib/routes-machines.js +186 -186
  35. package/lib/routes-misc.js +187 -150
  36. package/lib/routes-term.js +169 -169
  37. package/lib/routes-update.js +143 -143
  38. package/lib/routes-web-attach.js +112 -112
  39. package/lib/routes-workspace.js +312 -312
  40. package/lib/search.js +235 -235
  41. package/lib/sftp-surface.js +119 -119
  42. package/lib/sshconfig.js +779 -779
  43. package/lib/sync.js +350 -350
  44. package/lib/tasks.js +95 -95
  45. package/lib/telemetry.js +247 -247
  46. package/lib/terminal.js +205 -205
  47. package/lib/tui/flow.js +130 -130
  48. package/lib/tui/format.js +380 -380
  49. package/lib/tui/i18n.js +350 -350
  50. package/lib/tui/index.js +531 -531
  51. package/lib/tui/provider.js +344 -344
  52. package/lib/tui/scene.js +986 -986
  53. package/lib/update.js +490 -472
  54. package/lib/web-attach.js +860 -850
  55. package/lib/workspace-cleanup.js +337 -337
  56. package/package.json +103 -100
  57. package/node_modules/buildcheck/.eslintrc.js +0 -5
  58. package/node_modules/buildcheck/.github/workflows/ci.yml +0 -88
  59. package/node_modules/buildcheck/.github/workflows/lint.yml +0 -27
  60. package/node_modules/buildcheck/.npmignore +0 -3
  61. package/node_modules/buildcheck/LICENSE +0 -19
  62. package/node_modules/buildcheck/README.md +0 -106
  63. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +0 -250
  64. package/node_modules/buildcheck/lib/findvs.js +0 -361
  65. package/node_modules/buildcheck/lib/index.js +0 -738
  66. package/node_modules/buildcheck/package.json +0 -36
  67. package/node_modules/buildcheck/test/test.js +0 -8
  68. package/node_modules/cpu-features/.eslintrc.js +0 -5
  69. package/node_modules/cpu-features/.github/workflows/ci.yml +0 -74
  70. package/node_modules/cpu-features/.github/workflows/lint.yml +0 -27
  71. package/node_modules/cpu-features/LICENSE +0 -19
  72. package/node_modules/cpu-features/README.md +0 -59
  73. package/node_modules/cpu-features/binding.gyp +0 -16
  74. package/node_modules/cpu-features/buildcheck.js +0 -32
  75. package/node_modules/cpu-features/deps/cpu_features/.clang-format +0 -4
  76. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +0 -31
  77. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +0 -5
  78. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +0 -30
  79. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +0 -22
  80. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +0 -26
  81. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +0 -31
  82. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +0 -43
  83. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +0 -25
  84. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +0 -31
  85. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +0 -24
  86. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +0 -30
  87. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +0 -29
  88. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +0 -28
  89. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +0 -27
  90. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +0 -21
  91. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +0 -329
  92. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +0 -261
  93. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +0 -23
  94. package/node_modules/cpu-features/deps/cpu_features/LICENSE +0 -230
  95. package/node_modules/cpu-features/deps/cpu_features/README.md +0 -272
  96. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +0 -19
  97. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +0 -5
  98. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +0 -11
  99. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +0 -3
  100. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +0 -3
  101. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +0 -30
  102. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +0 -252
  103. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +0 -40
  104. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +0 -64
  105. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +0 -312
  106. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +0 -7
  107. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +0 -48
  108. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +0 -34
  109. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +0 -22
  110. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +0 -11
  111. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +0 -107
  112. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +0 -15
  113. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +0 -105
  114. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +0 -54
  115. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +0 -384
  116. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +0 -259
  117. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +0 -121
  118. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +0 -74
  119. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +0 -149
  120. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +0 -72
  121. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +0 -108
  122. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +0 -288
  123. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +0 -40
  124. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +0 -37
  125. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +0 -39
  126. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +0 -240
  127. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +0 -49
  128. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +0 -110
  129. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +0 -70
  130. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +0 -60
  131. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +0 -4
  132. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +0 -205
  133. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +0 -320
  134. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +0 -12
  135. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +0 -456
  136. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +0 -165
  137. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +0 -75
  138. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +0 -490
  139. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +0 -79
  140. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +0 -19
  141. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +0 -86
  142. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +0 -26
  143. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +0 -22
  144. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +0 -62
  145. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +0 -169
  146. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +0 -88
  147. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +0 -79
  148. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +0 -82
  149. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +0 -138
  150. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +0 -212
  151. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +0 -93
  152. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +0 -163
  153. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +0 -111
  154. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +0 -120
  155. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +0 -2055
  156. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +0 -68
  157. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +0 -58
  158. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +0 -57
  159. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +0 -58
  160. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +0 -132
  161. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +0 -192
  162. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +0 -461
  163. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +0 -114
  164. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +0 -53
  165. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +0 -396
  166. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +0 -384
  167. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +0 -176
  168. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +0 -131
  169. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +0 -180
  170. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +0 -82
  171. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +0 -1729
  172. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +0 -103
  173. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +0 -61
  174. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +0 -52
  175. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +0 -31
  176. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +0 -132
  177. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +0 -202
  178. package/node_modules/cpu-features/lib/index.js +0 -5
  179. package/node_modules/cpu-features/package.json +0 -40
  180. package/node_modules/cpu-features/src/binding.cc +0 -151
  181. package/node_modules/cpu-features/test/test.js +0 -12
@@ -1,312 +1,312 @@
1
- // Mirror/connection routes: /connect /workspace /mirror /local-pick
2
- // /local-list /local-mkdir /test-connect /current /forget-key /home.
3
- //
4
- // Extracted from lib/index.js (issue #82: the god-file split). Handler bodies
5
- // moved VERBATIM. Pure helpers come straight from their leaf modules
6
- // (paths/errors/hostkey); everything that closes over entry state — the active
7
- // pool, the mirror registry writers, the machine-store plumbing shared with the
8
- // in-process API — arrives as `deps`.
9
- import { normalizeRemotePath } from './paths.js'
10
- import { friendlyMessage } from './errors.js'
11
- import { createHostKeyGuard } from './hostkey.js'
12
-
13
- /**
14
- * @param {object} deps
15
- * @param {(res: object, status: number, body: object) => void} deps.sendJson
16
- * @param {(req: object) => Promise<string>} deps.readBody
17
- * @param {(raw: string) => object} deps.parseJsonObject - 400-throwing object parser.
18
- * @param {object} deps.config - validated plugin Config (MUTATED by setTarget flows).
19
- * @param {object} deps.pool - the ACTIVE machine pool (ActivePool facade).
20
- * @param {(m: object, cfg: object) => string} deps.backendFor - native vs openssh choice.
21
- * @param {() => object} deps.status - the entry's status snapshot.
22
- * @param {(p: string) => Promise<boolean>} deps.isRemoteDir
23
- * @param {(p: string) => void} deps.persistWorkspace
24
- * @param {(remotePath: string, host: string, user: string, port: number, extra?: object) => string} deps.ensureMirror
25
- * @param {(m: object) => string} deps.aliasOf
26
- * @param {() => object|null} deps.activeMachine
27
- * @param {(localDir: string) => void} deps.startAutoPush
28
- * @param {(body: object, res: object) => Promise<boolean>} deps.applyRequestedMachine - picker re-assertion (replies on mismatch).
29
- * @param {(localDir: string, remotePath: string, machine: object) => Promise<void>} deps.registerMirroredWorkspace
30
- * @param {() => Promise<object>} deps.localPickCapability - host picker backend probe.
31
- * @param {() => Promise<object>} deps.pickLocalNative - the OS dialog fallback.
32
- * @param {() => Array<object>} deps.listLocalDrives
33
- * @param {(body: object) => Promise<object>} deps.probeMachineRecord
34
- * @param {(id: string) => Promise<boolean>} deps.setCurrent
35
- * @param {() => string} deps.knownHostsFile
36
- * @returns {Array<object>} route descriptors for registerHttpTransports.
37
- */
38
- export function createWorkspaceRoutes({ sendJson, readBody, parseJsonObject, config, pool, backendFor, status, isRemoteDir, persistWorkspace, ensureMirror, aliasOf, activeMachine, startAutoPush, applyRequestedMachine, registerMirroredWorkspace, localPickCapability, pickLocalNative, listLocalDrives, probeMachineRecord, setCurrent, knownHostsFile }) {
39
- return [
40
- {
41
- kind: 'exact',
42
- path: '/dsh-remote/connect',
43
- handler: async (req, res) => {
44
- if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
45
- // Issue #30: `payload` is declared OUTSIDE the try block on purpose.
46
- // A `const payload` inside `try` is scoped to that block, so the catch
47
- // below used to throw `ReferenceError: payload is not defined` BEFORE
48
- // it could send anything — the webserver then turned the rejected
49
- // handler into an empty HTTP 400 and the real reason never reached the
50
- // UI. Hoisting it (and defaulting to {}) makes the failure path total:
51
- // this handler now always answers with JSON.
52
- let payload = {}
53
- try {
54
- payload = parseJsonObject(await readBody(req))
55
- // This route is a reconnect PROBE ("Connect" button): with the
56
- // unchanged-target no-op in setTarget, an identical target would
57
- // reuse a possibly half-open cached client and the probe could hang.
58
- // invalidate() is the design's forced-reconnect escape hatch — drop
59
- // the cached client so the `echo ok` below always re-dials.
60
- pool.invalidate()
61
- pool.setTarget({
62
- host: payload.host,
63
- port: payload.port,
64
- username: payload.username,
65
- password: payload.password !== undefined && payload.password !== '' ? payload.password : undefined,
66
- privateKeyPath: payload.privateKeyPath,
67
- workspace: payload.workspace,
68
- // A credential-less target — including an alias from ~/.ssh/config
69
- // whose Host block relies on OpenSSH's default keys — cannot connect
70
- // on native; dial it through the user's own ssh instead.
71
- backend: backendFor(payload, config),
72
- })
73
- await pool.exec('echo ok', { timeoutMs: Math.min(config.commandTimeoutMs, 8000) })
74
- return sendJson(res, 200, { ok: true, ...status() })
75
- } catch (err) {
76
- return sendJson(res, (err && err.httpStatus) || 500, { ok: false, error: friendlyMessage(err, { host: payload.host, port: payload.port }) })
77
- }
78
- },
79
- },
80
- {
81
- kind: 'exact',
82
- path: '/dsh-remote/workspace',
83
- handler: async (req, res) => {
84
- if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
85
- try {
86
- const payload = JSON.parse((await readBody(req)) || '{}')
87
- // Blank-only guard: a filesystem root is a legal workspace (issue
88
- // #60); the real directory probe below answers everything else.
89
- const rawPath = String(payload.path || '').trim()
90
- if (!rawPath) return sendJson(res, 400, { error: 'path must be an absolute directory' })
91
- const p = normalizeRemotePath(rawPath)
92
- const okDir = await isRemoteDir(p)
93
- if (!okDir) return sendJson(res, 400, { ok: false, error: `not a directory: ${p}` })
94
- persistWorkspace(p)
95
- const local = ensureMirror(p, config.host, config.username, config.port, { alias: aliasOf(activeMachine()) })
96
- startAutoPush(local)
97
- return sendJson(res, 200, { ok: true, workspace: p, localMirror: local, ...status() })
98
- } catch (err) {
99
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
100
- }
101
- },
102
- },
103
- {
104
- kind: 'exact',
105
- path: '/dsh-remote/mirror',
106
- handler: async (req, res) => {
107
- if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
108
- try {
109
- const payload = JSON.parse((await readBody(req)) || '{}')
110
- // Blank-only guard: a filesystem root is a legal workspace (issue
111
- // #60); the real directory probe below answers everything else.
112
- const rawPath = String(payload.path || '').trim()
113
- if (!rawPath) return sendJson(res, 400, { ok: false, error: 'path must be an absolute directory' })
114
- const p = normalizeRemotePath(rawPath)
115
- if (!config.host) return sendJson(res, 400, { ok: false, error: 'no remote host configured/connected — connect first' })
116
- // The picker names the machine it was browsing. Re-assert it so a
117
- // switch made elsewhere between the listing and this commit cannot
118
- // mirror onto a machine the user never looked at (the picker sends
119
- // /current only once per machine now, so nothing else re-applies it).
120
- if (!(await applyRequestedMachine(payload, res))) return
121
- const okDir = await isRemoteDir(p)
122
- if (!okDir) return sendJson(res, 400, { ok: false, error: `not a directory (or unreachable): ${p}` })
123
- const local = ensureMirror(p, config.host, config.username, config.port, { alias: aliasOf(activeMachine()) })
124
- persistWorkspace(p)
125
- startAutoPush(local)
126
- // The native "Add workspace" picker adopts the mirror right after this
127
- // response (`workspace.create({ path: localMirror })`). Registering it
128
- // here first is the only way to influence the title, because the core
129
- // Create API takes no title and would derive "xdfs" from the mirror's
130
- // last segment. Callers that only pick a folder (settings page, Remote
131
- // Files explorer) opt out with registerWorkspace:false, so no stray
132
- // workspace appears in their flow.
133
- if (payload.registerWorkspace !== false) await registerMirroredWorkspace(local, p, activeMachine())
134
- return sendJson(res, 200, { ok: true, path: p, localMirror: local, ...status() })
135
- } catch (err) {
136
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
137
- }
138
- },
139
- },
140
- {
141
- kind: 'exact',
142
- path: '/dsh-remote/local-pick',
143
- handler: async (req, res) => {
144
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
145
- try {
146
- let outcome = null
147
- let via = 'service'
148
- const cap = await localPickCapability()
149
- if (cap && cap.kind === 'native' && typeof cap.pick === 'function') {
150
- try {
151
- const pickAbort = new AbortController()
152
- const p = await Promise.resolve(cap.pick(pickAbort.signal || null))
153
- pickAbort.abort()
154
- outcome = (typeof p === 'string' && p) ? { path: p } : { cancelled: true }
155
- } catch (err) {
156
- outcome = null
157
- }
158
- }
159
- // Prefer a REAL OS dialog over the browse backend: operators expect
160
- // an Explorer-style chooser, and the own spawn (PowerShell
161
- // FolderBrowserDialog / osascript / zenity-kdialog) works even where
162
- // the host mounted browse — DSH Desktop (Electron) deliberately
163
- // mounts browse on win32 because the native backend's koffi dialog
164
- // worker cannot run under Electron, but a plain child process can.
165
- if (!outcome) {
166
- via = 'own'
167
- try {
168
- outcome = await pickLocalNative()
169
- } catch (err) {
170
- // No usable OS dialog (headless host, missing chooser binary):
171
- // fall back to the host's browse capability — fs-only, works
172
- // display-less — served as an in-app browser by the client
173
- // (backed by /dsh-remote/local-list + /dsh-remote/local-mkdir).
174
- if (cap && cap.kind === 'browse' && typeof cap.list === 'function') {
175
- return sendJson(res, 200, { ok: true, kind: 'browse', via: 'browse' })
176
- }
177
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) + ' — 可直接在输入框填本地路径' })
178
- }
179
- }
180
- if (outcome.cancelled) return sendJson(res, 200, { ok: true, cancelled: true, via })
181
- return sendJson(res, 200, { ok: true, path: outcome.path, via })
182
- } catch (err) {
183
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
184
- }
185
- },
186
- },
187
- {
188
- kind: 'exact',
189
- path: '/dsh-remote/local-list',
190
- handler: async (req, res) => {
191
- if (req.method !== 'GET') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
192
- try {
193
- const cap = await localPickCapability()
194
- if (!cap || cap.kind !== 'browse' || typeof cap.list !== 'function') return sendJson(res, 400, { ok: false, error: '当前目录选择器不是浏览后端,无法列出本机目录' })
195
- const m = (req.url || '').match(/path=([^&]*)/)
196
- const raw = m ? decodeURIComponent(m[1]) : ''
197
- // No path → the browse backend lists the host home directory.
198
- try {
199
- const out = await Promise.resolve(cap.list(raw ? raw : undefined))
200
- return sendJson(res, 200, { ok: true, ...out, drives: listLocalDrives() })
201
- } catch (listErr) {
202
- return sendJson(res, 400, { ok: false, error: String((listErr && listErr.message) || listErr), code: (listErr && listErr.code) || 'directory-unreadable' })
203
- }
204
- } catch (err) {
205
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
206
- }
207
- },
208
- },
209
- {
210
- kind: 'exact',
211
- path: '/dsh-remote/local-mkdir',
212
- handler: async (req, res) => {
213
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
214
- try {
215
- const cap = await localPickCapability()
216
- if (!cap || cap.kind !== 'browse' || typeof cap.createDirectory !== 'function') return sendJson(res, 400, { ok: false, error: '当前目录选择器不是浏览后端,无法新建文件夹' })
217
- const payload = JSON.parse((await readBody(req)) || '{}')
218
- const p = String(payload.path || '')
219
- const name = String(payload.name || '')
220
- if (!p.trim() || !name.trim()) return sendJson(res, 400, { ok: false, error: 'path and name required' })
221
- try {
222
- const created = await Promise.resolve(cap.createDirectory(p, name))
223
- return sendJson(res, 200, { ok: true, path: created })
224
- } catch (mkErr) {
225
- return sendJson(res, 400, { ok: false, error: String((mkErr && mkErr.message) || mkErr), code: (mkErr && mkErr.code) || 'directory-create-failed' })
226
- }
227
- } catch (err) {
228
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
229
- }
230
- },
231
- },
232
- {
233
- kind: 'exact',
234
- path: '/dsh-remote/test-connect',
235
- handler: async (req, res) => {
236
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
237
- // Issue #30: `body` lives OUTSIDE the try — a try-scoped `const` is
238
- // invisible in catch, so the old catch threw `ReferenceError: body is
239
- // not defined` and the probe result never reached the UI (the webserver
240
- // answered with an empty 400 for every kind of failure). This route is a
241
- // probe: every outcome is a 200 carrying {ok:false, error}.
242
- let body = {}
243
- try {
244
- body = parseJsonObject(await readBody(req))
245
- return sendJson(res, 200, await probeMachineRecord(body))
246
- } catch (err) {
247
- return sendJson(res, 200, { ok: false, error: friendlyMessage(err, { host: body.host, port: body.port }) })
248
- }
249
- },
250
- },
251
- {
252
- kind: 'exact',
253
- path: '/dsh-remote/current',
254
- handler: async (req, res) => {
255
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
256
- try {
257
- const body = JSON.parse((await readBody(req)) || '{}')
258
- const id = String(body.id || '').trim()
259
- // Issue #13: an empty id is an explicit "active remote = none" —
260
- // saved machines stay in the registry but nothing is current.
261
- if (!id) {
262
- await setCurrent('')
263
- return sendJson(res, 200, { ok: true, currentId: null, ...status() })
264
- }
265
- const okSet = await setCurrent(id)
266
- if (!okSet) return sendJson(res, 404, { ok: false, error: 'machine not found' })
267
- return sendJson(res, 200, { ok: true, ...status() })
268
- } catch (err) {
269
- return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
270
- }
271
- },
272
- },
273
- {
274
- kind: 'exact',
275
- path: '/dsh-remote/forget-key',
276
- handler: async (req, res) => {
277
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
278
- createHostKeyGuard(config, knownHostsFile()).forgetHost()
279
- return sendJson(res, 200, { ok: true, ...status() })
280
- },
281
- },
282
- {
283
- kind: 'exact',
284
- path: '/dsh-remote/home',
285
- handler: async (req, res) => {
286
- if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
287
- try {
288
- const body = parseJsonObject(await readBody(req))
289
- // The picker names the machine it is showing: re-assert it before
290
- // answering, so a switch made elsewhere cannot make /home describe a
291
- // different host than the tree the user is looking at.
292
- if (!(await applyRequestedMachine(body, res))) return
293
- const out = await pool.exec('echo ~', { timeoutMs: Math.min(config.commandTimeoutMs, 5000) })
294
- const home = String(out.stdout || '').replace(/\s+/g, '').trim()
295
- if (!home) return sendJson(res, 200, { ok: true, home: null, hint: 'Windows 远程暂不支持 ~ 解析,请直接输入绝对路径' })
296
- return sendJson(res, 200, { ok: true, home })
297
- } catch (err) {
298
- // `ok:false` — reporting `ok:true` WITH an `error` is a contradiction:
299
- // any caller that trusts `ok` treats "could not resolve the home
300
- // directory" as success. The picker only reads `home`, so it still falls
301
- // back to `hint`/`error` exactly as before.
302
- return sendJson(res, 200, {
303
- ok: false,
304
- home: null,
305
- hint: 'Windows 远程暂不支持 ~ 解析,请直接输入绝对路径',
306
- error: String((err && err.message) || err),
307
- })
308
- }
309
- },
310
- },
311
- ]
312
- }
1
+ // Mirror/connection routes: /connect /workspace /mirror /local-pick
2
+ // /local-list /local-mkdir /test-connect /current /forget-key /home.
3
+ //
4
+ // Extracted from lib/index.js (issue #82: the god-file split). Handler bodies
5
+ // moved VERBATIM. Pure helpers come straight from their leaf modules
6
+ // (paths/errors/hostkey); everything that closes over entry state — the active
7
+ // pool, the mirror registry writers, the machine-store plumbing shared with the
8
+ // in-process API — arrives as `deps`.
9
+ import { normalizeRemotePath } from './paths.js'
10
+ import { friendlyMessage } from './errors.js'
11
+ import { createHostKeyGuard } from './hostkey.js'
12
+
13
+ /**
14
+ * @param {object} deps
15
+ * @param {(res: object, status: number, body: object) => void} deps.sendJson
16
+ * @param {(req: object) => Promise<string>} deps.readBody
17
+ * @param {(raw: string) => object} deps.parseJsonObject - 400-throwing object parser.
18
+ * @param {object} deps.config - validated plugin Config (MUTATED by setTarget flows).
19
+ * @param {object} deps.pool - the ACTIVE machine pool (ActivePool facade).
20
+ * @param {(m: object, cfg: object) => string} deps.backendFor - native vs openssh choice.
21
+ * @param {() => object} deps.status - the entry's status snapshot.
22
+ * @param {(p: string) => Promise<boolean>} deps.isRemoteDir
23
+ * @param {(p: string) => void} deps.persistWorkspace
24
+ * @param {(remotePath: string, host: string, user: string, port: number, extra?: object) => string} deps.ensureMirror
25
+ * @param {(m: object) => string} deps.aliasOf
26
+ * @param {() => object|null} deps.activeMachine
27
+ * @param {(localDir: string) => void} deps.startAutoPush
28
+ * @param {(body: object, res: object) => Promise<boolean>} deps.applyRequestedMachine - picker re-assertion (replies on mismatch).
29
+ * @param {(localDir: string, remotePath: string, machine: object) => Promise<void>} deps.registerMirroredWorkspace
30
+ * @param {() => Promise<object>} deps.localPickCapability - host picker backend probe.
31
+ * @param {() => Promise<object>} deps.pickLocalNative - the OS dialog fallback.
32
+ * @param {() => Array<object>} deps.listLocalDrives
33
+ * @param {(body: object) => Promise<object>} deps.probeMachineRecord
34
+ * @param {(id: string) => Promise<boolean>} deps.setCurrent
35
+ * @param {() => string} deps.knownHostsFile
36
+ * @returns {Array<object>} route descriptors for registerHttpTransports.
37
+ */
38
+ export function createWorkspaceRoutes({ sendJson, readBody, parseJsonObject, config, pool, backendFor, status, isRemoteDir, persistWorkspace, ensureMirror, aliasOf, activeMachine, startAutoPush, applyRequestedMachine, registerMirroredWorkspace, localPickCapability, pickLocalNative, listLocalDrives, probeMachineRecord, setCurrent, knownHostsFile }) {
39
+ return [
40
+ {
41
+ kind: 'exact',
42
+ path: '/dsh-remote/connect',
43
+ handler: async (req, res) => {
44
+ if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
45
+ // Issue #30: `payload` is declared OUTSIDE the try block on purpose.
46
+ // A `const payload` inside `try` is scoped to that block, so the catch
47
+ // below used to throw `ReferenceError: payload is not defined` BEFORE
48
+ // it could send anything — the webserver then turned the rejected
49
+ // handler into an empty HTTP 400 and the real reason never reached the
50
+ // UI. Hoisting it (and defaulting to {}) makes the failure path total:
51
+ // this handler now always answers with JSON.
52
+ let payload = {}
53
+ try {
54
+ payload = parseJsonObject(await readBody(req))
55
+ // This route is a reconnect PROBE ("Connect" button): with the
56
+ // unchanged-target no-op in setTarget, an identical target would
57
+ // reuse a possibly half-open cached client and the probe could hang.
58
+ // invalidate() is the design's forced-reconnect escape hatch — drop
59
+ // the cached client so the `echo ok` below always re-dials.
60
+ pool.invalidate()
61
+ pool.setTarget({
62
+ host: payload.host,
63
+ port: payload.port,
64
+ username: payload.username,
65
+ password: payload.password !== undefined && payload.password !== '' ? payload.password : undefined,
66
+ privateKeyPath: payload.privateKeyPath,
67
+ workspace: payload.workspace,
68
+ // A credential-less target — including an alias from ~/.ssh/config
69
+ // whose Host block relies on OpenSSH's default keys — cannot connect
70
+ // on native; dial it through the user's own ssh instead.
71
+ backend: backendFor(payload, config),
72
+ })
73
+ await pool.exec('echo ok', { timeoutMs: Math.min(config.commandTimeoutMs, 8000) })
74
+ return sendJson(res, 200, { ok: true, ...status() })
75
+ } catch (err) {
76
+ return sendJson(res, (err && err.httpStatus) || 500, { ok: false, error: friendlyMessage(err, { host: payload.host, port: payload.port }) })
77
+ }
78
+ },
79
+ },
80
+ {
81
+ kind: 'exact',
82
+ path: '/dsh-remote/workspace',
83
+ handler: async (req, res) => {
84
+ if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
85
+ try {
86
+ const payload = JSON.parse((await readBody(req)) || '{}')
87
+ // Blank-only guard: a filesystem root is a legal workspace (issue
88
+ // #60); the real directory probe below answers everything else.
89
+ const rawPath = String(payload.path || '').trim()
90
+ if (!rawPath) return sendJson(res, 400, { error: 'path must be an absolute directory' })
91
+ const p = normalizeRemotePath(rawPath)
92
+ const okDir = await isRemoteDir(p)
93
+ if (!okDir) return sendJson(res, 400, { ok: false, error: `not a directory: ${p}` })
94
+ persistWorkspace(p)
95
+ const local = ensureMirror(p, config.host, config.username, config.port, { alias: aliasOf(activeMachine()) })
96
+ startAutoPush(local)
97
+ return sendJson(res, 200, { ok: true, workspace: p, localMirror: local, ...status() })
98
+ } catch (err) {
99
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
100
+ }
101
+ },
102
+ },
103
+ {
104
+ kind: 'exact',
105
+ path: '/dsh-remote/mirror',
106
+ handler: async (req, res) => {
107
+ if (req.method !== 'POST') return sendJson(res, 405, { error: 'method not allowed' })
108
+ try {
109
+ const payload = JSON.parse((await readBody(req)) || '{}')
110
+ // Blank-only guard: a filesystem root is a legal workspace (issue
111
+ // #60); the real directory probe below answers everything else.
112
+ const rawPath = String(payload.path || '').trim()
113
+ if (!rawPath) return sendJson(res, 400, { ok: false, error: 'path must be an absolute directory' })
114
+ const p = normalizeRemotePath(rawPath)
115
+ if (!config.host) return sendJson(res, 400, { ok: false, error: 'no remote host configured/connected — connect first' })
116
+ // The picker names the machine it was browsing. Re-assert it so a
117
+ // switch made elsewhere between the listing and this commit cannot
118
+ // mirror onto a machine the user never looked at (the picker sends
119
+ // /current only once per machine now, so nothing else re-applies it).
120
+ if (!(await applyRequestedMachine(payload, res))) return
121
+ const okDir = await isRemoteDir(p)
122
+ if (!okDir) return sendJson(res, 400, { ok: false, error: `not a directory (or unreachable): ${p}` })
123
+ const local = ensureMirror(p, config.host, config.username, config.port, { alias: aliasOf(activeMachine()) })
124
+ persistWorkspace(p)
125
+ startAutoPush(local)
126
+ // The native "Add workspace" picker adopts the mirror right after this
127
+ // response (`workspace.create({ path: localMirror })`). Registering it
128
+ // here first is the only way to influence the title, because the core
129
+ // Create API takes no title and would derive "xdfs" from the mirror's
130
+ // last segment. Callers that only pick a folder (settings page, Remote
131
+ // Files explorer) opt out with registerWorkspace:false, so no stray
132
+ // workspace appears in their flow.
133
+ if (payload.registerWorkspace !== false) await registerMirroredWorkspace(local, p, activeMachine())
134
+ return sendJson(res, 200, { ok: true, path: p, localMirror: local, ...status() })
135
+ } catch (err) {
136
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
137
+ }
138
+ },
139
+ },
140
+ {
141
+ kind: 'exact',
142
+ path: '/dsh-remote/local-pick',
143
+ handler: async (req, res) => {
144
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
145
+ try {
146
+ let outcome = null
147
+ let via = 'service'
148
+ const cap = await localPickCapability()
149
+ if (cap && cap.kind === 'native' && typeof cap.pick === 'function') {
150
+ try {
151
+ const pickAbort = new AbortController()
152
+ const p = await Promise.resolve(cap.pick(pickAbort.signal || null))
153
+ pickAbort.abort()
154
+ outcome = (typeof p === 'string' && p) ? { path: p } : { cancelled: true }
155
+ } catch (err) {
156
+ outcome = null
157
+ }
158
+ }
159
+ // Prefer a REAL OS dialog over the browse backend: operators expect
160
+ // an Explorer-style chooser, and the own spawn (PowerShell
161
+ // FolderBrowserDialog / osascript / zenity-kdialog) works even where
162
+ // the host mounted browse — DSH Desktop (Electron) deliberately
163
+ // mounts browse on win32 because the native backend's koffi dialog
164
+ // worker cannot run under Electron, but a plain child process can.
165
+ if (!outcome) {
166
+ via = 'own'
167
+ try {
168
+ outcome = await pickLocalNative()
169
+ } catch (err) {
170
+ // No usable OS dialog (headless host, missing chooser binary):
171
+ // fall back to the host's browse capability — fs-only, works
172
+ // display-less — served as an in-app browser by the client
173
+ // (backed by /dsh-remote/local-list + /dsh-remote/local-mkdir).
174
+ if (cap && cap.kind === 'browse' && typeof cap.list === 'function') {
175
+ return sendJson(res, 200, { ok: true, kind: 'browse', via: 'browse' })
176
+ }
177
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) + ' — 可直接在输入框填本地路径' })
178
+ }
179
+ }
180
+ if (outcome.cancelled) return sendJson(res, 200, { ok: true, cancelled: true, via })
181
+ return sendJson(res, 200, { ok: true, path: outcome.path, via })
182
+ } catch (err) {
183
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
184
+ }
185
+ },
186
+ },
187
+ {
188
+ kind: 'exact',
189
+ path: '/dsh-remote/local-list',
190
+ handler: async (req, res) => {
191
+ if (req.method !== 'GET') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
192
+ try {
193
+ const cap = await localPickCapability()
194
+ if (!cap || cap.kind !== 'browse' || typeof cap.list !== 'function') return sendJson(res, 400, { ok: false, error: '当前目录选择器不是浏览后端,无法列出本机目录' })
195
+ const m = (req.url || '').match(/path=([^&]*)/)
196
+ const raw = m ? decodeURIComponent(m[1]) : ''
197
+ // No path → the browse backend lists the host home directory.
198
+ try {
199
+ const out = await Promise.resolve(cap.list(raw ? raw : undefined))
200
+ return sendJson(res, 200, { ok: true, ...out, drives: listLocalDrives() })
201
+ } catch (listErr) {
202
+ return sendJson(res, 400, { ok: false, error: String((listErr && listErr.message) || listErr), code: (listErr && listErr.code) || 'directory-unreadable' })
203
+ }
204
+ } catch (err) {
205
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
206
+ }
207
+ },
208
+ },
209
+ {
210
+ kind: 'exact',
211
+ path: '/dsh-remote/local-mkdir',
212
+ handler: async (req, res) => {
213
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
214
+ try {
215
+ const cap = await localPickCapability()
216
+ if (!cap || cap.kind !== 'browse' || typeof cap.createDirectory !== 'function') return sendJson(res, 400, { ok: false, error: '当前目录选择器不是浏览后端,无法新建文件夹' })
217
+ const payload = JSON.parse((await readBody(req)) || '{}')
218
+ const p = String(payload.path || '')
219
+ const name = String(payload.name || '')
220
+ if (!p.trim() || !name.trim()) return sendJson(res, 400, { ok: false, error: 'path and name required' })
221
+ try {
222
+ const created = await Promise.resolve(cap.createDirectory(p, name))
223
+ return sendJson(res, 200, { ok: true, path: created })
224
+ } catch (mkErr) {
225
+ return sendJson(res, 400, { ok: false, error: String((mkErr && mkErr.message) || mkErr), code: (mkErr && mkErr.code) || 'directory-create-failed' })
226
+ }
227
+ } catch (err) {
228
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
229
+ }
230
+ },
231
+ },
232
+ {
233
+ kind: 'exact',
234
+ path: '/dsh-remote/test-connect',
235
+ handler: async (req, res) => {
236
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
237
+ // Issue #30: `body` lives OUTSIDE the try — a try-scoped `const` is
238
+ // invisible in catch, so the old catch threw `ReferenceError: body is
239
+ // not defined` and the probe result never reached the UI (the webserver
240
+ // answered with an empty 400 for every kind of failure). This route is a
241
+ // probe: every outcome is a 200 carrying {ok:false, error}.
242
+ let body = {}
243
+ try {
244
+ body = parseJsonObject(await readBody(req))
245
+ return sendJson(res, 200, await probeMachineRecord(body))
246
+ } catch (err) {
247
+ return sendJson(res, 200, { ok: false, error: friendlyMessage(err, { host: body.host, port: body.port }) })
248
+ }
249
+ },
250
+ },
251
+ {
252
+ kind: 'exact',
253
+ path: '/dsh-remote/current',
254
+ handler: async (req, res) => {
255
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
256
+ try {
257
+ const body = JSON.parse((await readBody(req)) || '{}')
258
+ const id = String(body.id || '').trim()
259
+ // Issue #13: an empty id is an explicit "active remote = none" —
260
+ // saved machines stay in the registry but nothing is current.
261
+ if (!id) {
262
+ await setCurrent('')
263
+ return sendJson(res, 200, { ok: true, currentId: null, ...status() })
264
+ }
265
+ const okSet = await setCurrent(id)
266
+ if (!okSet) return sendJson(res, 404, { ok: false, error: 'machine not found' })
267
+ return sendJson(res, 200, { ok: true, ...status() })
268
+ } catch (err) {
269
+ return sendJson(res, 500, { ok: false, error: String((err && err.message) || err) })
270
+ }
271
+ },
272
+ },
273
+ {
274
+ kind: 'exact',
275
+ path: '/dsh-remote/forget-key',
276
+ handler: async (req, res) => {
277
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
278
+ createHostKeyGuard(config, knownHostsFile()).forgetHost()
279
+ return sendJson(res, 200, { ok: true, ...status() })
280
+ },
281
+ },
282
+ {
283
+ kind: 'exact',
284
+ path: '/dsh-remote/home',
285
+ handler: async (req, res) => {
286
+ if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
287
+ try {
288
+ const body = parseJsonObject(await readBody(req))
289
+ // The picker names the machine it is showing: re-assert it before
290
+ // answering, so a switch made elsewhere cannot make /home describe a
291
+ // different host than the tree the user is looking at.
292
+ if (!(await applyRequestedMachine(body, res))) return
293
+ const out = await pool.exec('echo ~', { timeoutMs: Math.min(config.commandTimeoutMs, 5000) })
294
+ const home = String(out.stdout || '').replace(/\s+/g, '').trim()
295
+ if (!home) return sendJson(res, 200, { ok: true, home: null, hint: 'Windows 远程暂不支持 ~ 解析,请直接输入绝对路径' })
296
+ return sendJson(res, 200, { ok: true, home })
297
+ } catch (err) {
298
+ // `ok:false` — reporting `ok:true` WITH an `error` is a contradiction:
299
+ // any caller that trusts `ok` treats "could not resolve the home
300
+ // directory" as success. The picker only reads `home`, so it still falls
301
+ // back to `hint`/`error` exactly as before.
302
+ return sendJson(res, 200, {
303
+ ok: false,
304
+ home: null,
305
+ hint: 'Windows 远程暂不支持 ~ 解析,请直接输入绝对路径',
306
+ error: String((err && err.message) || err),
307
+ })
308
+ }
309
+ },
310
+ },
311
+ ]
312
+ }