@andy.ian/dsh-homing 0.0.0-stage → 2.0.1
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/LICENSE +21 -0
- package/README.md +71 -2
- package/bin/auth.mjs +159 -0
- package/bin/backup.mjs +118 -0
- package/bin/bootstrap-server.mjs +436 -0
- package/bin/entry-link.mjs +69 -0
- package/bin/nginx-dsh.template.conf +91 -0
- package/bin/nginx-gate.conf +9 -0
- package/bin/nginx-ws-map.conf +5 -0
- package/bin/renew-cert.mjs +127 -0
- package/bin/supervisor.mjs +488 -0
- package/bin/watchdog.mjs +163 -0
- package/client.js +79 -0
- package/cordis.patch.yml +30 -0
- package/icon.svg +9 -0
- package/index.js +3526 -0
- package/lib/csrf.mjs +60 -0
- package/lib/devices.mjs +221 -0
- package/lib/files-page.mjs +592 -0
- package/lib/files.mjs +551 -0
- package/lib/git.mjs +154 -0
- package/lib/limits.mjs +135 -0
- package/lib/pty.mjs +361 -0
- package/lib/session.mjs +216 -0
- package/lib/shell-page.mjs +430 -0
- package/lib/shell.mjs +274 -0
- package/lib/term-app.js +318 -0
- package/lib/term-page.mjs +117 -0
- package/lib/vendor/fonts/JetBrainsMono-Regular.ttf +0 -0
- package/lib/vendor/fonts/jetbrains-mono-400.woff2 +0 -0
- package/lib/vendor/fonts/jetbrains-mono-700.woff2 +0 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/LICENSE +19 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/README.md +24 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js +2 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/lib/addon-fit.js.map +1 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/package.json +26 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/src/FitAddon.ts +90 -0
- package/lib/vendor/node_modules/@xterm/addon-fit/typings/addon-fit.d.ts +55 -0
- package/lib/vendor/node_modules/asn1/Jenkinsfile +65 -0
- package/lib/vendor/node_modules/asn1/LICENSE +19 -0
- package/lib/vendor/node_modules/asn1/README.md +50 -0
- package/lib/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
- package/lib/vendor/node_modules/asn1/lib/ber/index.js +27 -0
- package/lib/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
- package/lib/vendor/node_modules/asn1/lib/ber/types.js +36 -0
- package/lib/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
- package/lib/vendor/node_modules/asn1/lib/index.js +20 -0
- package/lib/vendor/node_modules/asn1/package.json +31 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
- package/lib/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
- package/lib/vendor/node_modules/safer-buffer/LICENSE +21 -0
- package/lib/vendor/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/lib/vendor/node_modules/safer-buffer/Readme.md +156 -0
- package/lib/vendor/node_modules/safer-buffer/dangerous.js +58 -0
- package/lib/vendor/node_modules/safer-buffer/package.json +34 -0
- package/lib/vendor/node_modules/safer-buffer/safer.js +77 -0
- package/lib/vendor/node_modules/safer-buffer/tests.js +406 -0
- package/lib/vendor/node_modules/ssh2/.eslintignore +4 -0
- package/lib/vendor/node_modules/ssh2/.eslintrc.js +5 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/ci.yml +110 -0
- package/lib/vendor/node_modules/ssh2/.github/workflows/lint.yml +27 -0
- package/lib/vendor/node_modules/ssh2/LICENSE +19 -0
- package/lib/vendor/node_modules/ssh2/README.md +1529 -0
- package/lib/vendor/node_modules/ssh2/SFTP.md +413 -0
- package/lib/vendor/node_modules/ssh2/examples/server-chat.js +238 -0
- package/lib/vendor/node_modules/ssh2/examples/sftp-server-download-only.js +134 -0
- package/lib/vendor/node_modules/ssh2/install.js +27 -0
- package/lib/vendor/node_modules/ssh2/lib/Channel.js +295 -0
- package/lib/vendor/node_modules/ssh2/lib/agent.js +1123 -0
- package/lib/vendor/node_modules/ssh2/lib/client.js +2176 -0
- package/lib/vendor/node_modules/ssh2/lib/http-agents.js +84 -0
- package/lib/vendor/node_modules/ssh2/lib/index.js +44 -0
- package/lib/vendor/node_modules/ssh2/lib/keygen.js +582 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/Protocol.js +2136 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/SFTP.js +4052 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/constants.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/binding.gyp +23 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/poly1305.js +43 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto/src/binding.cc +2300 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/crypto.js +1602 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.js +16 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/handlers.misc.js +1285 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/kex.js +1908 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/keyParser.js +1484 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/node-fs-compat.js +115 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/utils.js +356 -0
- package/lib/vendor/node_modules/ssh2/lib/protocol/zlib.js +255 -0
- package/lib/vendor/node_modules/ssh2/lib/server.js +1380 -0
- package/lib/vendor/node_modules/ssh2/lib/utils.js +336 -0
- package/lib/vendor/node_modules/ssh2/package.json +49 -0
- package/lib/vendor/node_modules/ssh2/test/common.js +316 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/bad_rsa_private_key +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_cert.pem +33 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/https_key.pem +52 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa.ppk +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/id_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa +21 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc +22 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm +23 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_dsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ecdsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519 +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_ed25519.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc +28 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm +29 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_new_rsa_enc_gcm.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc +15 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_ecdsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc +30 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.pub.result +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256 +54 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub +1 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.pub.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/openssh_old_rsa_enc_aes256.result +6 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc +17 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_dsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa +26 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc +18 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/ppk_rsa_enc.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub +9 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub +10 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa2.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa3.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub +11 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa4.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub +8 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa5.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub +13 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/keyParser/rfc4716_rsa6.pub.result +7 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/openssh_new_rsa +27 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_dsa_key +12 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_ecdsa_key +5 -0
- package/lib/vendor/node_modules/ssh2/test/fixtures/ssh_host_rsa_key +15 -0
- package/lib/vendor/node_modules/ssh2/test/test-exec.js +578 -0
- package/lib/vendor/node_modules/ssh2/test/test-integration-openssh.js +486 -0
- package/lib/vendor/node_modules/ssh2/test/test-keygen.js +60 -0
- package/lib/vendor/node_modules/ssh2/test/test-misc-client-server.js +1460 -0
- package/lib/vendor/node_modules/ssh2/test/test-openssh.js +261 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-crypto.js +631 -0
- package/lib/vendor/node_modules/ssh2/test/test-protocol-keyparser.js +177 -0
- package/lib/vendor/node_modules/ssh2/test/test-server-hostkeys.js +138 -0
- package/lib/vendor/node_modules/ssh2/test/test-sftp.js +842 -0
- package/lib/vendor/node_modules/ssh2/test/test-shell.js +109 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent-openssh.js +110 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth-agent.js +171 -0
- package/lib/vendor/node_modules/ssh2/test/test-userauth.js +611 -0
- package/lib/vendor/node_modules/ssh2/test/test-worker-imports.js +25 -0
- package/lib/vendor/node_modules/ssh2/test/test.js +20 -0
- package/lib/vendor/node_modules/ssh2/util/build_pagent.bat +2 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.c +88 -0
- package/lib/vendor/node_modules/ssh2/util/pagent.exe +0 -0
- package/lib/vendor/node_modules/tweetnacl/AUTHORS.md +27 -0
- package/lib/vendor/node_modules/tweetnacl/CHANGELOG.md +283 -0
- package/lib/vendor/node_modules/tweetnacl/LICENSE +24 -0
- package/lib/vendor/node_modules/tweetnacl/PULL_REQUEST_TEMPLATE.md +20 -0
- package/lib/vendor/node_modules/tweetnacl/README.md +494 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.js +2391 -0
- package/lib/vendor/node_modules/tweetnacl/nacl-fast.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.d.ts +98 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.js +1178 -0
- package/lib/vendor/node_modules/tweetnacl/nacl.min.js +1 -0
- package/lib/vendor/node_modules/tweetnacl/package.json +56 -0
- package/lib/vendor/xterm.css +218 -0
- package/lib/vendor/xterm.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/ops/watchdog/dsh-watchdog.ps1 +105 -0
- package/ops/watchdog/restart-hidden.vbs +7 -0
- package/ops/watchdog/restart-now.ps1 +261 -0
- package/ops/watchdog/run-hidden.vbs +4 -0
- package/package.json +71 -4
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /files 页面模板。独立模块,所以可以正常使用模板字面量(不再受插件内嵌字符串的限制)。
|
|
3
|
+
* 全部服务端渲染 + 原生表单:微信/鸿蒙浏览器里最稳,不依赖任何 JS 框架。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const escapeHtml = (value) => String(value ?? '')
|
|
7
|
+
.replaceAll('&', '&')
|
|
8
|
+
.replaceAll('<', '<')
|
|
9
|
+
.replaceAll('>', '>')
|
|
10
|
+
.replaceAll('"', '"')
|
|
11
|
+
.replaceAll("'", ''')
|
|
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}.flist { display: flex; flex-direction: column; }
|
|
48
|
+
.sortbar { display: flex; align-items: center; gap: 6px; padding: 6px 2px 8px; color: #8b93a1; font-size: 12px; }
|
|
49
|
+
.sortlabel { margin-right: 2px; }
|
|
50
|
+
.sortbtn { padding: 4px 9px; border-radius: 6px; background: #222833; border: 1px solid #333c48; color: #b9c3d1; font-size: 12px; }
|
|
51
|
+
.sortbtn[data-active="1"] { background: #2f3a49; color: #e6edf5; border-color: #4a586b; }
|
|
52
|
+
.fitem { position: relative; display: grid; grid-template-columns: 22px auto 1fr auto; grid-template-areas: "ico size size menu" "name name name menu"; align-items: center; gap: 2px 6px; padding: 9px 2px 11px; border-bottom: 1px solid #232a35; }
|
|
53
|
+
.fico { grid-area: ico; font-size: 15px; line-height: 1; }
|
|
54
|
+
.fsize { grid-area: size; justify-self: start; color: #8b93a1; font-size: 12px; white-space: nowrap; pointer-events: none; }
|
|
55
|
+
.ftime { grid-area: 1 / 2 / 2 / 4; text-align: center; color: #8b93a1; font-size: 12px; white-space: nowrap; pointer-events: none; }
|
|
56
|
+
.fname { grid-area: name; color: #dfe6ef; text-decoration: none; font-size: 15px; word-break: break-all; }
|
|
57
|
+
.fname.dir { color: #cfe3ff; }
|
|
58
|
+
.fname.exe { color: #ffd479; }
|
|
59
|
+
.fempty { padding: 18px 4px; color: #8b93a1; }
|
|
60
|
+
.flist .mm { grid-area: menu; }
|
|
61
|
+
</style></head>
|
|
62
|
+
<body><div class="wrap">${body}</div></body></html>`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const messageHtml = (message, isError) => (message
|
|
66
|
+
? `<div class="msg${isError ? ' err' : ''}">${escapeHtml(message)}</div>`
|
|
67
|
+
: '')
|
|
68
|
+
|
|
69
|
+
/** 目录列表页 */
|
|
70
|
+
const LONG_PRESS_JS = `<script>
|
|
71
|
+
(() => {
|
|
72
|
+
var openMenu = null;
|
|
73
|
+
function closeAll() {
|
|
74
|
+
document.querySelectorAll('.rowmenu').forEach(function (m) { m.hidden = true; });
|
|
75
|
+
openMenu = null;
|
|
76
|
+
}
|
|
77
|
+
function position(btn, menu) {
|
|
78
|
+
menu.style.left = '0px';
|
|
79
|
+
menu.style.top = '0px';
|
|
80
|
+
var r = btn.getBoundingClientRect();
|
|
81
|
+
var mw = menu.offsetWidth;
|
|
82
|
+
var mh = menu.offsetHeight;
|
|
83
|
+
var left = Math.max(8, Math.min(r.right - mw, window.innerWidth - mw - 8));
|
|
84
|
+
var up = (window.innerHeight - r.bottom) < (mh + 20);
|
|
85
|
+
var top = up ? (r.top - mh - 6) : (r.bottom + 6);
|
|
86
|
+
menu.style.left = left + 'px';
|
|
87
|
+
menu.style.top = Math.max(8, top) + 'px';
|
|
88
|
+
requestAnimationFrame(function () {
|
|
89
|
+
var w2 = menu.offsetWidth, h2 = menu.offsetHeight;
|
|
90
|
+
var l2 = Math.max(8, Math.min(r.right - w2, window.innerWidth - w2 - 8));
|
|
91
|
+
var t2 = ((window.innerHeight - r.bottom) < (h2 + 20)) ? (r.top - h2 - 6) : (r.bottom + 6);
|
|
92
|
+
menu.style.left = l2 + 'px';
|
|
93
|
+
menu.style.top = Math.max(8, t2) + 'px';
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
document.addEventListener('click', function (e) {
|
|
97
|
+
var btn = e.target.closest ? e.target.closest('.mm-btn') : null;
|
|
98
|
+
if (btn) {
|
|
99
|
+
e.preventDefault(); e.stopPropagation();
|
|
100
|
+
var menu = btn.parentNode.querySelector('.rowmenu');
|
|
101
|
+
var wasOpen = openMenu === menu;
|
|
102
|
+
closeAll();
|
|
103
|
+
if (!wasOpen) { menu.hidden = false; position(btn, menu); openMenu = menu; }
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
var act = e.target.closest ? e.target.closest('.mi') : null;
|
|
107
|
+
if (act) {
|
|
108
|
+
e.preventDefault(); e.stopPropagation();
|
|
109
|
+
var kind = act.getAttribute('data-act');
|
|
110
|
+
var path = act.getAttribute('data-path');
|
|
111
|
+
closeAll();
|
|
112
|
+
if (kind === 'edit') {
|
|
113
|
+
location.href = '/files/edit?path=' + encodeURIComponent(path);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (kind === 'run') {
|
|
117
|
+
location.href = '/files/run?path=' + encodeURIComponent(path);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (kind === 'copy' || kind === 'cut') {
|
|
121
|
+
try { localStorage.setItem('dsh-files-clip', JSON.stringify({ path: path, op: kind === 'cut' ? 'cut' : 'copy' })); } catch (error) { /* 忽略 */ }
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (kind === 'mkdir' || kind === 'newfile') {
|
|
125
|
+
var nm = window.prompt(kind === 'mkdir' ? '新文件夹名:' : '新文件名:', '');
|
|
126
|
+
if (!nm) return;
|
|
127
|
+
var api = kind === 'mkdir' ? '/files/mkdir' : '/files/newfile';
|
|
128
|
+
fetch(api, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
131
|
+
body: 'dir=' + encodeURIComponent(path) + '&name=' + encodeURIComponent(nm),
|
|
132
|
+
}).then(function () { location.reload(); }).catch(function () { location.reload(); });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (kind === 'paste') {
|
|
136
|
+
var raw = null;
|
|
137
|
+
try { raw = localStorage.getItem('dsh-files-clip'); } catch (error) { /* 忽略 */ }
|
|
138
|
+
if (!raw) { window.alert('剪贴板是空的,先点「复制」或「剪切」'); return; }
|
|
139
|
+
var clip = { path: raw, op: 'copy' };
|
|
140
|
+
try { var parsed = JSON.parse(raw); if (parsed && parsed.path) clip = parsed; } catch (error) { /* 兼容旧格式 */ }
|
|
141
|
+
fetch('/files/paste', {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
144
|
+
body: 'src=' + encodeURIComponent(clip.path) + '&dir=' + encodeURIComponent(path) + '&op=' + encodeURIComponent(clip.op || 'copy'),
|
|
145
|
+
}).then(function () {
|
|
146
|
+
try { if ((clip.op || 'copy') === 'cut') localStorage.removeItem('dsh-files-clip'); } catch (error) { /* 忽略 */ }
|
|
147
|
+
location.reload();
|
|
148
|
+
}).catch(function () { location.reload(); });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (kind === 'copypath') {
|
|
152
|
+
if (navigator.clipboard) navigator.clipboard.writeText(path);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (kind === 'rename') {
|
|
156
|
+
var next = window.prompt('重命名为:', act.getAttribute('data-name'));
|
|
157
|
+
if (!next) return;
|
|
158
|
+
fetch('/files/rename', {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
161
|
+
body: 'path=' + encodeURIComponent(path) + '&name=' + encodeURIComponent(next),
|
|
162
|
+
}).then(function () { location.reload(); }).catch(function () { location.reload(); });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (kind === 'delete') {
|
|
166
|
+
var isDir2 = act.getAttribute('data-dir') === '1';
|
|
167
|
+
if (!window.confirm(isDir2 ? '删除这个目录及其全部内容?' : '删除这个文件?')) return;
|
|
168
|
+
fetch('/files/delete', {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
171
|
+
body: 'path=' + encodeURIComponent(path),
|
|
172
|
+
}).then(function () { location.reload(); }).catch(function () { location.reload(); });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
closeAll();
|
|
178
|
+
}, true);
|
|
179
|
+
var sortState = { key: '', asc: true };
|
|
180
|
+
function applySort(key) {
|
|
181
|
+
var list = document.querySelector('.flist');
|
|
182
|
+
if (!list) return;
|
|
183
|
+
var asc = (sortState.key === key) ? !sortState.asc : true;
|
|
184
|
+
sortState = { key: key, asc: asc };
|
|
185
|
+
var items = Array.prototype.slice.call(list.querySelectorAll('.fitem'));
|
|
186
|
+
items.sort(function (a, b) {
|
|
187
|
+
var ad = a.getAttribute('data-dir') === '1', bd = b.getAttribute('data-dir') === '1';
|
|
188
|
+
if (ad !== bd) return ad ? -1 : 1;
|
|
189
|
+
var r = 0;
|
|
190
|
+
if (key === 'name') {
|
|
191
|
+
r = a.getAttribute('data-name').localeCompare(b.getAttribute('data-name'), 'zh');
|
|
192
|
+
} else if (key === 'size') {
|
|
193
|
+
r = Number(a.getAttribute('data-size')) - Number(b.getAttribute('data-size'));
|
|
194
|
+
} else {
|
|
195
|
+
r = Number(a.getAttribute('data-time')) - Number(b.getAttribute('data-time'));
|
|
196
|
+
}
|
|
197
|
+
return asc ? r : -r;
|
|
198
|
+
});
|
|
199
|
+
items.forEach(function (el) { list.appendChild(el); });
|
|
200
|
+
document.querySelectorAll('.sortbtn').forEach(function (btn) {
|
|
201
|
+
btn.setAttribute('data-active', btn.getAttribute('data-sort') === key ? '1' : '0');
|
|
202
|
+
btn.textContent = btn.getAttribute('data-sort') === 'name' ? '名称' : (btn.getAttribute('data-sort') === 'size' ? '大小' : '时间');
|
|
203
|
+
if (btn.getAttribute('data-sort') === key) btn.textContent += asc ? ' ↑' : ' ↓';
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
document.addEventListener('click', function (e) {
|
|
207
|
+
var btn = e.target.closest ? e.target.closest('.sortbtn') : null;
|
|
208
|
+
if (btn) { e.preventDefault(); applySort(btn.getAttribute('data-sort')); }
|
|
209
|
+
}, true);
|
|
210
|
+
document.addEventListener('keydown', function (e) { if (e.key === 'Escape') closeAll(); });
|
|
211
|
+
window.addEventListener('scroll', closeAll, { passive: true });
|
|
212
|
+
})();
|
|
213
|
+
</script>`;
|
|
214
|
+
|
|
215
|
+
export function renderListing({ info, message, isError, home, dataDir, workspaces = [] }) {
|
|
216
|
+
const menuFor = (entry) => `<span class="mm">
|
|
217
|
+
<button type="button" class="mm-btn" aria-haspopup="menu" title="更多操作">\u22ef</button>
|
|
218
|
+
<span class="rowmenu" hidden role="menu">
|
|
219
|
+
${entry.dir ? '' : `<a class="mi" role="menuitem" data-act="edit" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u270F\uFE0F</span>编辑</a>`}
|
|
220
|
+
${entry.runnable ? `<a class="mi" role="menuitem" data-act="run" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u25B6\uFE0F</span>执行</a>` : ''}
|
|
221
|
+
<a class="mi" role="menuitem" data-act="rename" data-path="${escapeHtml(entry.path)}" data-name="${escapeHtml(entry.name)}" href="#"><span class="ico">\u{1F3F7}\uFE0F</span>重命名</a>
|
|
222
|
+
<a class="mi" role="menuitem" data-act="cut" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u2702\uFE0F</span>剪切</a>
|
|
223
|
+
<a class="mi" role="menuitem" data-act="copy" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F4C4}</span>复制</a>
|
|
224
|
+
${entry.dir ? `<a class="mi" role="menuitem" data-act="paste" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F4E5}</span>粘贴到此处</a>
|
|
225
|
+
<a class="mi" role="menuitem" data-act="mkdir" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F4C1}</span>新建文件夹</a>
|
|
226
|
+
<a class="mi" role="menuitem" data-act="newfile" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F4C4}</span>新建文件</a>` : ''}
|
|
227
|
+
<a class="mi" role="menuitem" data-act="copypath" data-path="${escapeHtml(entry.path)}" href="#"><span class="ico">\u{1F4CB}</span>复制路径</a>
|
|
228
|
+
<a class="mi danger" role="menuitem" data-act="delete" data-path="${escapeHtml(entry.path)}" data-dir="${entry.dir ? 1 : 0}" href="#"><span class="ico">\u{1F5D1}\uFE0F</span>删除</a>
|
|
229
|
+
</span>
|
|
230
|
+
</span>`;
|
|
231
|
+
|
|
232
|
+
const rows = info.entries.map((entry) => {
|
|
233
|
+
const label = escapeHtml(entry.name);
|
|
234
|
+
const icon = entry.dir ? '\u{1F4C1}' : (entry.runnable ? '\u2699\uFE0F' : '\u{1F4C4}');
|
|
235
|
+
const nameHtml = entry.dir
|
|
236
|
+
? `<a class="fname dir" href="/files?path=${encodeURIComponent(entry.path)}">${label}</a>`
|
|
237
|
+
: `<a class="fname${entry.runnable ? ' exe' : ''}" href="/files/view?path=${encodeURIComponent(entry.path)}">${label}</a>`;
|
|
238
|
+
return `<div class="fitem" data-path="${escapeHtml(entry.path)}" data-name="${escapeHtml(entry.name)}" data-dir="${entry.dir ? 1 : 0}" data-size="${Number(entry.size) || 0}" data-time="${Number(entry.mtimeMs) || 0}">
|
|
239
|
+
<div class="fico">${icon}</div>
|
|
240
|
+
<div class="fsize">${escapeHtml(entry.sizeText ?? '')}</div>
|
|
241
|
+
<div class="ftime">${escapeHtml(entry.mtime ?? '')}</div>
|
|
242
|
+
${nameHtml}
|
|
243
|
+
${menuFor(entry)}
|
|
244
|
+
</div>`;
|
|
245
|
+
}).join('');
|
|
246
|
+
|
|
247
|
+
const navStyle = 'flex:0 0 auto;padding:4px 7px;border-radius:6px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:11px;line-height:1.4;white-space:nowrap'
|
|
248
|
+
const parent = info.parent
|
|
249
|
+
? `<a class="btn ghost" href="/files?path=${encodeURIComponent(info.parent)}" style="${navStyle}">上一级</a>`
|
|
250
|
+
: `<span style="${navStyle};opacity:.3">上一级</span>`
|
|
251
|
+
|
|
252
|
+
const chips = workspaces.length === 0 ? '' : `
|
|
253
|
+
<div class="chips">
|
|
254
|
+
${workspaces.map((w) => `<a class="chip" href="/files?path=${encodeURIComponent(w.path)}" title="${escapeHtml(w.path)}">${escapeHtml(w.title)}</a>`).join('')}
|
|
255
|
+
</div>`;
|
|
256
|
+
|
|
257
|
+
const body = `
|
|
258
|
+
<div class="bar">
|
|
259
|
+
<div style="display:flex;align-items:center;gap:8px;flex-wrap:nowrap;min-width:0">
|
|
260
|
+
<h1 style="margin:0;flex:0 0 auto;font-size:18px">文件</h1>
|
|
261
|
+
<div style="flex:1 1 auto;display:flex;align-items:center;justify-content:flex-end;gap:4px;flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none">
|
|
262
|
+
<a class="btn ghost" href="/" style="${navStyle}">DSH</a>
|
|
263
|
+
<a class="btn ghost" href="/term" style="${navStyle}">终端</a>
|
|
264
|
+
<a class="btn ghost" href="/git?path=${encodeURIComponent(info.path)}" style="${navStyle}">Git</a>
|
|
265
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(home)}" style="${navStyle}">HOME</a>
|
|
266
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(dataDir)}" style="${navStyle}">配置</a>
|
|
267
|
+
${parent}
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
<form method="get" action="/files" class="row">
|
|
271
|
+
<input type="text" name="path" list="path-suggestions" value="${escapeHtml(info.path)}" placeholder="输入绝对路径">
|
|
272
|
+
<datalist id="path-suggestions">
|
|
273
|
+
${[home, dataDir, ...workspaces.map((w) => w.path)].map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
|
|
274
|
+
</datalist>
|
|
275
|
+
<button type="submit">前往</button>
|
|
276
|
+
</form>
|
|
277
|
+
</div>
|
|
278
|
+
${chips}
|
|
279
|
+
${messageHtml(message, isError)}
|
|
280
|
+
${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
|
|
281
|
+
${info.truncated ? `<div class="msg">目录项过多,只显示前 2000 个</div>` : ''}
|
|
282
|
+
<style>
|
|
283
|
+
.mm { position: relative; display: inline-block; }
|
|
284
|
+
.mm-btn { margin-left: 6px; padding: 6px 10px; border-radius: 8px; background: #2a2f3a; border: 1px solid #3a4351; color: #c7cdd8; font-size: 14px; line-height: 1; }
|
|
285
|
+
.mm-btn:active { background: #3a4351; }
|
|
286
|
+
.rowmenu { position: fixed; z-index: 9999; min-width: 0; padding: 4px 0; background: #20262f; border: 1px solid #3a4351; border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.6); }
|
|
287
|
+
.rowmenu[hidden] { display: none; }
|
|
288
|
+
.rowmenu .mi { display: flex; align-items: center; gap: 9px; padding: 8px 14px 8px 10px; color: #e3e9f1; text-decoration: none; font-size: 13px; line-height: 1.35; white-space: nowrap; text-align: left; }
|
|
289
|
+
.rowmenu .ico { width: 18px; flex: 0 0 18px; text-align: center; opacity: .95; font-size: 13px; }
|
|
290
|
+
.rowmenu .mi.danger { color: #ff8f8f; }
|
|
291
|
+
.rowmenu .mi:first-child { border-radius: 8px 8px 0 0; }
|
|
292
|
+
.rowmenu .mi:last-child { border-radius: 0 0 8px 8px; }
|
|
293
|
+
.rowmenu .mi:active, .rowmenu .mi:hover { background: #333c48; }
|
|
294
|
+
</style>
|
|
295
|
+
<div class="sortbar">
|
|
296
|
+
<span class="sortlabel">排序</span>
|
|
297
|
+
<button type="button" class="sortbtn" data-sort="name">名称</button>
|
|
298
|
+
<button type="button" class="sortbtn" data-sort="size">大小</button>
|
|
299
|
+
<button type="button" class="sortbtn" data-sort="time">时间</button>
|
|
300
|
+
</div>
|
|
301
|
+
<div class="flist">${rows || '<div class="fempty">空目录</div>'}</div>
|
|
302
|
+
${LONG_PRESS_JS}\n <p class="crumbs">提示:点目录进入,点文件名查看内容;标 ⚙️ 的可直接运行(会在这台电脑上执行)。</p>`
|
|
303
|
+
|
|
304
|
+
return layout({ title: info.path, body })
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** 文件内容页 */
|
|
308
|
+
export function renderFile({ info, message, isError }) {
|
|
309
|
+
const body = `
|
|
310
|
+
<div class="bar">
|
|
311
|
+
<h1>${escapeHtml(info.path.split(/[\\/]/u).pop() ?? info.path)}</h1>
|
|
312
|
+
<div class="path">${escapeHtml(info.path)}</div>
|
|
313
|
+
</div>
|
|
314
|
+
${messageHtml(message, isError)}
|
|
315
|
+
${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
|
|
316
|
+
${info.text !== undefined ? `<pre>${escapeHtml(info.text)}</pre>` : ''}
|
|
317
|
+
<div class="row">
|
|
318
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(info.path.replace(/[\\/][^\\/]*$/u, '') || '/')}"
|
|
319
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
|
|
320
|
+
</div>
|
|
321
|
+
${info.sizeText ? `<p class="crumbs">大小 ${escapeHtml(info.sizeText)}${info.mtime ? ` · ${escapeHtml(info.mtime)}` : ''}</p>` : ''}`
|
|
322
|
+
return layout({ title: info.path, body })
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** 运行结果页 */
|
|
326
|
+
export function renderRunResult({ file, result }) {
|
|
327
|
+
const failed = !result.ok || result.timedOut || (typeof result.code === 'number' && result.code !== 0)
|
|
328
|
+
const body = `
|
|
329
|
+
<div class="bar">
|
|
330
|
+
<h1>运行结果</h1>
|
|
331
|
+
<div class="path">${escapeHtml(file)}</div>
|
|
332
|
+
</div>
|
|
333
|
+
${failed
|
|
334
|
+
? `<div class="msg err">${escapeHtml(result.error ?? (result.timedOut ? '执行超时(15 秒),已终止' : `退出码 ${result.code}`))}</div>`
|
|
335
|
+
: `<div class="msg">退出码 ${result.code}</div>`}
|
|
336
|
+
<pre>${escapeHtml(result.output === '' ? '(无输出)' : result.output)}</pre>
|
|
337
|
+
${result.truncated ? '<p class="crumbs">输出过长,已截断到 64 KB</p>' : ''}
|
|
338
|
+
<div class="row">
|
|
339
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(file.replace(/[\\/][^\\/]*$/u, '') || '/')}"
|
|
340
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
|
|
341
|
+
</div>`
|
|
342
|
+
return layout({ title: `运行 ${file}`, body })
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** 运行页:可填参数,结果同页显示,便于改参数重跑 */
|
|
346
|
+
export function renderRunPage({ file, args = '', result = null }) {
|
|
347
|
+
const failed = result !== null && (!result.ok || result.timedOut || (typeof result.code === 'number' && result.code !== 0))
|
|
348
|
+
const body = `
|
|
349
|
+
<div class="bar">
|
|
350
|
+
<h1>运行</h1>
|
|
351
|
+
<div class="path">${escapeHtml(file)}</div>
|
|
352
|
+
</div>
|
|
353
|
+
<form method="post" action="/files/run">
|
|
354
|
+
<input type="hidden" name="path" value="${escapeHtml(file)}">
|
|
355
|
+
<label style="display:block;margin-top:12px;font-size:13px;color:#9aa4b2">参数(可留空)</label>
|
|
356
|
+
<input type="text" name="args" value="${escapeHtml(args)}" placeholder="例如:\"feat: 新功能\" -DryRun"
|
|
357
|
+
style="width:100%;box-sizing:border-box">
|
|
358
|
+
<div class="row">
|
|
359
|
+
<button type="submit" style="flex:1">运行</button>
|
|
360
|
+
</div>
|
|
361
|
+
</form>
|
|
362
|
+
${result === null ? '' : `
|
|
363
|
+
<div class="msg${failed ? ' err' : ''}" style="margin-top:14px">${failed
|
|
364
|
+
? escapeHtml(result.error ?? (result.timedOut ? '执行超时(15 秒),已终止' : `退出码 ${result.code}`))
|
|
365
|
+
: `退出码 ${result.code}`}</div>
|
|
366
|
+
<pre>${escapeHtml(result.output === '' ? '(无输出)' : result.output)}</pre>
|
|
367
|
+
`}
|
|
368
|
+
<div class="row">
|
|
369
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(file.replace(/[\\/][^\\/]*$/u, '') || '/')}"
|
|
370
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
|
|
371
|
+
</div>`
|
|
372
|
+
return layout({ title: `运行 ${file}`, body })
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** git 页:仓库路径 + 快捷命令 + 任意 git 参数 + 输出 */
|
|
376
|
+
export function renderGitPage({ repoPath, summary = null, args = '', result = null, message = '', suggestions = [], repoPaths = [] }) {
|
|
377
|
+
const quick = [
|
|
378
|
+
['status --short --branch', '状态'],
|
|
379
|
+
['log --oneline -20', '最近 20 条'],
|
|
380
|
+
['diff --stat', '改动统计'],
|
|
381
|
+
['diff', '改动详情'],
|
|
382
|
+
['branch -a', '分支'],
|
|
383
|
+
['pull', '拉取'],
|
|
384
|
+
['push', '推送'],
|
|
385
|
+
]
|
|
386
|
+
const failed = result !== null && result.ok === false
|
|
387
|
+
const body = `
|
|
388
|
+
<div class="bar">
|
|
389
|
+
<h1>Git</h1>
|
|
390
|
+
<form method="get" action="/git" class="row">
|
|
391
|
+
<input type="text" name="path" list="repo-paths" value="${escapeHtml(repoPath)}" placeholder="仓库目录(绝对路径)">
|
|
392
|
+
<datalist id="repo-paths">
|
|
393
|
+
${repoPaths.map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
|
|
394
|
+
</datalist>
|
|
395
|
+
<button type="submit">打开</button>
|
|
396
|
+
</form>
|
|
397
|
+
<div class="row">
|
|
398
|
+
<a class="btn ghost" href="/git?path=${encodeURIComponent(repoPath)}"
|
|
399
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">刷新</a>
|
|
400
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(repoPath)}"
|
|
401
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">看文件</a>
|
|
402
|
+
<a class="btn ghost" href="/term"
|
|
403
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">终端</a>
|
|
404
|
+
<a class="btn ghost" href="/"
|
|
405
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">DSH</a>
|
|
406
|
+
</div>
|
|
407
|
+
</div>
|
|
408
|
+
${message ? `<div class="msg">${escapeHtml(message)}</div>` : ''}
|
|
409
|
+
${summary === null ? '' : `
|
|
410
|
+
<div class="msg" style="margin-top:10px">
|
|
411
|
+
分支 <span class="kbd">${escapeHtml(summary.branch || '?')}</span>
|
|
412
|
+
· 改动 <span class="kbd">${summary.dirty.length}</span> 个文件
|
|
413
|
+
${summary.remote ? `· 远端 ${escapeHtml(summary.remote)}` : ''}
|
|
414
|
+
${summary.last ? `<br><span style="color:#8b93a1">最近提交:${escapeHtml(summary.last)}</span>` : ''}
|
|
415
|
+
</div>
|
|
416
|
+
${summary.dirty.length === 0 ? '' : `<pre>${escapeHtml(summary.dirty.slice(0, 40).join('\n'))}</pre>`}
|
|
417
|
+
`}
|
|
418
|
+
<h2 style="font-size:14px;color:#9aa4b2;margin:18px 0 6px">快捷命令</h2>
|
|
419
|
+
<div style="display:flex;flex-wrap:wrap;gap:6px">
|
|
420
|
+
${quick.map(([cmd, label]) => `<form method="post" action="/git/run" style="display:inline">
|
|
421
|
+
<input type="hidden" name="path" value="${escapeHtml(repoPath)}">
|
|
422
|
+
<input type="hidden" name="args" value="${escapeHtml(cmd)}">
|
|
423
|
+
<button class="small" type="submit"
|
|
424
|
+
style="padding:8px 12px;border-radius:8px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(label)}</button>
|
|
425
|
+
</form>`).join('')}
|
|
426
|
+
</div>
|
|
427
|
+
<h2 style="font-size:14px;color:#9aa4b2;margin:18px 0 6px">任意 git 命令</h2>
|
|
428
|
+
<datalist id="git-args">
|
|
429
|
+
${suggestions.map((item) => `<option value="${escapeHtml(item)}"></option>`).join('')}
|
|
430
|
+
</datalist>
|
|
431
|
+
<form method="post" action="/git/run">
|
|
432
|
+
<input type="hidden" name="path" value="${escapeHtml(repoPath)}">
|
|
433
|
+
<input type="text" name="args" list="git-args" value="${escapeHtml(args)}" placeholder='例如:commit -m "fix: 修好了"'
|
|
434
|
+
style="width:100%;box-sizing:border-box">
|
|
435
|
+
<div class="row"><button type="submit" style="flex:1">执行</button></div>
|
|
436
|
+
</form>
|
|
437
|
+
|
|
438
|
+
<div style="display:flex;flex-wrap:wrap;gap:6px;margin-top:8px">
|
|
439
|
+
${suggestions.slice(0, 14).map((item) => `<form method="post" action="/git/run" style="display:inline">
|
|
440
|
+
<input type="hidden" name="path" value="${escapeHtml(repoPath)}">
|
|
441
|
+
<input type="hidden" name="args" value="${escapeHtml(item)}">
|
|
442
|
+
<button type="submit" style="padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(item)}</button>
|
|
443
|
+
</form>`).join('')}
|
|
444
|
+
</div>
|
|
445
|
+
${result === null ? '' : `
|
|
446
|
+
<div class="msg${failed ? ' err' : ''}" style="margin-top:14px">
|
|
447
|
+
${failed ? escapeHtml(result.error ?? (result.timeout ? '超时,已终止' : `退出码 ${result.code}`)) : `退出码 ${result.code} · ${escapeHtml(args)}`}
|
|
448
|
+
</div>
|
|
449
|
+
<pre>${escapeHtml(result.output ?? '')}</pre>
|
|
450
|
+
`}
|
|
451
|
+
<p class="crumbs">命令只执行 git 本身,不经过 shell;push/pull 用你本机已配置的凭据。</p>`
|
|
452
|
+
return layout({ title: 'Git', body })
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** 编辑页:textarea + 保存 */
|
|
456
|
+
export function renderEditPage({ info, message = '', isError = false }) {
|
|
457
|
+
const body = `
|
|
458
|
+
<div class="bar">
|
|
459
|
+
<h1>编辑</h1>
|
|
460
|
+
<div class="path">${escapeHtml(info.path)}</div>
|
|
461
|
+
</div>
|
|
462
|
+
${messageHtml(message, isError)}
|
|
463
|
+
${info.error ? `<div class="msg err">${escapeHtml(info.error)}</div>` : ''}
|
|
464
|
+
${info.text === undefined ? '' : `
|
|
465
|
+
<form method="post" action="/files/edit">
|
|
466
|
+
<input type="hidden" name="path" value="${escapeHtml(info.path)}">
|
|
467
|
+
<textarea name="text" spellcheck="false"
|
|
468
|
+
style="width:100%;box-sizing:border-box;min-height:60vh;margin-top:10px;padding:12px;border-radius:10px;
|
|
469
|
+
border:1px solid #2a2f3a;background:#12151b;color:#e8eaed;font-family:ui-monospace,Menlo,Consolas,monospace;
|
|
470
|
+
font-size:12px;line-height:1.5">${escapeHtml(info.text)}</textarea>
|
|
471
|
+
<div class="row"><button type="submit" style="flex:1">保存</button></div>
|
|
472
|
+
</form>`}
|
|
473
|
+
<div class="row">
|
|
474
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(info.path.replace(/[\\/][^\\/]*$/u, '') || '/')}"
|
|
475
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">返回目录</a>
|
|
476
|
+
</div>
|
|
477
|
+
${info.sizeText ? `<p class="crumbs">大小 ${escapeHtml(info.sizeText)}</p>` : ''}`
|
|
478
|
+
return layout({ title: `编辑 ${info.path}`, body })
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** shell 页(手机端 Git Bash):命令 + 工作目录 + 输出 */
|
|
482
|
+
export function renderShellPage({ cwd, command = '', result = null, history = [], shellName = '' }) {
|
|
483
|
+
const failed = result !== null && (result.ok === false || (typeof result.code === 'number' && result.code !== 0))
|
|
484
|
+
const body = `
|
|
485
|
+
<div class="bar">
|
|
486
|
+
<h1>终端</h1>
|
|
487
|
+
<div class="path">${escapeHtml(cwd)}${shellName ? ' · ' + escapeHtml(shellName) : ''}</div>
|
|
488
|
+
</div>
|
|
489
|
+
<form method="post" action="/shell">
|
|
490
|
+
<label style="display:block;margin-top:10px;font-size:13px;color:#9aa4b2">工作目录</label>
|
|
491
|
+
<input type="text" name="cwd" list="shell-paths" value="${escapeHtml(cwd)}" style="width:100%;box-sizing:border-box">
|
|
492
|
+
<label style="display:block;margin-top:10px;font-size:13px;color:#9aa4b2">命令</label>
|
|
493
|
+
<input type="text" id="cmd" name="command" value="${escapeHtml(command)}" autocomplete="off" autocapitalize="off"
|
|
494
|
+
autocorrect="off" spellcheck="false"
|
|
495
|
+
placeholder='例如:git status / ls -la / npm test'
|
|
496
|
+
style="width:100%;box-sizing:border-box">
|
|
497
|
+
<div class="row">
|
|
498
|
+
<button type="submit" style="flex:2">执行</button>
|
|
499
|
+
<button type="button" id="tabkey" style="flex:1;background:#2a2f3a;color:#c7cdd8">Tab</button>
|
|
500
|
+
<button type="submit" name="action" value="reset" formnovalidate style="flex:1;background:#3a2a2a;color:#f0b6bf">重置</button>
|
|
501
|
+
</div>
|
|
502
|
+
</form>
|
|
503
|
+
<div id="cands" style="display:flex;flex-wrap:wrap;gap:6px;margin-top:8px"></div>
|
|
504
|
+
<script id="shell-complete.js">
|
|
505
|
+
(function () {
|
|
506
|
+
var input = document.getElementById('cmd');
|
|
507
|
+
var box = document.getElementById('cands');
|
|
508
|
+
var cwdInput = document.querySelector('input[name=cwd]');
|
|
509
|
+
if (!input || !box) return;
|
|
510
|
+
var timer = null;
|
|
511
|
+
function apply(value) {
|
|
512
|
+
var text = input.value;
|
|
513
|
+
var m = text.match(/(\\S+)$/);
|
|
514
|
+
input.value = (m ? text.slice(0, m.index) : text) + value;
|
|
515
|
+
input.focus();
|
|
516
|
+
refresh();
|
|
517
|
+
}
|
|
518
|
+
function render(items) {
|
|
519
|
+
box.innerHTML = '';
|
|
520
|
+
items.slice(0, 12).forEach(function (item) {
|
|
521
|
+
var btn = document.createElement('button');
|
|
522
|
+
btn.type = 'button';
|
|
523
|
+
btn.textContent = item.label;
|
|
524
|
+
btn.style.cssText = 'padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px';
|
|
525
|
+
btn.addEventListener('click', function () { apply(item.value); });
|
|
526
|
+
box.appendChild(btn);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function refresh() {
|
|
530
|
+
var cwd = cwdInput ? cwdInput.value : '';
|
|
531
|
+
var line = input.value;
|
|
532
|
+
if (line.trim() === '') { box.innerHTML = ''; return; }
|
|
533
|
+
fetch('/shell/complete?cwd=' + encodeURIComponent(cwd) + '&line=' + encodeURIComponent(line))
|
|
534
|
+
.then(function (r) { return r.ok ? r.json() : []; })
|
|
535
|
+
.then(function (items) { render(Array.isArray(items) ? items : []); })
|
|
536
|
+
.catch(function () { /* 忽略补全失败 */ });
|
|
537
|
+
}
|
|
538
|
+
function completeNow() {
|
|
539
|
+
var cwd = cwdInput ? cwdInput.value : '';
|
|
540
|
+
var line = input.value;
|
|
541
|
+
if (line.trim() === '') return;
|
|
542
|
+
fetch('/shell/complete?cwd=' + encodeURIComponent(cwd) + '&line=' + encodeURIComponent(line))
|
|
543
|
+
.then(function (r) { return r.ok ? r.json() : []; })
|
|
544
|
+
.then(function (items) {
|
|
545
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
546
|
+
box.textContent = '无候选';
|
|
547
|
+
setTimeout(function () { box.textContent = ''; }, 1200);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
render(items);
|
|
551
|
+
if (items.length === 1) { apply(items[0].value); return; }
|
|
552
|
+
// 多个候选:把最后一段改成它们的公共前缀(像 bash 的 Tab 那样)
|
|
553
|
+
var prefix = items[0].value;
|
|
554
|
+
for (var i = 1; i < items.length; i += 1) {
|
|
555
|
+
while (prefix.length > 0 && items[i].value.indexOf(prefix) !== 0) prefix = prefix.slice(0, -1);
|
|
556
|
+
}
|
|
557
|
+
if (prefix.length > 0) apply(prefix);
|
|
558
|
+
})
|
|
559
|
+
.catch(function () { /* 忽略 */ });
|
|
560
|
+
}
|
|
561
|
+
var tabBtn = document.getElementById('tabkey');
|
|
562
|
+
if (tabBtn) tabBtn.addEventListener('click', completeNow);
|
|
563
|
+
|
|
564
|
+
input.addEventListener('input', function () {
|
|
565
|
+
clearTimeout(timer);
|
|
566
|
+
timer = setTimeout(refresh, 250);
|
|
567
|
+
});
|
|
568
|
+
input.addEventListener('focus', refresh);
|
|
569
|
+
})();
|
|
570
|
+
</script>
|
|
571
|
+
${history.length === 0 ? '' : `<div style="display:flex;flex-wrap:wrap;gap:6px;margin-top:10px">
|
|
572
|
+
${history.slice(0, 8).map((cmd) => `<form method="post" action="/shell" style="display:inline">
|
|
573
|
+
<input type="hidden" name="cwd" value="${escapeHtml(cwd)}">
|
|
574
|
+
<input type="hidden" name="command" value="${escapeHtml(cmd)}">
|
|
575
|
+
<button type="submit" style="padding:6px 10px;border-radius:999px;background:#1b2030;border:1px solid #2a3550;color:#9fc0ff;font-size:12px">${escapeHtml(cmd)}</button>
|
|
576
|
+
</form>`).join('')}
|
|
577
|
+
</div>`}
|
|
578
|
+
${result === null ? '' : `
|
|
579
|
+
<div class="msg${failed ? ' err' : ''}" style="margin-top:14px">
|
|
580
|
+
${failed ? escapeHtml(result.error ?? (result.timeout ? '超时(30 秒),已终止' : `退出码 ${result.code}`)) : `退出码 ${result.code}`}
|
|
581
|
+
</div>
|
|
582
|
+
<pre>${escapeHtml(result.output ?? '')}</pre>
|
|
583
|
+
`}
|
|
584
|
+
<div class="row">
|
|
585
|
+
<a class="btn ghost" href="/git?path=${encodeURIComponent(cwd)}"
|
|
586
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">Git 页</a>
|
|
587
|
+
<a class="btn ghost" href="/files?path=${encodeURIComponent(cwd)}"
|
|
588
|
+
style="flex:1;text-align:center;padding:10px;border-radius:8px;background:#2a2f3a;color:#c7cdd8;text-decoration:none;font-size:14px">文件</a>
|
|
589
|
+
</div>
|
|
590
|
+
<p class="crumbs">命令直接在你电脑上执行,输出截断到 64KB,30 秒超时。可以用 cd 切换工作目录。</p>`
|
|
591
|
+
return layout({ title: '终端', body })
|
|
592
|
+
}
|