@tianacloud/dsh-remote 0.0.0-stage → 0.2.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 +204 -0
- package/README.md +44 -2
- package/cli.js +347 -0
- package/client.js +1501 -0
- package/cordis.patch.yml +3 -0
- package/host-main.js +628 -0
- package/icon.svg +7 -0
- package/locale/en-US.json +9 -0
- package/locale/zh-CN.json +9 -0
- package/package.json +89 -4
- package/relay-go/go.mod +3 -0
- package/relay-go/main.go +1711 -0
- package/scripts/build-web-dist.mjs +46 -0
- package/src/clipboard.js +94 -0
- package/src/connect.js +599 -0
- package/src/dsh-packages.js +46 -0
- package/src/frontend-assets.js +405 -0
- package/src/host-bridge.js +1412 -0
- package/src/local-transport.js +496 -0
- package/src/protocol.js +124 -0
- package/src/remote-api.js +433 -0
- package/src/state.js +379 -0
- package/src/tiana-cli.js +929 -0
- package/web-src/dsh-remote-entry.mjs +2692 -0
- package/web-src/dsh-remote-sw.js +593 -0
- package/web-src/e2ee.js +460 -0
- package/web-src/frontend-loader.js +450 -0
- package/web-src/multipath.js +375 -0
- package/web-src/peer-path.js +265 -0
- package/web-src/shell-ui.js +280 -0
- package/web-src/ws-fragments.js +46 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/** Four-state Shell UI for `@tianacloud/dsh-remote` (.tweb hosted app). */
|
|
2
|
+
|
|
3
|
+
const SHELL_STYLES = ':root{color-scheme:light dark;--dsh-bg-l:#f1f5f9;--dsh-bg-d:#0b1120;--dsh-c-l:#fff;--dsh-c-d:rgba(19,27,46,.94);--dsh-t-l:#0f172a;--dsh-t-d:#f1f5f9;--dsh-m-l:#475569;--dsh-m-d:#94a3b8;--dsh-b-l:rgba(15,23,42,.12);--dsh-b-d:rgba(148,163,184,.22);--dsh-k-l:#f8fafc;--dsh-k-d:#0f172a;--dsh-bg:var(--dsh-bg-l);--dsh-card:var(--dsh-c-l);--dsh-text:var(--dsh-t-l);--dsh-muted:var(--dsh-m-l);--dsh-border:var(--dsh-b-l);--dsh-code:var(--dsh-k-l)}' +
|
|
4
|
+
'@media (prefers-color-scheme:dark){:root{--dsh-bg:var(--dsh-bg-d);--dsh-card:var(--dsh-c-d);--dsh-text:var(--dsh-t-d);--dsh-muted:var(--dsh-m-d);--dsh-border:var(--dsh-b-d);--dsh-code:var(--dsh-k-d)}}' +
|
|
5
|
+
'@supports (color:light-dark(white,black)){:root{--dsh-bg:light-dark(var(--dsh-bg-l),var(--dsh-bg-d));--dsh-card:light-dark(var(--dsh-c-l),var(--dsh-c-d));--dsh-text:light-dark(var(--dsh-t-l),var(--dsh-t-d));--dsh-muted:light-dark(var(--dsh-m-l),var(--dsh-m-d));--dsh-border:light-dark(var(--dsh-b-l),var(--dsh-b-d));--dsh-code:light-dark(var(--dsh-k-l),var(--dsh-k-d))}}' +
|
|
6
|
+
'#dsh-remote-shell{position:fixed;inset:0;z-index:2147483640;overflow:auto;display:flex;align-items:center;justify-content:center;padding:24px;background:var(--dsh-bg);color:var(--dsh-text);font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}' +
|
|
7
|
+
'.dsh-shell-card{box-sizing:border-box;width:min(640px,100%);background:var(--dsh-card);border:1px solid var(--dsh-border);border-radius:18px;padding:28px;box-shadow:0 24px 60px rgba(0,0,0,.22);display:grid;grid-template-columns:minmax(0,1fr);gap:16px}' +
|
|
8
|
+
'.dsh-shell-badge{display:inline-flex;align-items:center;gap:8px;font-size:12px;font-weight:600;color:#3b82f6;letter-spacing:.02em}' +
|
|
9
|
+
'.dsh-shell-title{margin:0;font-size:22px;font-weight:650;line-height:1.3}.dsh-shell-sub{margin:0;font-size:14px;line-height:1.6;color:var(--dsh-muted)}' +
|
|
10
|
+
'.dsh-shell-tabs{display:flex;gap:8px;flex-wrap:wrap}.dsh-shell-tab{padding:6px 12px;border-radius:8px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--dsh-border);background:transparent;color:var(--dsh-muted)}.dsh-shell-tab[aria-selected="true"]{background:#2563eb;border-color:#2563eb;color:#fff}' +
|
|
11
|
+
'.dsh-shell-codebox{display:flex;align-items:center;gap:10px;padding:12px 14px;border-radius:10px;min-width:0;max-width:100%;box-sizing:border-box;background:var(--dsh-code);border:1px solid var(--dsh-border)}' +
|
|
12
|
+
'.dsh-shell-code{flex:1;min-width:0;overflow-x:auto;white-space:nowrap;font:13px ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}' +
|
|
13
|
+
'.dsh-shell-btn{padding:9px 14px;border-radius:9px;font-size:13px;font-weight:500;cursor:pointer;border:1px solid var(--dsh-border);background:transparent;color:var(--dsh-text);white-space:nowrap}.dsh-shell-btn-primary{background:#2563eb;border-color:#2563eb;color:#fff}.dsh-shell-btn:hover{filter:brightness(1.06)}' +
|
|
14
|
+
'.dsh-shell-input-row{display:flex;gap:8px;align-items:center}.dsh-shell-input{flex:1;min-width:0;padding:11px 13px;border-radius:9px;border:1px solid var(--dsh-border);background:var(--dsh-code);color:var(--dsh-text);font:13px ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}' +
|
|
15
|
+
'.dsh-shell-err{padding:10px 12px;border-radius:9px;font-size:13px;line-height:1.45;background:rgba(220,38,38,.14);border:1px solid rgba(248,113,113,.45);color:#ef4444}' +
|
|
16
|
+
'.dsh-shell-valid-hint{font-size:12px;line-height:1.4;min-height:18px}.dsh-shell-valid-hint.is-ok{color:#22c55e}.dsh-shell-valid-hint.is-err{color:#ef4444}' +
|
|
17
|
+
'.dsh-shell-wait{display:flex;align-items:center;gap:10px;padding:11px 14px;border-radius:10px;background:rgba(59,130,246,.1);border:1px solid rgba(59,130,246,.25);font-size:13px}' +
|
|
18
|
+
'.dsh-shell-pulse{width:9px;height:9px;border-radius:50%;background:#3b82f6;flex:none;animation:dsh-pulse 1.5s infinite}@keyframes dsh-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.45;transform:scale(.8)}}' +
|
|
19
|
+
'.dsh-shell-check{display:flex;align-items:center;gap:8px;font-size:13px;color:var(--dsh-muted);cursor:pointer}.dsh-shell-details{font-size:13px;color:var(--dsh-muted);border-top:1px solid var(--dsh-border);padding-top:12px}.dsh-shell-details summary{cursor:pointer;font-weight:500;color:var(--dsh-text)}' +
|
|
20
|
+
'#dsh-remote-reconnect-banner,#dsh-remote-no-sw-banner{position:fixed;left:50%;transform:translateX(-50%);z-index:2147483645;display:flex;align-items:center;gap:10px;padding:8px 14px;border-radius:999px;font:13px system-ui,-apple-system,sans-serif;box-shadow:0 8px 28px rgba(0,0,0,.28);backdrop-filter:blur(10px)}' +
|
|
21
|
+
'#dsh-remote-reconnect-banner{top:12px;background:rgba(15,23,42,.9);color:#f8fafc;border:1px solid rgba(148,163,184,.35)}#dsh-remote-no-sw-banner{top:12px;background:rgba(245,158,11,.94);color:#1c1917;border:1px solid rgba(217,119,6,.55);max-width:calc(100vw - 24px)}' +
|
|
22
|
+
'@media (max-width:560px){#dsh-remote-shell{padding:14px}.dsh-shell-card{padding:20px}}';
|
|
23
|
+
|
|
24
|
+
const PAIRING_KEY_PATTERN = /^(?:dshk1_)?[A-Za-z0-9_-]{43}$/u;
|
|
25
|
+
|
|
26
|
+
export function validatePairingKeyInput(raw) {
|
|
27
|
+
const trimmed = String(raw ?? '').trim();
|
|
28
|
+
if (!trimmed) return { valid: false, empty: true, trimmed: '', message: '' };
|
|
29
|
+
if (PAIRING_KEY_PATTERN.test(trimmed)) return { valid: true, empty: false, trimmed, message: '密钥格式有效(43 位 base64url)' };
|
|
30
|
+
const bare = trimmed.startsWith('dshk1_') ? trimmed.slice(6) : trimmed;
|
|
31
|
+
if (!/^[A-Za-z0-9_-]*$/u.test(bare)) {
|
|
32
|
+
return { valid: false, empty: false, trimmed, message: '密钥包含非法字符,仅支持 43 位 base64url 或 dshk1_ 前缀格式。' };
|
|
33
|
+
}
|
|
34
|
+
return { valid: false, empty: false, trimmed, message: `密钥长度应为 43 位(当前 ${bare.length} 位,支持可选 dshk1_ 前缀)。` };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function el(tag, props, ...children) {
|
|
38
|
+
const node = document.createElement(tag);
|
|
39
|
+
if (props) {
|
|
40
|
+
for (const [k, v] of Object.entries(props)) {
|
|
41
|
+
if (k === 'style') node.style.cssText = v;
|
|
42
|
+
else if (k === 'attrs') { for (const [ak, av] of Object.entries(v)) node.setAttribute(ak, av); }
|
|
43
|
+
else node[k] = v;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (children.length) node.append(...children);
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ensureShellStyles() {
|
|
51
|
+
if (typeof document === 'undefined') return;
|
|
52
|
+
if (!document.querySelector('meta[name="color-scheme"]')) {
|
|
53
|
+
document.head?.appendChild(el('meta', { name: 'color-scheme', content: 'light dark' }));
|
|
54
|
+
}
|
|
55
|
+
if (!document.getElementById('dsh-remote-shell-styles')) {
|
|
56
|
+
document.head?.appendChild(el('style', { id: 'dsh-remote-shell-styles', textContent: SHELL_STYLES }));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function detectClientOS() {
|
|
61
|
+
const ua = typeof navigator !== 'undefined'
|
|
62
|
+
? String(navigator.userAgentData?.platform || navigator.platform || navigator.userAgent || '').toLowerCase()
|
|
63
|
+
: '';
|
|
64
|
+
return ua.includes('win') ? 'windows' : ua.includes('mac') ? 'macos' : 'linux';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function buildConnectCommand({ webId, tenantId, rebind = false } = {}) {
|
|
68
|
+
const parts = ['npx --yes @tianacloud/dsh-remote@latest connect', `--app ${webId || '<appId>'}`];
|
|
69
|
+
if (tenantId) parts.push(`--space ${tenantId}`);
|
|
70
|
+
if (rebind) parts.push('--rebind');
|
|
71
|
+
return parts.join(' ');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createShellUI(rootEl) {
|
|
75
|
+
ensureShellStyles();
|
|
76
|
+
const card = el('div', { className: 'dsh-shell-card' });
|
|
77
|
+
const overlay = el('div', { id: 'dsh-remote-shell' }, card);
|
|
78
|
+
rootEl.replaceChildren(overlay);
|
|
79
|
+
|
|
80
|
+
let reconnectBanner = null;
|
|
81
|
+
let noSwBanner = null;
|
|
82
|
+
let waitStatusEl = null;
|
|
83
|
+
|
|
84
|
+
function renderCard(stateName, elements) {
|
|
85
|
+
overlay.dataset.state = stateName;
|
|
86
|
+
card.replaceChildren(...elements);
|
|
87
|
+
if (!overlay.isConnected) {
|
|
88
|
+
if (rootEl.isConnected) rootEl.replaceChildren(overlay);
|
|
89
|
+
else document.body?.append(overlay);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const makeHeader = (badgeText, titleText, subText) => [
|
|
94
|
+
el('div', { className: 'dsh-shell-badge', textContent: badgeText }),
|
|
95
|
+
el('h2', { className: 'dsh-shell-title', textContent: titleText }),
|
|
96
|
+
el('p', { className: 'dsh-shell-sub', textContent: subText }),
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
showLoading(title, subtitle) {
|
|
101
|
+
renderCard('loading', makeHeader('Tiana · DSH Remote (E2EE)', title, subtitle));
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
showError(title, subtitle, onRetry) {
|
|
105
|
+
const btn = el('button', { type: 'button', className: 'dsh-shell-btn dsh-shell-btn-primary', textContent: '重新加载' });
|
|
106
|
+
btn.addEventListener('click', () => (onRetry ? onRetry() : location.reload()), { once: true });
|
|
107
|
+
renderCard('error', [...makeHeader('Tiana · DSH Remote', title, subtitle), btn]);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
showOnboarding({ webId, tenantId } = {}) {
|
|
111
|
+
const baseCmd = buildConnectCommand({ webId, tenantId });
|
|
112
|
+
const osCommands = {
|
|
113
|
+
macos: { label: 'macOS / Linux', cmd: baseCmd, hint: '需要 Node.js >= 24.9.0(推荐 fnm / nvm)。未装 DSH 将自动安装并启用双插件。' },
|
|
114
|
+
windows: { label: 'Windows PowerShell', cmd: baseCmd, hint: '需要 Node.js >= 24.9.0(推荐 winget install OpenJS.NodeJS.LTS)。' },
|
|
115
|
+
};
|
|
116
|
+
let activeOs = detectClientOS() === 'windows' ? 'windows' : 'macos';
|
|
117
|
+
const tabs = el('div', { className: 'dsh-shell-tabs', attrs: { role: 'tablist' } });
|
|
118
|
+
const codeEl = el('code', { className: 'dsh-shell-code', id: 'dsh-remote-onboarding-cmd' });
|
|
119
|
+
const hintEl = el('p', { className: 'dsh-shell-sub', style: 'font-size:12px;' });
|
|
120
|
+
const tabButtons = {};
|
|
121
|
+
const selectOs = (key) => {
|
|
122
|
+
activeOs = key;
|
|
123
|
+
for (const [k, btn] of Object.entries(tabButtons)) btn.setAttribute('aria-selected', k === key ? 'true' : 'false');
|
|
124
|
+
codeEl.textContent = osCommands[key].cmd;
|
|
125
|
+
hintEl.textContent = osCommands[key].hint;
|
|
126
|
+
};
|
|
127
|
+
for (const [key, cfg] of Object.entries(osCommands)) {
|
|
128
|
+
const btn = el('button', { type: 'button', className: 'dsh-shell-tab', textContent: cfg.label, attrs: { role: 'tab' } });
|
|
129
|
+
btn.addEventListener('click', () => selectOs(key));
|
|
130
|
+
tabButtons[key] = btn;
|
|
131
|
+
tabs.append(btn);
|
|
132
|
+
}
|
|
133
|
+
const copyBtn = el('button', { type: 'button', id: 'dsh-remote-copy-cmd', className: 'dsh-shell-btn dsh-shell-btn-primary', textContent: '复制命令' });
|
|
134
|
+
copyBtn.addEventListener('click', async () => {
|
|
135
|
+
try {
|
|
136
|
+
await navigator.clipboard.writeText(osCommands[activeOs].cmd);
|
|
137
|
+
copyBtn.textContent = '已复制';
|
|
138
|
+
setTimeout(() => { copyBtn.textContent = '复制命令'; }, 1800);
|
|
139
|
+
} catch { copyBtn.textContent = '请手动复制'; }
|
|
140
|
+
});
|
|
141
|
+
const codeBox = el('div', { className: 'dsh-shell-codebox' }, codeEl, copyBtn);
|
|
142
|
+
waitStatusEl = el('span', { textContent: '正在等待你的电脑完成配置并上线…(上线后自动进入解锁页)' });
|
|
143
|
+
const waitBar = el('div', { className: 'dsh-shell-wait', id: 'dsh-remote-onboarding-wait' }, el('span', { className: 'dsh-shell-pulse' }), waitStatusEl);
|
|
144
|
+
const details = el('details', { className: 'dsh-shell-details' },
|
|
145
|
+
el('summary', { textContent: '高级说明:本机已有 DSH 实例?' }),
|
|
146
|
+
el('p', { style: 'margin:8px 0 0;', textContent: '上述命令会自动检测并复用已有 DSH、保留所有项目与对话记录,仅增量启用 @tianacloud/dsh-tiana 与 @tianacloud/dsh-remote 并免重编译写入云端策略。' }),
|
|
147
|
+
);
|
|
148
|
+
selectOs(activeOs);
|
|
149
|
+
renderCard('onboarding', [
|
|
150
|
+
...makeHeader('Tiana · DSH Remote 首次配置向导', '连接你的个人电脑 DSH 工作台', '在个人电脑终端运行下方命令,即可自动完成环境配置、云端免重编译绑定并生成端到端加密配对密钥。'),
|
|
151
|
+
tabs, codeBox, hintEl, waitBar, details,
|
|
152
|
+
]);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
markHostOnlineDetected(hostName) {
|
|
156
|
+
if (waitStatusEl) waitStatusEl.textContent = `已检测到主机 "${hostName || 'DSH'}" 上线!正在进入解锁界面…`;
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
showHostOffline({ webId, tenantId, hostName, hostId } = {}) {
|
|
160
|
+
const display = hostName || hostId || '本地主机';
|
|
161
|
+
const steps = el('div', { className: 'dsh-shell-sub' },
|
|
162
|
+
el('div', { textContent: '1. 在该电脑终端运行 `dsh --profile web` 启动本地服务;' }),
|
|
163
|
+
el('div', { textContent: '2. 或在已运行的本地 DSH 左侧边栏打开「Tiana Remote」开启远程访问开关。' }),
|
|
164
|
+
);
|
|
165
|
+
waitStatusEl = el('span', { textContent: `正在监听主机 "${display}" 上线信号,恢复后自动连接…` });
|
|
166
|
+
const waitBar = el('div', { className: 'dsh-shell-wait' }, el('span', { className: 'dsh-shell-pulse' }), waitStatusEl);
|
|
167
|
+
const details = el('details', { className: 'dsh-shell-details' },
|
|
168
|
+
el('summary', { textContent: '需要将此应用换绑到另一台电脑?' }),
|
|
169
|
+
el('div', { className: 'dsh-shell-codebox', style: 'margin-top:8px;' }, el('code', { className: 'dsh-shell-code', textContent: buildConnectCommand({ webId, tenantId, rebind: true }) })),
|
|
170
|
+
);
|
|
171
|
+
renderCard('offline', [
|
|
172
|
+
...makeHeader('Tiana · DSH Remote 主机离线', `主机 "${display}" 当前不在线`, '应用已完成绑定,但本地电脑的 DSH 远程桥尚未连接。'),
|
|
173
|
+
steps, waitBar, details,
|
|
174
|
+
]);
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
promptUnlock({ hostName, hostId, errorMessage = '', defaultRemember = true } = {}) {
|
|
178
|
+
const display = hostName || hostId || 'DSH 主机';
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
const errBox = el('div', { id: 'dsh-remote-e2ee-error', className: 'dsh-shell-err', textContent: errorMessage, style: errorMessage ? '' : 'display:none;' });
|
|
181
|
+
const input = el('input', {
|
|
182
|
+
id: 'dsh-remote-e2ee-key-input', className: 'dsh-shell-input', type: 'password',
|
|
183
|
+
autocomplete: 'off', spellcheck: false, maxLength: 80, placeholder: '粘贴配对密钥 (dshk1_... 或 43 位密钥)',
|
|
184
|
+
});
|
|
185
|
+
const validationEl = el('div', { id: 'dsh-remote-key-validation', className: 'dsh-shell-valid-hint', attrs: { 'aria-live': 'polite' } });
|
|
186
|
+
const updateValidation = () => {
|
|
187
|
+
const trimmed = input.value.trim();
|
|
188
|
+
if (trimmed !== input.value) input.value = trimmed;
|
|
189
|
+
const check = validatePairingKeyInput(trimmed);
|
|
190
|
+
validationEl.textContent = check.empty ? '' : check.message;
|
|
191
|
+
validationEl.className = check.empty ? 'dsh-shell-valid-hint' : `dsh-shell-valid-hint ${check.valid ? 'is-ok' : 'is-err'}`;
|
|
192
|
+
validationEl.dataset.valid = check.empty ? '' : String(check.valid);
|
|
193
|
+
return check;
|
|
194
|
+
};
|
|
195
|
+
input.addEventListener('paste', (ev) => {
|
|
196
|
+
const pasted = ev.clipboardData?.getData('text');
|
|
197
|
+
if (pasted !== undefined) { ev.preventDefault(); input.value = pasted.trim(); updateValidation(); }
|
|
198
|
+
});
|
|
199
|
+
input.addEventListener('input', updateValidation);
|
|
200
|
+
|
|
201
|
+
const toggleBtn = el('button', { type: 'button', className: 'dsh-shell-btn', textContent: '显示' });
|
|
202
|
+
toggleBtn.addEventListener('click', () => {
|
|
203
|
+
const showing = input.type === 'text';
|
|
204
|
+
input.type = showing ? 'password' : 'text';
|
|
205
|
+
toggleBtn.textContent = showing ? '显示' : '隐藏';
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const rememberBox = el('input', { type: 'checkbox', id: 'dsh-remote-remember-key', checked: Boolean(defaultRemember) });
|
|
209
|
+
const rememberLabel = el('label', { className: 'dsh-shell-check' }, rememberBox, '在此受信任浏览器记住密钥(取消勾选后密钥仅驻留当前页面内存,刷新或关闭标签页立即销毁)');
|
|
210
|
+
const hint = el('div', { className: 'dsh-shell-sub', style: 'font-size:12px;', textContent: '密钥仅在浏览器与你的电脑之间进行端到端加密校验,Tiana 云端无法解密任何内容。可从刚运行的 connect 剪贴板粘贴,或在本地 DSH 侧栏「Tiana Remote」复制。' });
|
|
211
|
+
const submitBtn = el('button', { id: 'dsh-remote-e2ee-submit', type: 'submit', className: 'dsh-shell-btn dsh-shell-btn-primary', textContent: '解锁并进入工作台' });
|
|
212
|
+
|
|
213
|
+
const form = el('form', { style: 'display:grid;gap:12px;' }, errBox, el('div', { className: 'dsh-shell-input-row' }, input, toggleBtn), validationEl, rememberLabel, hint, submitBtn);
|
|
214
|
+
form.addEventListener('submit', (e) => {
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
const check = updateValidation();
|
|
217
|
+
if (!check.valid) {
|
|
218
|
+
errBox.textContent = check.message || '请输入有效的 43 位配对密钥(支持可选 dshk1_ 前缀)。';
|
|
219
|
+
errBox.style.display = 'block';
|
|
220
|
+
input.focus();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
input.value = '';
|
|
224
|
+
resolve({ secret: check.trimmed, remember: rememberBox.checked });
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
renderCard('unlock', [
|
|
228
|
+
...makeHeader('Tiana · DSH Remote (E2EE)', '输入端到端配对密钥解锁', `目标主机 "${display}" 已在线。请粘贴主机端生成的配对密钥建立加密隧道。`),
|
|
229
|
+
form,
|
|
230
|
+
]);
|
|
231
|
+
queueMicrotask(() => input.focus());
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
mountReconnectBanner({ hostName, onLock } = {}) {
|
|
236
|
+
reconnectBanner?.remove();
|
|
237
|
+
const text = el('span', { textContent: `正在重连至 ${hostName || '主机'}…` });
|
|
238
|
+
const lockBtn = el('button', { type: 'button', className: 'dsh-shell-btn', style: 'padding:4px 10px;font-size:12px;color:#fff;border-color:rgba(255,255,255,0.3);', textContent: '立即锁定' });
|
|
239
|
+
lockBtn.addEventListener('click', () => void onLock?.());
|
|
240
|
+
reconnectBanner = el('div', { id: 'dsh-remote-reconnect-banner', role: 'status', style: 'display:none;' }, text, lockBtn);
|
|
241
|
+
document.body.append(reconnectBanner);
|
|
242
|
+
return {
|
|
243
|
+
showReconnecting() { text.textContent = `正在重连至 ${hostName || '主机'}…`; reconnectBanner.style.display = 'flex'; },
|
|
244
|
+
showRecovered() {
|
|
245
|
+
text.textContent = '已恢复连接';
|
|
246
|
+
reconnectBanner.style.display = 'flex';
|
|
247
|
+
setTimeout(() => { if (reconnectBanner) reconnectBanner.style.display = 'none'; }, 1200);
|
|
248
|
+
},
|
|
249
|
+
hide() { if (reconnectBanner) reconnectBanner.style.display = 'none'; },
|
|
250
|
+
remove() { reconnectBanner?.remove(); reconnectBanner = null; },
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
mountNoSwBanner() {
|
|
255
|
+
if (noSwBanner) return noSwBanner;
|
|
256
|
+
const closeBtn = el('button', {
|
|
257
|
+
type: 'button', id: 'dsh-remote-no-sw-dismiss', textContent: '关闭',
|
|
258
|
+
attrs: { 'aria-label': '关闭提示' },
|
|
259
|
+
style: 'background:rgba(0,0,0,0.12);border:none;border-radius:6px;padding:4px 8px;cursor:pointer;font-size:12px;color:#1c1917;white-space:nowrap;',
|
|
260
|
+
});
|
|
261
|
+
closeBtn.addEventListener('click', () => { noSwBanner?.remove(); noSwBanner = null; });
|
|
262
|
+
noSwBanner = el('div', { id: 'dsh-remote-no-sw-banner', role: 'status' },
|
|
263
|
+
el('span', { textContent: '当前容器未启用 Service Worker,对话、文件上传与实时流可正常使用;如需完整媒体预览与流式下载,请在系统标准浏览器中打开。' }),
|
|
264
|
+
closeBtn,
|
|
265
|
+
);
|
|
266
|
+
document.body.append(noSwBanner);
|
|
267
|
+
return noSwBanner;
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
destroy() { overlay.remove(); },
|
|
271
|
+
|
|
272
|
+
destroyAll() {
|
|
273
|
+
overlay.remove();
|
|
274
|
+
reconnectBanner?.remove();
|
|
275
|
+
reconnectBanner = null;
|
|
276
|
+
noSwBanner?.remove();
|
|
277
|
+
noSwBanner = null;
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { concatBytes } from './e2ee.js';
|
|
2
|
+
import { CHUNK_SIZE } from './multipath.js';
|
|
3
|
+
|
|
4
|
+
const FIRST = 1;
|
|
5
|
+
const FIN = 2;
|
|
6
|
+
const MAX_MESSAGE = 16 << 20;
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
|
|
9
|
+
export async function sendFragments(value, send) {
|
|
10
|
+
const bytes = typeof value === 'string' ? encoder.encode(value) :
|
|
11
|
+
value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
12
|
+
if (bytes.length > MAX_MESSAGE) throw new Error('Virtual WebSocket message exceeds 16 MiB');
|
|
13
|
+
for (let offset = 0; offset === 0 || offset < bytes.length; offset += CHUNK_SIZE - 1) {
|
|
14
|
+
const end = Math.min(offset + CHUNK_SIZE - 1, bytes.length);
|
|
15
|
+
const flags = (offset === 0 ? FIRST : 0) | (end === bytes.length ? FIN : 0);
|
|
16
|
+
await send(concatBytes(Uint8Array.of(flags), bytes.subarray(offset, end)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class FragmentReader {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.parts = [];
|
|
23
|
+
this.size = 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
push(kind, packet) {
|
|
27
|
+
const flags = packet[0];
|
|
28
|
+
if (!packet.length || flags > (FIRST | FIN) || packet.length > CHUNK_SIZE ||
|
|
29
|
+
Boolean(flags & FIRST) !== (this.parts.length === 0) ||
|
|
30
|
+
(this.parts.length > 0 && this.kind !== kind) ||
|
|
31
|
+
(!((flags & FIN) === FIN) && packet.length !== CHUNK_SIZE)) {
|
|
32
|
+
throw new Error('Invalid WebSocket message fragments');
|
|
33
|
+
}
|
|
34
|
+
this.kind = kind;
|
|
35
|
+
this.parts.push(packet.subarray(1));
|
|
36
|
+
this.size += packet.length - 1;
|
|
37
|
+
if (this.size > MAX_MESSAGE) throw new Error('Virtual WebSocket message exceeds 16 MiB');
|
|
38
|
+
if (flags & FIN) {
|
|
39
|
+
const result = concatBytes(...this.parts);
|
|
40
|
+
this.parts = [];
|
|
41
|
+
this.size = 0;
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|