@andy.ian/dsh-homing 0.0.0-stage → 2.0.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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -2
  3. package/bin/auth.mjs +159 -0
  4. package/bin/backup.mjs +118 -0
  5. package/bin/bootstrap-server.mjs +436 -0
  6. package/bin/entry-link.mjs +69 -0
  7. package/bin/nginx-dsh.template.conf +91 -0
  8. package/bin/nginx-gate.conf +9 -0
  9. package/bin/nginx-ws-map.conf +5 -0
  10. package/bin/renew-cert.mjs +127 -0
  11. package/bin/watchdog.mjs +158 -0
  12. package/cordis.patch.yml +30 -0
  13. package/icon.svg +9 -0
  14. package/index.js +3339 -0
  15. package/lib/csrf.mjs +60 -0
  16. package/lib/devices.mjs +221 -0
  17. package/lib/files-page.mjs +391 -0
  18. package/lib/files.mjs +464 -0
  19. package/lib/git.mjs +154 -0
  20. package/lib/limits.mjs +135 -0
  21. package/lib/pty.mjs +354 -0
  22. package/lib/session.mjs +216 -0
  23. package/lib/shell-page.mjs +430 -0
  24. package/lib/shell.mjs +274 -0
  25. package/lib/term-app.js +318 -0
  26. package/lib/term-page.mjs +117 -0
  27. package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
  28. package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
  29. package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
  30. package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
  31. package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
  32. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
  33. package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
  34. package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
  35. package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
  36. package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
  37. package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
  38. package/lib/vendor/node_modules/asn1/LICENSE +19 -0
  39. package/lib/vendor/node_modules/asn1/README.md +50 -0
  40. package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  41. package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  42. package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  43. package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  44. package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  45. package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
  46. package/lib/vendor/node_modules/asn1/package.json +31 -0
  47. package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  48. package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  49. package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  50. package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  51. package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  52. package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
  53. package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  54. package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
  55. package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  56. package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
  57. package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
  58. package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
  59. package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
  60. package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
  61. package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
  62. package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
  63. package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
  64. package/lib/vendor/node_modules/ssh2/README.md +1529 -0
  65. package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
  66. package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
  67. package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
  68. package/lib/vendor/node_modules/ssh2/install.js +27 -0
  69. package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
  70. package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
  71. package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
  72. package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
  73. package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
  74. package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
  75. package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
  76. package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
  77. package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
  78. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
  79. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  80. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
  81. package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
  82. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
  83. package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
  84. package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
  85. package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
  86. package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
  87. package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
  88. package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
  89. package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
  90. package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
  91. package/lib/vendor/node_modules/ssh2/package.json +49 -0
  92. package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
  93. package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
  94. package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
  95. package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
  96. package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
  97. package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
  98. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
  99. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
  100. package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
  101. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
  102. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
  103. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
  104. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
  105. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
  106. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
  107. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
  108. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
  109. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
  110. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
  111. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
  112. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
  113. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
  114. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
  115. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
  116. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
  117. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
  118. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
  119. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
  120. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
  121. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
  122. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
  123. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
  124. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
  125. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
  126. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
  127. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
  128. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
  129. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
  130. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
  131. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
  132. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
  133. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
  134. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
  135. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
  136. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
  137. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
  138. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
  139. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
  140. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
  141. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
  142. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
  143. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
  144. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
  145. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
  146. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
  147. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
  148. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
  149. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
  150. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
  151. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
  152. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
  153. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
  154. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
  155. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
  156. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
  157. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
  158. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
  159. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
  160. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
  161. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
  162. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
  163. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
  164. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
  165. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
  166. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
  167. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
  168. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
  169. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
  170. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
  171. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
  172. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
  173. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
  174. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
  175. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
  176. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
  177. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
  178. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
  179. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
  180. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
  181. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
  182. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
  183. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
  184. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
  185. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
  186. package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
  187. package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
  188. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
  189. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
  190. package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
  191. package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
  192. package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
  193. package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
  194. package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
  195. package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
  196. package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
  197. package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
  198. package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
  199. package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
  200. package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
  201. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
  202. package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
  203. package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
  204. package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
  205. package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
  206. package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
  207. package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
  208. package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
  209. package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
  210. package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
  211. package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
  212. package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
  213. package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
  214. package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
  215. package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
  216. package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
  217. package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
  218. package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
  219. package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
  220. package/lib/vendor/xterm.css +218 -0
  221. package/lib/vendor/xterm.js +2 -0
  222. package/locale/en.json +6 -0
  223. package/locale/zh.json +6 -0
  224. package/ops/watchdog/dsh-watchdog.ps1 +105 -0
  225. package/ops/watchdog/restart-now.ps1 +247 -0
  226. package/package.json +69 -4
@@ -0,0 +1,391 @@
1
+ /**
2
+ * /files 页面模板。独立模块,所以可以正常使用模板字面量(不再受插件内嵌字符串的限制)。
3
+ * 全部服务端渲染 + 原生表单:微信/鸿蒙浏览器里最稳,不依赖任何 JS 框架。
4
+ */
5
+
6
+ const escapeHtml = (value) => String(value ?? '')
7
+ .replaceAll('&', '&')
8
+ .replaceAll('<', '&lt;')
9
+ .replaceAll('>', '&gt;')
10
+ .replaceAll('"', '&quot;')
11
+ .replaceAll("'", '&#39;')
12
+
13
+ const STYLE = `
14
+ :root { color-scheme: dark; }
15
+ body { margin:0; font-family: system-ui, -apple-system, "Noto Sans SC", sans-serif; background:#0f1115; color:#e8eaed; }
16
+ .wrap { padding: 12px 12px 70px; }
17
+ h1 { font-size: 16px; margin: 6px 0 10px; }
18
+ .bar { position: sticky; top: 0; z-index: 5; background:#0f1115; padding: 8px 0; border-bottom:1px solid #21262f; }
19
+ .path { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color:#9aa4b2; word-break: break-all; }
20
+ .row { display:flex; gap:8px; margin-top:8px; }
21
+ input[type=text] { flex:1; min-width:0; padding:10px; border-radius:8px; border:1px solid #2a2f3a; background:#171a21; color:#e8eaed; font-size:14px; }
22
+ button { padding:10px 14px; border:0; border-radius:8px; background:#4f7cff; color:#fff; font-size:14px; font-weight:600; }
23
+ button.ghost { background:#2a2f3a; color:#c7cdd8; font-weight:500; }
24
+ button.small { padding:6px 10px; font-size:12px; }
25
+ table { width:100%; border-collapse: collapse; margin-top:10px; }
26
+ td { padding:10px 6px; border-bottom:1px solid #1c2029; font-size:14px; vertical-align: middle; }
27
+ td.size, td.time { color:#8b93a1; font-size:12px; white-space:nowrap; text-align:right; }
28
+ td.ops { text-align:right; white-space:nowrap; }
29
+ a { color:#8ab4f8; text-decoration:none; }
30
+ .dir { color:#8fd8a8; }
31
+ .exe { color:#f2c14e; }
32
+ pre { background:#12151b; border:1px solid #21262f; border-radius:10px; padding:12px; overflow:auto; font-size:12px; line-height:1.5; }
33
+ .msg { margin-top:12px; padding:10px 12px; border-radius:10px; background:rgba(79,124,255,.12); border:1px solid rgba(79,124,255,.35); color:#b8ccff; font-size:13px; }
34
+ .err { background:rgba(255,80,80,.1); border-color:rgba(255,80,80,.35); color:#ff9b9b; }
35
+ .crumbs { font-size:12px; color:#8b93a1; margin-top:6px; word-break:break-all; }
36
+ .chips { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
37
+ .chip { background:#1b2030; border:1px solid #2a3550; color:#9fc0ff; border-radius:999px; padding:6px 12px; font-size:12px; }
38
+ .crumb { color:#8ab4f8; }
39
+ .kbd { font-family: ui-monospace, Menlo, Consolas, monospace; background:#1d2229; padding:1px 5px; border-radius:4px; font-size:12px; }
40
+ `
41
+
42
+ export function layout({ title, body }) {
43
+ return `<!doctype html>
44
+ <html lang="zh-CN"><head><meta charset="utf-8">
45
+ <meta name="viewport" content="width=device-width, initial-scale=1">
46
+ <title>${escapeHtml(title)} · DSH 文件</title>
47
+ <style>${STYLE}</style></head>
48
+ <body><div class="wrap">${body}</div></body></html>`
49
+ }
50
+
51
+ const messageHtml = (message, isError) => (message
52
+ ? `<div class="msg${isError ? ' err' : ''}">${escapeHtml(message)}</div>`
53
+ : '')
54
+
55
+ /** 目录列表页 */
56
+ export function renderListing({ info, message, isError, home, dataDir, workspaces = [] }) {
57
+ const rows = info.entries.map((entry) => {
58
+ const label = escapeHtml(entry.name)
59
+ const nameCell = entry.dir
60
+ ? `<a class="dir" href="/files?path=${encodeURIComponent(entry.path)}">📁 ${label}/</a>`
61
+ : `<a class="${entry.runnable ? 'exe' : ''}" href="/files/view?path=${encodeURIComponent(entry.path)}">${entry.runnable ? '⚙️' : '📄'} ${label}</a>`
62
+ + (entry.runnable ? '' : ` <a href="/files/edit?path=${encodeURIComponent(entry.path)}" title="编辑"
63
+ style="font-size:12px;color:#9fc0ff;white-space:nowrap">✏️</a>`)
64
+ // 运行改成链接:先进入运行页,可以填参数(很多脚本需要参数,比如提交信息)
65
+ const ops = entry.runnable
66
+ ? `<a class="small" href="/files/run?path=${encodeURIComponent(entry.path)}"
67
+ style="display:inline-block;padding:6px 12px;border-radius:8px;background:#4f7cff;color:#fff;font-size:12px;font-weight:600;text-decoration:none">运行</a>`
68
+ : ''
69
+ return `<tr><td>${nameCell}</td><td class="size">${escapeHtml(entry.sizeText)}</td>`
70
+ + `<td class="time">${escapeHtml(entry.mtime)}</td><td class="ops">${ops}</td></tr>`
71
+ }).join('')
72
+
73
+ const parent = info.parent
74
+ ? `<a class="btn ghost" href="/files?path=${encodeURIComponent(info.parent)}">上一级</a>`
75
+ : ''
76
+
77
+ const chips = workspaces.length === 0 ? '' : `
78
+ <div class="chips">
79
+ ${workspaces.map((w) => `<a class="chip" href="/files?path=${encodeURIComponent(w.path)}" title="${escapeHtml(w.path)}">${escapeHtml(w.title)}</a>`).join('')}
80
+ </div>`;
81
+
82
+ const body = `
83
+ <div class="bar">
84
+ <h1>文件</h1>
85
+ <form method="get" action="/files" class="row">
86
+ <input type="text" name="path" list="path-suggestions" value="${escapeHtml(info.path)}" placeholder="输入绝对路径">
87
+ <datalist id="path-suggestions">
88
+ ${[home, dataDir, ...workspaces.map((w) => w.path)].map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
89
+ </datalist>
90
+ <button type="submit">前往</button>
91
+ </form>
92
+ <div class="row">
93
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(home)}" style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">主目录</a>
94
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(dataDir)}" style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">DSH 数据</a>
95
+ ${parent}
96
+ <a class="btn ghost" href="/git?path=${encodeURIComponent(info.path)}"
97
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">Git</a>
98
+ </div>
99
+ </div>
100
+ ${chips}
101
+ ${messageHtml(message, isError)}
102
+ ${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
103
+ ${info.truncated ? `<div class="msg">目录项过多,只显示前 2000 个</div>` : ''}
104
+ <table>${rows || '<tr><td style="color:#8b93a1">空目录</td></tr>'}</table>
105
+ <p class="crumbs">提示:点目录进入,点文件名查看内容;标 ⚙️ 的可直接运行(会在这台电脑上执行)。</p>`
106
+
107
+ return layout({ title: info.path, body })
108
+ }
109
+
110
+ /** 文件内容页 */
111
+ export function renderFile({ info, message, isError }) {
112
+ const body = `
113
+ <div class="bar">
114
+ <h1>${escapeHtml(info.path.split(/[\\/]/u).pop() ?? info.path)}</h1>
115
+ <div class="path">${escapeHtml(info.path)}</div>
116
+ </div>
117
+ ${messageHtml(message, isError)}
118
+ ${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
119
+ ${info.text !== undefined ? `<pre>${escapeHtml(info.text)}</pre>` : ''}
120
+ <div class="row">
121
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(info.path.replace(/[\\/][^\\/]*$/u, '') || '/')}"
122
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
123
+ </div>
124
+ ${info.sizeText ? `<p class="crumbs">大小 ${escapeHtml(info.sizeText)}${info.mtime ? ` · ${escapeHtml(info.mtime)}` : ''}</p>` : ''}`
125
+ return layout({ title: info.path, body })
126
+ }
127
+
128
+ /** 运行结果页 */
129
+ export function renderRunResult({ file, result }) {
130
+ const failed = !result.ok || result.timedOut || (typeof result.code === 'number' && result.code !== 0)
131
+ const body = `
132
+ <div class="bar">
133
+ <h1>运行结果</h1>
134
+ <div class="path">${escapeHtml(file)}</div>
135
+ </div>
136
+ ${failed
137
+ ? `<div class="msg err">${escapeHtml(result.error ?? (result.timedOut ? '执行超时(15 秒),已终止' : `退出码 ${result.code}`))}</div>`
138
+ : `<div class="msg">退出码 ${result.code}</div>`}
139
+ <pre>${escapeHtml(result.output === '' ? '(无输出)' : result.output)}</pre>
140
+ ${result.truncated ? '<p class="crumbs">输出过长,已截断到 64 KB</p>' : ''}
141
+ <div class="row">
142
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(file.replace(/[\\/][^\\/]*$/u, '') || '/')}"
143
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
144
+ </div>`
145
+ return layout({ title: `运行 ${file}`, body })
146
+ }
147
+
148
+ /** 运行页:可填参数,结果同页显示,便于改参数重跑 */
149
+ export function renderRunPage({ file, args = '', result = null }) {
150
+ const failed = result !== null && (!result.ok || result.timedOut || (typeof result.code === 'number' && result.code !== 0))
151
+ const body = `
152
+ <div class="bar">
153
+ <h1>运行</h1>
154
+ <div class="path">${escapeHtml(file)}</div>
155
+ </div>
156
+ <form method="post" action="/files/run">
157
+ <input type="hidden" name="path" value="${escapeHtml(file)}">
158
+ <label style="display:block;margin-top:12px;font-size:13px;color:#9aa4b2">参数(可留空)</label>
159
+ <input type="text" name="args" value="${escapeHtml(args)}" placeholder="例如:\"feat: 新功能\" -DryRun"
160
+ style="width:100%;box-sizing:border-box">
161
+ <div class="row">
162
+ <button type="submit" style="flex:1">运行</button>
163
+ </div>
164
+ </form>
165
+ ${result === null ? '' : `
166
+ <div class="msg${failed ? ' err' : ''}" style="margin-top:14px">${failed
167
+ ? escapeHtml(result.error ?? (result.timedOut ? '执行超时(15 秒),已终止' : `退出码 ${result.code}`))
168
+ : `退出码 ${result.code}`}</div>
169
+ <pre>${escapeHtml(result.output === '' ? '(无输出)' : result.output)}</pre>
170
+ `}
171
+ <div class="row">
172
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(file.replace(/[\\/][^\\/]*$/u, '') || '/')}"
173
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
174
+ </div>`
175
+ return layout({ title: `运行 ${file}`, body })
176
+ }
177
+
178
+ /** git 页:仓库路径 + 快捷命令 + 任意 git 参数 + 输出 */
179
+ export function renderGitPage({ repoPath, summary = null, args = '', result = null, message = '', suggestions = [], repoPaths = [] }) {
180
+ const quick = [
181
+ ['status --short --branch', '状态'],
182
+ ['log --oneline -20', '最近 20 条'],
183
+ ['diff --stat', '改动统计'],
184
+ ['diff', '改动详情'],
185
+ ['branch -a', '分支'],
186
+ ['pull', '拉取'],
187
+ ['push', '推送'],
188
+ ]
189
+ const failed = result !== null && result.ok === false
190
+ const body = `
191
+ <div class="bar">
192
+ <h1>Git</h1>
193
+ <form method="get" action="/git" class="row">
194
+ <input type="text" name="path" list="repo-paths" value="${escapeHtml(repoPath)}" placeholder="仓库目录(绝对路径)">
195
+ <datalist id="repo-paths">
196
+ ${repoPaths.map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
197
+ </datalist>
198
+ <button type="submit">打开</button>
199
+ </form>
200
+ <div class="row">
201
+ <a class="btn ghost" href="/git?path=${encodeURIComponent(repoPath)}"
202
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">刷新</a>
203
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(repoPath)}"
204
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">看文件</a>
205
+ </div>
206
+ </div>
207
+ ${message ? `<div class="msg">${escapeHtml(message)}</div>` : ''}
208
+ ${summary === null ? '' : `
209
+ <div class="msg" style="margin-top:10px">
210
+ 分支 <span class="kbd">${escapeHtml(summary.branch || '?')}</span>
211
+ · 改动 <span class="kbd">${summary.dirty.length}</span> 个文件
212
+ ${summary.remote ? `· 远端 ${escapeHtml(summary.remote)}` : ''}
213
+ ${summary.last ? `<br><span style="color:#8b93a1">最近提交:${escapeHtml(summary.last)}</span>` : ''}
214
+ </div>
215
+ ${summary.dirty.length === 0 ? '' : `<pre>${escapeHtml(summary.dirty.slice(0, 40).join('\n'))}</pre>`}
216
+ `}
217
+ <h2 style="font-size:14px;color:#9aa4b2;margin:18px 0 6px">快捷命令</h2>
218
+ <div style="display:flex;flex-wrap:wrap;gap:6px">
219
+ ${quick.map(([cmd, label]) => `<form method="post" action="/git/run" style="display:inline">
220
+ <input type="hidden" name="path" value="${escapeHtml(repoPath)}">
221
+ <input type="hidden" name="args" value="${escapeHtml(cmd)}">
222
+ <button class="small" type="submit"
223
+ style="padding:8px 12px;border-radius:8px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(label)}</button>
224
+ </form>`).join('')}
225
+ </div>
226
+ <h2 style="font-size:14px;color:#9aa4b2;margin:18px 0 6px">任意 git 命令</h2>
227
+ <datalist id="git-args">
228
+ ${suggestions.map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
229
+ </datalist>
230
+ <form method="post" action="/git/run">
231
+ <input type="hidden" name="path" value="${escapeHtml(repoPath)}">
232
+ <input type="text" name="args" list="git-args" value="${escapeHtml(args)}" placeholder='例如:commit -m "fix: 修好了"'
233
+ style="width:100%;box-sizing:border-box">
234
+ <div class="row"><button type="submit" style="flex:1">执行</button></div>
235
+ </form>
236
+
237
+ <div style="display:flex;flex-wrap:wrap;gap:6px;margin-top:8px">
238
+ ${suggestions.slice(0, 14).map((item) => `<form method="post" action="/git/run" style="display:inline">
239
+ <input type="hidden" name="path" value="${escapeHtml(repoPath)}">
240
+ <input type="hidden" name="args" value="${escapeHtml(item)}">
241
+ <button type="submit" style="padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(item)}</button>
242
+ </form>`).join('')}
243
+ </div>
244
+ ${result === null ? '' : `
245
+ <div class="msg${failed ? ' err' : ''}" style="margin-top:14px">
246
+ ${failed ? escapeHtml(result.error ?? (result.timeout ? '超时,已终止' : `退出码 ${result.code}`)) : `退出码 ${result.code} · ${escapeHtml(args)}`}
247
+ </div>
248
+ <pre>${escapeHtml(result.output ?? '')}</pre>
249
+ `}
250
+ <p class="crumbs">命令只执行 git 本身,不经过 shell;push/pull 用你本机已配置的凭据。</p>`
251
+ return layout({ title: 'Git', body })
252
+ }
253
+
254
+ /** 编辑页:textarea + 保存 */
255
+ export function renderEditPage({ info, message = '', isError = false }) {
256
+ const body = `
257
+ <div class="bar">
258
+ <h1>编辑</h1>
259
+ <div class="path">${escapeHtml(info.path)}</div>
260
+ </div>
261
+ ${messageHtml(message, isError)}
262
+ ${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
263
+ ${info.text === undefined ? '' : `
264
+ <form method="post" action="/files/edit">
265
+ <input type="hidden" name="path" value="${escapeHtml(info.path)}">
266
+ <textarea name="text" spellcheck="false"
267
+ style="width:100%;box-sizing:border-box;min-height:60vh;margin-top:10px;padding:12px;border-radius:10px;
268
+ border:1px solid #2a2f3a;background:#12151b;color:#e8eaed;font-family:ui-monospace,Menlo,Consolas,monospace;
269
+ font-size:12px;line-height:1.5">${escapeHtml(info.text)}</textarea>
270
+ <div class="row"><button type="submit" style="flex:1">保存</button></div>
271
+ </form>`}
272
+ <div class="row">
273
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(info.path.replace(/[\\/][^\\/]*$/u, '') || '/')}"
274
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
275
+ </div>
276
+ ${info.sizeText ? `<p class="crumbs">大小 ${escapeHtml(info.sizeText)}</p>` : ''}`
277
+ return layout({ title: `编辑 ${info.path}`, body })
278
+ }
279
+
280
+ /** shell 页(手机端 Git Bash):命令 + 工作目录 + 输出 */
281
+ export function renderShellPage({ cwd, command = '', result = null, history = [], shellName = '' }) {
282
+ const failed = result !== null && (result.ok === false || (typeof result.code === 'number' && result.code !== 0))
283
+ const body = `
284
+ <div class="bar">
285
+ <h1>终端</h1>
286
+ <div class="path">${escapeHtml(cwd)}${shellName ? ' · ' + escapeHtml(shellName) : ''}</div>
287
+ </div>
288
+ <form method="post" action="/shell">
289
+ <label style="display:block;margin-top:10px;font-size:13px;color:#9aa4b2">工作目录</label>
290
+ <input type="text" name="cwd" list="shell-paths" value="${escapeHtml(cwd)}" style="width:100%;box-sizing:border-box">
291
+ <label style="display:block;margin-top:10px;font-size:13px;color:#9aa4b2">命令</label>
292
+ <input type="text" id="cmd" name="command" value="${escapeHtml(command)}" autocomplete="off" autocapitalize="off"
293
+ autocorrect="off" spellcheck="false"
294
+ placeholder='例如:git status / ls -la / npm test'
295
+ style="width:100%;box-sizing:border-box">
296
+ <div class="row">
297
+ <button type="submit" style="flex:2">执行</button>
298
+ <button type="button" id="tabkey" style="flex:1;background:#2a2f3a;color:#c7cdd8">Tab</button>
299
+ <button type="submit" name="action" value="reset" formnovalidate style="flex:1;background:#3a2a2a;color:#f0b6bf">重置</button>
300
+ </div>
301
+ </form>
302
+ <div id="cands" style="display:flex;flex-wrap:wrap;gap:6px;margin-top:8px"></div>
303
+ <script id="shell-complete.js">
304
+ (function () {
305
+ var input = document.getElementById('cmd');
306
+ var box = document.getElementById('cands');
307
+ var cwdInput = document.querySelector('input[name=cwd]');
308
+ if (!input || !box) return;
309
+ var timer = null;
310
+ function apply(value) {
311
+ var text = input.value;
312
+ var m = text.match(/(\\S+)$/);
313
+ input.value = (m ? text.slice(0, m.index) : text) + value;
314
+ input.focus();
315
+ refresh();
316
+ }
317
+ function render(items) {
318
+ box.innerHTML = '';
319
+ items.slice(0, 12).forEach(function (item) {
320
+ var btn = document.createElement('button');
321
+ btn.type = 'button';
322
+ btn.textContent = item.label;
323
+ btn.style.cssText = 'padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px';
324
+ btn.addEventListener('click', function () { apply(item.value); });
325
+ box.appendChild(btn);
326
+ });
327
+ }
328
+ function refresh() {
329
+ var cwd = cwdInput ? cwdInput.value : '';
330
+ var line = input.value;
331
+ if (line.trim() === '') { box.innerHTML = ''; return; }
332
+ fetch('/shell/complete?cwd=' + encodeURIComponent(cwd) + '&line=' + encodeURIComponent(line))
333
+ .then(function (r) { return r.ok ? r.json() : []; })
334
+ .then(function (items) { render(Array.isArray(items) ? items : []); })
335
+ .catch(function () { /* 忽略补全失败 */ });
336
+ }
337
+ function completeNow() {
338
+ var cwd = cwdInput ? cwdInput.value : '';
339
+ var line = input.value;
340
+ if (line.trim() === '') return;
341
+ fetch('/shell/complete?cwd=' + encodeURIComponent(cwd) + '&line=' + encodeURIComponent(line))
342
+ .then(function (r) { return r.ok ? r.json() : []; })
343
+ .then(function (items) {
344
+ if (!Array.isArray(items) || items.length === 0) {
345
+ box.textContent = '无候选';
346
+ setTimeout(function () { box.textContent = ''; }, 1200);
347
+ return;
348
+ }
349
+ render(items);
350
+ if (items.length === 1) { apply(items[0].value); return; }
351
+ // 多个候选:把最后一段改成它们的公共前缀(像 bash 的 Tab 那样)
352
+ var prefix = items[0].value;
353
+ for (var i = 1; i < items.length; i += 1) {
354
+ while (prefix.length > 0 && items[i].value.indexOf(prefix) !== 0) prefix = prefix.slice(0, -1);
355
+ }
356
+ if (prefix.length > 0) apply(prefix);
357
+ })
358
+ .catch(function () { /* 忽略 */ });
359
+ }
360
+ var tabBtn = document.getElementById('tabkey');
361
+ if (tabBtn) tabBtn.addEventListener('click', completeNow);
362
+
363
+ input.addEventListener('input', function () {
364
+ clearTimeout(timer);
365
+ timer = setTimeout(refresh, 250);
366
+ });
367
+ input.addEventListener('focus', refresh);
368
+ })();
369
+ </script>
370
+ ${history.length === 0 ? '' : `<div style="display:flex;flex-wrap:wrap;gap:6px;margin-top:10px">
371
+ ${history.slice(0, 8).map((cmd) => `<form method="post" action="/shell" style="display:inline">
372
+ <input type="hidden" name="cwd" value="${escapeHtml(cwd)}">
373
+ <input type="hidden" name="command" value="${escapeHtml(cmd)}">
374
+ <button type="submit" style="padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(cmd)}</button>
375
+ </form>`).join('')}
376
+ </div>`}
377
+ ${result === null ? '' : `
378
+ <div class="msg${failed ? ' err' : ''}" style="margin-top:14px">
379
+ ${failed ? escapeHtml(result.error ?? (result.timeout ? '超时(30 秒),已终止' : `退出码 ${result.code}`)) : `退出码 ${result.code}`}
380
+ </div>
381
+ <pre>${escapeHtml(result.output ?? '')}</pre>
382
+ `}
383
+ <div class="row">
384
+ <a class="btn ghost" href="/git?path=${encodeURIComponent(cwd)}"
385
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">Git 页</a>
386
+ <a class="btn ghost" href="/files?path=${encodeURIComponent(cwd)}"
387
+ style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">文件</a>
388
+ </div>
389
+ <p class="crumbs">命令直接在你电脑上执行,输出截断到 64KB,30 秒超时。可以用 cd 切换工作目录。</p>`
390
+ return layout({ title: '终端', body })
391
+ }