dsh-remote-plugin 0.7.5 → 0.8.0-rc.2
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/apk/dsh-remote.apk +0 -0
- package/gateway.cjs +708 -12
- package/index.mjs +20 -5
- package/package.json +1 -1
- package/plugin-center.mjs +9 -2
- package/public/admin.html +4 -0
- package/public/admin.js +4 -0
- package/public/app.js +237 -37
- package/public/chat-files.js +74 -4
- package/public/desktop/desktop.css +16 -2
- package/public/desktop/desktop.html +6 -0
- package/public/desktop/desktop.js +106 -29
- package/public/index.html +9 -3
- package/public/md.js +14 -7
- package/public/motion.js +3 -3
- package/public/network.js +7 -1
- package/public/operations.js +109 -0
- package/public/relay-settings.css +2 -0
- package/public/relay-settings.js +119 -0
- package/public/styles.css +20 -2
- package/public/update.json +6 -6
- package/public/version.json +1 -1
- package/public/workflow.css +151 -0
- package/public/workflow.js +286 -0
package/index.mjs
CHANGED
|
@@ -209,7 +209,7 @@ async function proxyGateway(path, method, body) {
|
|
|
209
209
|
'x-dsh-remote-client': 'admin',
|
|
210
210
|
},
|
|
211
211
|
body: method === 'POST' ? body : undefined,
|
|
212
|
-
signal: AbortSignal.timeout(path.startsWith('/admin/api/dsh') ? 15000 : 5000),
|
|
212
|
+
signal: AbortSignal.timeout(path === '/admin/api/relay' ? 18000 : path.startsWith('/admin/api/dsh') ? 15000 : 5000),
|
|
213
213
|
})
|
|
214
214
|
const json = await res.json().catch(() => ({ ok: false, error: `gateway ${res.status}` }))
|
|
215
215
|
return { status: res.status, json }
|
|
@@ -414,6 +414,11 @@ async function startGateway() {
|
|
|
414
414
|
|
|
415
415
|
// 无 systemd 的机器回退: detached 子进程
|
|
416
416
|
if (!sysd) {
|
|
417
|
+
// Windows locks a process's current directory. Keep both supervisor and
|
|
418
|
+
// worker outside the replaceable node_modules package during self-update.
|
|
419
|
+
const gatewayCwd = `${homedir()}/.dsh-remote`
|
|
420
|
+
try { mkdirSync(gatewayCwd, { recursive: true }) }
|
|
421
|
+
catch { return { ok: false, running: false, error: '无法创建网关运行目录,请检查用户目录权限' } }
|
|
417
422
|
let logFd = null
|
|
418
423
|
try {
|
|
419
424
|
logFd = openSync(`${homedir()}/.dsh-remote/plugin-gateway.log`, 'a')
|
|
@@ -422,7 +427,7 @@ async function startGateway() {
|
|
|
422
427
|
delete gatewayEnv.NODE_CHANNEL_FD
|
|
423
428
|
delete gatewayEnv.NODE_CHANNEL_SERIALIZATION_MODE
|
|
424
429
|
const child = spawn(process.execPath, [script, '--supervise'], {
|
|
425
|
-
cwd:
|
|
430
|
+
cwd: gatewayCwd,
|
|
426
431
|
detached: true,
|
|
427
432
|
stdio: ['ignore', logFd ?? 'ignore', logFd ?? 'ignore'],
|
|
428
433
|
env: gatewayEnv,
|
|
@@ -598,8 +603,11 @@ async function executeRegisteredCommand(ctx, agent, line, signal) {
|
|
|
598
603
|
|
|
599
604
|
function beginCommandOperation(ctx, agent, sessionId, line, command) {
|
|
600
605
|
const existing = commandOperations.get(sessionId)
|
|
601
|
-
if (existing?.active)
|
|
602
|
-
|
|
606
|
+
if (existing?.active) {
|
|
607
|
+
if (existing.line !== line) throw new Error('当前会话已有命令正在执行,请等待完成后再提交。')
|
|
608
|
+
return { operation: existing, reused: true }
|
|
609
|
+
}
|
|
610
|
+
const operation = { active: true, phase: 'running', command, line, startedAt: Date.now(), endedAt: 0, message: '' }
|
|
603
611
|
commandOperations.set(sessionId, operation)
|
|
604
612
|
// 不把已登记命令绑定到 HTTP 超时:真实 command/done 才是完成边界。
|
|
605
613
|
// 处理器仍接收可用 AbortSignal,以符合命令执行器的契约。
|
|
@@ -793,6 +801,13 @@ async function serveStatic(req, res, ctx) {
|
|
|
793
801
|
[`${MOUNT}/admin/api/device-keys/rotate`, '/device-keys/rotate'],
|
|
794
802
|
[`${MOUNT}/admin/api/device-keys/revoke`, '/device-keys/revoke'],
|
|
795
803
|
])
|
|
804
|
+
if (pathname === `${MOUNT}/admin/api/relay`) {
|
|
805
|
+
if (!['GET', 'POST'].includes(req.method)) { res.writeHead(405, { allow: 'GET, POST' }); res.end(); return }
|
|
806
|
+
const body = req.method === 'POST' ? await readBody(req, 4096) : undefined
|
|
807
|
+
const proxied = await proxyGateway('/admin/api/relay', req.method, body)
|
|
808
|
+
sendJson(res, proxied?.status || 502, proxied?.json || { error: 'GATEWAY_UNAVAILABLE' })
|
|
809
|
+
return
|
|
810
|
+
}
|
|
796
811
|
if (gatewayAdminMutations.has(pathname)) {
|
|
797
812
|
if (req.method !== 'POST') {
|
|
798
813
|
res.writeHead(405, { allow: 'POST' })
|
|
@@ -975,7 +990,7 @@ async function serveStatic(req, res, ctx) {
|
|
|
975
990
|
}
|
|
976
991
|
// /export 的成功结果必须先回到客户端,由客户端再发起 ZIP 下载;其他已登记
|
|
977
992
|
// 命令统一异步受理,避免把未知耗时绑定到一条 HTTP 请求。
|
|
978
|
-
if (name && name !== 'export') {
|
|
993
|
+
if (name && (name !== 'export' || body.async === true)) {
|
|
979
994
|
const { operation, reused } = beginCommandOperation(ctx, agent, sessionId, line, name)
|
|
980
995
|
sendJson(res, 202, {
|
|
981
996
|
ok: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-rc.2",
|
|
4
4
|
"description": "DSH Remote 官方 bundle 插件:DSH 左侧原生边栏入口 + 右侧抽屉内嵌管理控制台;内置网关随 DSH 自动启停(systemd 独立单元),抽屉直显令牌与设备监控;网关提供 /fs/* 文件传输端点(列表/断点下载/上传),配合 Android App 远程操控会话/审批/提问/goal 与文件互传(多服务器测速切换、聊天记录离线缓存)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|
package/plugin-center.mjs
CHANGED
|
@@ -191,11 +191,15 @@ export function createPluginCenter(ctx, options = {}) {
|
|
|
191
191
|
const probe = options.probeProcesses || probeProcesses
|
|
192
192
|
const launch = options.launch || (args => {
|
|
193
193
|
const desktop = profile?.cliMode === 'desktop'
|
|
194
|
+
// A self-update can replace this module's package directory. Run a private
|
|
195
|
+
// snapshot from the profile ledger, with an explicit stable working dir.
|
|
196
|
+
const workerFile = join(profile.dir, '.remote-plugin-center', 'worker-' + args[2] + '.mjs')
|
|
197
|
+
writeFileSync(workerFile, readFileSync(SELF), { flag: 'wx', mode: 0o600 })
|
|
194
198
|
const errorLog = openSync(join(profile.dir, '.remote-plugin-center', 'worker-' + args[2] + '.log'), 'a', 0o600)
|
|
195
199
|
let child
|
|
196
200
|
try {
|
|
197
|
-
child = spawn(process.execPath, [...(desktop ? ['--expose-internals'] : []),
|
|
198
|
-
detached: true, windowsHide: true, stdio: ['ignore', 'ignore', errorLog],
|
|
201
|
+
child = spawn(process.execPath, [...(desktop ? ['--expose-internals'] : []), workerFile, '--worker', ...args], {
|
|
202
|
+
cwd: profile.dir, detached: true, windowsHide: true, stdio: ['ignore', 'ignore', errorLog],
|
|
199
203
|
env: { ...process.env, ...(desktop ? { ELECTRON_RUN_AS_NODE: '1' } : {}) },
|
|
200
204
|
})
|
|
201
205
|
} finally { closeSync(errorLog) }
|
|
@@ -410,6 +414,9 @@ export async function runWorker(dir, cli, id, execute = runCli, cliMode = 'node'
|
|
|
410
414
|
job.message = '配置已保存;重启 DSH 后生效。安装脚本未执行。'
|
|
411
415
|
} catch (error) {
|
|
412
416
|
job.phase = 'failed'; job.message = String(error.message || error)
|
|
417
|
+
if(job.name==='dsh-remote-plugin' && /(?:ERR_PNPM_)?(?:EPERM|EBUSY)/.test(job.log) && /rename/i.test(job.log)) {
|
|
418
|
+
job.message = 'Windows 拒绝替换 Remote 插件目录,可能仍有旧网关或 DSH 进程占用。更新未完成,配置和旧包备份已保留;请退出对应 DSH Desktop 及其 Remote 网关后,使用同一 Desktop 安装自带的 CLI 在当前 profile 重装目标版本,再启动 DSH。不要删除插件目录或强行覆盖;不能假定失败后已自动回滚。'
|
|
419
|
+
}
|
|
413
420
|
// A failed package manager may have changed files. Never claim rollback.
|
|
414
421
|
job.restartRequired = true
|
|
415
422
|
} finally {
|
package/public/admin.html
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
<title>DSH Remote · 管理</title>
|
|
8
8
|
<script>/* 首帧前应用皮肤 */ (function(){try{var t=localStorage.getItem('dshTheme');if(t!=='default'&&t!=='dark'&&t!=='light'&&t!=='neutral'&&t!=='mono'){t=window.matchMedia('(prefers-color-scheme: light)').matches?'light':'default'}document.documentElement.setAttribute('data-theme',t)}catch(e){}})()</script>
|
|
9
9
|
<link rel="stylesheet" href="../styles.css">
|
|
10
|
+
<link rel="stylesheet" href="../relay-settings.css">
|
|
10
11
|
<style>
|
|
11
12
|
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 14px) 14px 40px; }
|
|
12
13
|
.admin-title {
|
|
@@ -459,6 +460,7 @@
|
|
|
459
460
|
<button id="btn-save-port" class="mini-btn" data-i18n="savePort">保存</button>
|
|
460
461
|
</div>
|
|
461
462
|
|
|
463
|
+
<div id="relay-settings"></div>
|
|
462
464
|
<section id="host-ip-card" class="host-ip-card" aria-live="polite">
|
|
463
465
|
<div class="host-ip-head">
|
|
464
466
|
<div>
|
|
@@ -770,5 +772,7 @@
|
|
|
770
772
|
<script src="../vendor/gsap/gsap.min.js"></script>
|
|
771
773
|
<script src="../motion.js"></script>
|
|
772
774
|
<script src="../admin.js"></script>
|
|
775
|
+
<script src="../relay-settings.js"></script>
|
|
776
|
+
<script>window.mountAdminRelaySettings?.()</script>
|
|
773
777
|
</body>
|
|
774
778
|
</html>
|
package/public/admin.js
CHANGED
|
@@ -11,6 +11,10 @@ const pluginMode = location.pathname === '/remote'
|
|
|
11
11
|
|| location.pathname.startsWith('/remote/')
|
|
12
12
|
|| new URLSearchParams(location.search).get('embedded') === '1'
|
|
13
13
|
const API = pluginMode ? '/remote/admin/api' : '/admin/api'
|
|
14
|
+
window.mountAdminRelaySettings = () => window.DshRelaySettings?.mount($('relay-settings'), {
|
|
15
|
+
connection: () => { const saved=token;return {url:route=>API+route,headers:adminHeaders({},saved),valid:()=>token===saved} },
|
|
16
|
+
path:'/relay', credentials:'same-origin'
|
|
17
|
+
})
|
|
14
18
|
// 沙箱 iframe/隐私模式里 localStorage 可能抛 SecurityError, 不能让它杀死整个页面
|
|
15
19
|
const store = {
|
|
16
20
|
get(k) { try { return localStorage.getItem(k) } catch { return null } },
|