dsh-go-plugin-sync 0.3.2 → 0.3.4
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/CHANGELOG.md +26 -0
- package/README.md +9 -15
- package/lib/client.js +191 -30
- package/lib/index.js +179 -98
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.4 — 2026-12-04
|
|
4
|
+
|
|
5
|
+
### 电脑端
|
|
6
|
+
- 新增 **设置 → 插件同步** 页面:同步码导入、插件勾选安装、任务状态、Git 中转和 SSH 配置都在设置页完成
|
|
7
|
+
- 移除插件详情页的「打开插件同步网页」按钮和网页版页面,不再依赖浏览器新标签页、DSH 地址或端口
|
|
8
|
+
- 配置保存到 `plugin-sync-config.json`,设置页会显示当前路径
|
|
9
|
+
|
|
10
|
+
### 说明
|
|
11
|
+
- 手机端原生面板不变;电脑端改用设置页,Windows 同样适用
|
|
12
|
+
|
|
13
|
+
## 0.3.3 — 2026-12-04
|
|
14
|
+
|
|
15
|
+
### 修复
|
|
16
|
+
- **Windows**:「安装选中」恢复可用;安装任务改由 Node 直接执行,不再依赖 `/bin/sh`
|
|
17
|
+
- **Windows**:Git 中转 / SSH 不再假装开始,直接提示当前平台不支持
|
|
18
|
+
- **清单校验**:`relDir` 只接受插件根目录下的单级目录名,拒绝绝对路径和 `.`/`..`
|
|
19
|
+
- **网页版**:刷新或任务完成后不再重置用户勾选;应用后清空已选项
|
|
20
|
+
- **网页版**:有任务在运行时拒绝再次提交,避免并发任务互相覆盖
|
|
21
|
+
- **空同步码** / 全部条目无效的同步码按错误处理,不再显示“已导入 0 个”
|
|
22
|
+
- 同步码解压限制 2 MB,异常压缩包不再拖垮引擎
|
|
23
|
+
- 任务日志里的插件名做安全转义,避免特殊名称破坏任务脚本
|
|
24
|
+
|
|
25
|
+
### 说明
|
|
26
|
+
- Git 中转和 SSH 推/拉仍只在 Linux / macOS 上工作
|
|
27
|
+
- 只增不删的行为不变:冲突、清单外、缺文件仍然只提示
|
|
28
|
+
|
|
3
29
|
## 0.3.2 — 2026-12-04
|
|
4
30
|
|
|
5
31
|
- 修复 README 里的网页地址:实际路径是 `/dsh-go-plugin-sync/`;旧的 `/local-plugin-sync/` 自动跳转
|
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- **状态条**:输入框上方显示「待同步 N 项 / 同步失败 N 项 / 插件已同步」
|
|
14
14
|
- **高级通道**:Git 私有仓中转、SSH 直连(推送 / 拉取 / 拉远端清单)
|
|
15
15
|
- **使用引导**:面板里的「使用引导」有完整步骤
|
|
16
|
+
- **电脑端设置页**:设置 → 插件同步,导入同步码、勾选安装、配置 Git 中转和 SSH
|
|
16
17
|
|
|
17
18
|
## 安装
|
|
18
19
|
|
|
@@ -43,24 +44,16 @@ dsh plugin --profile web add ./dshgochajiantongbucha
|
|
|
43
44
|
|
|
44
45
|
两端第一次都要手动装一次本插件,之后就能复制粘贴。
|
|
45
46
|
|
|
46
|
-
##
|
|
47
|
+
## 电脑端(设置页)
|
|
47
48
|
|
|
48
|
-
电脑上的 DSH
|
|
49
|
+
电脑上的 DSH 不需要 dsh-go 桥接,也不需要打开网页。装好插件并重启 DSH 后,打开 **设置 → 插件同步**,直接在里面完成:
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
地址就是当前 DSH Web 的地址和端口(例如 `http://127.0.0.1:3080/dsh-go-plugin-sync/`)。旧地址 `/local-plugin-sync/` 会自动跳转过来。
|
|
55
|
-
|
|
56
|
-
页面提供和手机端一样的发送/接收:
|
|
57
|
-
|
|
58
|
-
1. 勾选要同步的插件,点**复制同步码**
|
|
59
|
-
2. 在另一台打开同一页面,把同步码粘进输入框,点**导入同步码**
|
|
60
|
-
3. 默认选中同步码里的插件,可以取消;点**安装选中**
|
|
61
|
-
4. 页面下方显示任务状态和逐项结果
|
|
51
|
+
1. 粘贴同步码,点**导入同步码**
|
|
52
|
+
2. 在插件列表里勾选要安装的项(默认选中同步码里的插件)
|
|
53
|
+
3. 点**安装选中**,下方显示任务状态
|
|
54
|
+
4. 在同一页填写 **Git 中转**(仓库地址 / 分支 / 目录)和 **SSH**(主机 / 端口 / 用户 / 私钥 / profile),点**保存配置**
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
Windows 上支持同步码导入和安装;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
|
|
64
57
|
|
|
65
58
|
注意:电脑上装完插件后同样要重启一次 DSH。
|
|
66
59
|
|
|
@@ -107,6 +100,7 @@ http://<DSH 地址>:<端口>/dsh-go-plugin-sync/
|
|
|
107
100
|
- Cordis 插件可能依赖 DSH 版本或平台,装不上会进失败清单
|
|
108
101
|
- 不同步插件的启用状态和插件配置
|
|
109
102
|
- 首次两端都要手动安装本插件
|
|
103
|
+
- Windows 只支持同步码安装;Git 中转和 SSH 暂不支持
|
|
110
104
|
|
|
111
105
|
## 安全
|
|
112
106
|
|
package/lib/client.js
CHANGED
|
@@ -3,9 +3,23 @@ window.__ModuleLoader__.load({
|
|
|
3
3
|
factory(require) {
|
|
4
4
|
const React = require('react')
|
|
5
5
|
const h = React.createElement
|
|
6
|
-
const
|
|
6
|
+
const API = '/dsh-go-plugin-sync/api'
|
|
7
|
+
const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
|
|
8
|
+
const T = (cn, en) => (zh ? cn : en)
|
|
9
|
+
const INPUT = {
|
|
10
|
+
width: '100%',
|
|
11
|
+
boxSizing: 'border-box',
|
|
12
|
+
padding: '6px 8px',
|
|
13
|
+
borderRadius: '6px',
|
|
14
|
+
border: '1px solid rgba(128,128,128,.35)',
|
|
15
|
+
background: 'transparent',
|
|
16
|
+
color: 'inherit',
|
|
17
|
+
font: 'inherit',
|
|
18
|
+
fontSize: '13px',
|
|
19
|
+
}
|
|
20
|
+
const LABEL = { display: 'block', margin: '8px 0 0', fontSize: '12px', opacity: 0.7 }
|
|
7
21
|
const BUTTON = {
|
|
8
|
-
padding: '
|
|
22
|
+
padding: '6px 12px',
|
|
9
23
|
borderRadius: '6px',
|
|
10
24
|
border: '1px solid rgba(128,128,128,.35)',
|
|
11
25
|
background: 'transparent',
|
|
@@ -14,42 +28,189 @@ window.__ModuleLoader__.load({
|
|
|
14
28
|
fontSize: '13px',
|
|
15
29
|
cursor: 'pointer',
|
|
16
30
|
}
|
|
31
|
+
const PRIMARY = { ...BUTTON, background: '#3D6FD6', borderColor: '#3D6FD6', color: '#fff' }
|
|
32
|
+
|
|
33
|
+
function api(path, body) {
|
|
34
|
+
const options = body === undefined
|
|
35
|
+
? {}
|
|
36
|
+
: { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }
|
|
37
|
+
return fetch(`${API}/${path}`, options).then((response) => response.json())
|
|
38
|
+
}
|
|
17
39
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
url.search = window.location.search || ''
|
|
28
|
-
url.hash = window.location.hash || ''
|
|
29
|
-
return url.href
|
|
40
|
+
function Field({ label, value, onChange, placeholder, type }) {
|
|
41
|
+
return h('label', { style: LABEL }, label,
|
|
42
|
+
h('input', {
|
|
43
|
+
type: type || 'text',
|
|
44
|
+
value: value == null ? '' : String(value),
|
|
45
|
+
placeholder: placeholder || '',
|
|
46
|
+
onChange: (event) => onChange(event.target.value),
|
|
47
|
+
style: { ...INPUT, marginTop: '4px' },
|
|
48
|
+
}))
|
|
30
49
|
}
|
|
31
50
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
function SyncSettings() {
|
|
52
|
+
const [rows, setRows] = React.useState([])
|
|
53
|
+
const [picked, setPicked] = React.useState({})
|
|
54
|
+
const [code, setCode] = React.useState('')
|
|
55
|
+
const [config, setConfig] = React.useState(null)
|
|
56
|
+
const [status, setStatus] = React.useState('')
|
|
57
|
+
const [tone, setTone] = React.useState('')
|
|
58
|
+
const [busy, setBusy] = React.useState(false)
|
|
59
|
+
const [configPath, setConfigPath] = React.useState('')
|
|
60
|
+
const wasRunning = React.useRef(false)
|
|
61
|
+
|
|
62
|
+
const note = (text, kind) => { setStatus(text); setTone(kind || '') }
|
|
63
|
+
|
|
64
|
+
const load = () => api('state').then((snapshot) => {
|
|
65
|
+
if (snapshot.error) { note(snapshot.error, 'bad'); return }
|
|
66
|
+
setRows(snapshot.rows || [])
|
|
67
|
+
setConfig(snapshot.config || null)
|
|
68
|
+
setConfigPath(snapshot.configPath || '')
|
|
69
|
+
const next = {}
|
|
70
|
+
for (const name of snapshot.selected || []) next[name] = true
|
|
71
|
+
setPicked(next)
|
|
72
|
+
}).catch((error) => note(String(error && error.message || error), 'bad'))
|
|
73
|
+
|
|
74
|
+
React.useEffect(() => { load() }, [])
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
const timer = setInterval(() => {
|
|
77
|
+
api('status').then((snapshot) => {
|
|
78
|
+
if (!snapshot.task) return
|
|
79
|
+
if (snapshot.task.running) note(T('正在执行…', 'Running…'))
|
|
80
|
+
else if (snapshot.task.ok === false) note(T(`上次失败 ${snapshot.task.failed} 项`, `Last run failed: ${snapshot.task.failed}`), 'bad')
|
|
81
|
+
else note(T('上次完成', 'Last run finished'), 'good')
|
|
82
|
+
if (wasRunning.current && !snapshot.task.running) load()
|
|
83
|
+
wasRunning.current = snapshot.task.running
|
|
84
|
+
}).catch(() => {})
|
|
85
|
+
}, 3000)
|
|
86
|
+
return () => clearInterval(timer)
|
|
87
|
+
}, [])
|
|
88
|
+
|
|
89
|
+
const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
|
|
90
|
+
const all = (checked) => {
|
|
91
|
+
const next = {}
|
|
92
|
+
for (const row of rows) next[row.name] = checked
|
|
93
|
+
setPicked(next)
|
|
94
|
+
}
|
|
95
|
+
const importCode = () => {
|
|
96
|
+
if (!code.trim()) { note(T('先粘贴同步码', 'Paste a sync code first'), 'bad'); return }
|
|
97
|
+
setBusy(true)
|
|
98
|
+
api('import', { code }).then((result) => {
|
|
99
|
+
setBusy(false)
|
|
100
|
+
if (result.error) { note(result.error, 'bad'); return }
|
|
101
|
+
setCode('')
|
|
102
|
+
note(T(`已导入 ${result.count} 个插件,选中 ${result.selected} 个`, `Imported ${result.count}, selected ${result.selected}`), 'good')
|
|
103
|
+
load()
|
|
104
|
+
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
105
|
+
}
|
|
106
|
+
const applySelected = () => {
|
|
107
|
+
const names = rows.filter((row) => row.action && picked[row.name]).map((row) => row.name)
|
|
108
|
+
if (names.length === 0) { note(T('先选择要安装的插件', 'Select plugins to install'), 'bad'); return }
|
|
109
|
+
setBusy(true)
|
|
110
|
+
api('apply', { names }).then((result) => {
|
|
111
|
+
setBusy(false)
|
|
112
|
+
if (result.error) { note(result.error, 'bad'); return }
|
|
113
|
+
note(T(`已开始安装 ${result.count} 项`, `Installing ${result.count}`), 'good')
|
|
114
|
+
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
115
|
+
}
|
|
116
|
+
const setPath = (path, value) => setConfig((previous) => {
|
|
117
|
+
const next = { ...previous }
|
|
118
|
+
const keys = path.split('.')
|
|
119
|
+
let cursor = next
|
|
120
|
+
for (let index = 0; index < keys.length - 1; index += 1) {
|
|
121
|
+
cursor[keys[index]] = { ...(cursor[keys[index]] || {}) }
|
|
122
|
+
cursor = cursor[keys[index]]
|
|
123
|
+
}
|
|
124
|
+
cursor[keys[keys.length - 1]] = value
|
|
125
|
+
return next
|
|
126
|
+
})
|
|
127
|
+
const saveConfig = () => {
|
|
128
|
+
if (!config) { note(T('配置还没加载完,稍后再试', 'Configuration is not loaded yet'), 'bad'); return }
|
|
129
|
+
setBusy(true)
|
|
130
|
+
api('config', { config }).then((result) => {
|
|
131
|
+
setBusy(false)
|
|
132
|
+
if (result.error) { note(result.error, 'bad'); return }
|
|
133
|
+
setConfig(result.config)
|
|
134
|
+
setConfigPath(result.path || configPath)
|
|
135
|
+
note(T('配置已保存', 'Configuration saved'), 'good')
|
|
136
|
+
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const relay = config && config.relay ? config.relay : { repo: '', branch: 'main', dir: 'dsh-go-plugins' }
|
|
140
|
+
const ssh = config && config.ssh ? config.ssh : { host: '', port: 22, user: '', identity: '', remoteHome: '~/.dsh', dshPath: 'dsh', nodePath: 'node', profile: 'web' }
|
|
141
|
+
|
|
142
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
|
|
143
|
+
h('div', { style: { fontSize: '13px', opacity: 0.7 } },
|
|
144
|
+
T('从同步码安装缺少的插件;只增不删,冲突只提示。', 'Install missing plugins from a sync code. Add-only: conflicts are warnings.')),
|
|
145
|
+
|
|
146
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
147
|
+
h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
|
|
148
|
+
h('textarea', {
|
|
149
|
+
value: code,
|
|
150
|
+
rows: 4,
|
|
151
|
+
placeholder: 'DSHSYNC1:…',
|
|
152
|
+
onChange: (event) => setCode(event.target.value),
|
|
153
|
+
style: { ...INPUT, fontFamily: 'ui-monospace, monospace', minHeight: '80px', resize: 'vertical' },
|
|
154
|
+
}),
|
|
155
|
+
h('div', { style: { display: 'flex', gap: '8px' } },
|
|
156
|
+
h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: importCode }, T('导入同步码', 'Import code')),
|
|
157
|
+
h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: load }, T('刷新', 'Refresh')))),
|
|
158
|
+
|
|
159
|
+
rows.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
160
|
+
h('div', { style: { fontWeight: 600 } }, T('待处理插件', 'Plugins')),
|
|
161
|
+
...rows.map((row) => h('label', {
|
|
162
|
+
key: row.name,
|
|
163
|
+
style: { display: 'flex', alignItems: 'center', gap: '8px', padding: '4px 0', opacity: row.action ? 1 : 0.55 },
|
|
164
|
+
},
|
|
165
|
+
h('input', {
|
|
166
|
+
type: 'checkbox',
|
|
167
|
+
checked: Boolean(picked[row.name]),
|
|
168
|
+
disabled: !row.action,
|
|
169
|
+
onChange: (event) => toggle(row.name, event.target.checked),
|
|
170
|
+
}),
|
|
171
|
+
h('span', { style: { fontWeight: 500 } }, row.name),
|
|
172
|
+
h('span', { style: { marginLeft: 'auto', fontSize: '12px', opacity: 0.65 } }, row.subtitle || row.status))),
|
|
173
|
+
h('div', { style: { display: 'flex', gap: '8px', marginTop: '4px' } },
|
|
174
|
+
h('button', { type: 'button', style: BUTTON, onClick: () => all(true) }, T('全选', 'Select all')),
|
|
175
|
+
h('button', { type: 'button', style: BUTTON, onClick: () => all(false) }, T('清空', 'Clear')),
|
|
176
|
+
h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: applySelected }, T('安装选中', 'Install selected')))),
|
|
177
|
+
|
|
178
|
+
status && h('div', { style: { fontSize: '13px', color: tone === 'bad' ? '#c62828' : tone === 'good' ? '#2e7d32' : 'inherit' } }, status),
|
|
179
|
+
|
|
180
|
+
h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
|
|
181
|
+
h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
|
|
182
|
+
h(Field, { label: T('仓库地址', 'Repository'), value: relay.repo, onChange: (value) => setPath('relay.repo', value), placeholder: 'https://gitee.com/you/dsh-plugins.git' }),
|
|
183
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
|
|
184
|
+
h(Field, { label: T('分支', 'Branch'), value: relay.branch, onChange: (value) => setPath('relay.branch', value) }),
|
|
185
|
+
h(Field, { label: T('目录', 'Directory'), value: relay.dir, onChange: (value) => setPath('relay.dir', value) }))),
|
|
186
|
+
|
|
187
|
+
h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
|
|
188
|
+
h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('SSH(可选)', 'SSH (optional)')),
|
|
189
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
|
|
190
|
+
h(Field, { label: T('主机', 'Host'), value: ssh.host, onChange: (value) => setPath('ssh.host', value), placeholder: '192.168.1.10' }),
|
|
191
|
+
h(Field, { label: T('端口', 'Port'), value: ssh.port, onChange: (value) => setPath('ssh.port', Number(value) || 22), type: 'number' }),
|
|
192
|
+
h(Field, { label: T('用户', 'User'), value: ssh.user, onChange: (value) => setPath('ssh.user', value) }),
|
|
193
|
+
h(Field, { label: T('私钥路径', 'Identity file'), value: ssh.identity, onChange: (value) => setPath('ssh.identity', value), placeholder: '~/.ssh/id_ed25519' }),
|
|
194
|
+
h(Field, { label: T('远端 HOME', 'Remote home'), value: ssh.remoteHome, onChange: (value) => setPath('ssh.remoteHome', value) }),
|
|
195
|
+
h(Field, { label: T('profile', 'Profile'), value: ssh.profile, onChange: (value) => setPath('ssh.profile', value) }))),
|
|
196
|
+
|
|
197
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' } },
|
|
198
|
+
h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: saveConfig }, T('保存配置', 'Save configuration')),
|
|
199
|
+
configPath && h('span', { style: { fontSize: '12px', opacity: 0.6, wordBreak: 'break-all' } }, configPath)),
|
|
200
|
+
|
|
201
|
+
h('div', { style: { fontSize: '12px', opacity: 0.6 } },
|
|
202
|
+
T('SSH 只支持密钥或 agent,不保存密码;Git 使用系统凭据。', 'SSH uses a key or agent (no passwords). Git uses system credentials.')))
|
|
43
203
|
}
|
|
44
204
|
|
|
45
205
|
return {
|
|
46
206
|
inject: ['slots'],
|
|
47
207
|
apply(ctx) {
|
|
48
|
-
ctx.slots.inject('
|
|
49
|
-
name: '
|
|
50
|
-
id: 'dsh-go-plugin-sync
|
|
51
|
-
order:
|
|
52
|
-
|
|
208
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
209
|
+
name: 'settings.section',
|
|
210
|
+
id: 'dsh-go-plugin-sync',
|
|
211
|
+
order: 50,
|
|
212
|
+
label: () => T('插件同步', 'Plugin sync'),
|
|
213
|
+
}, SyncSettings))
|
|
53
214
|
},
|
|
54
215
|
}
|
|
55
216
|
},
|
package/lib/index.js
CHANGED
|
@@ -54,6 +54,8 @@ const sshManifestFile = () => join(storeDir(), 'ssh-manifest.json')
|
|
|
54
54
|
const pushManifestFile = () => join(storeDir(), 'push-manifest.json')
|
|
55
55
|
const remoteScannerFile = () => join(storeDir(), 'scan-remote.cjs')
|
|
56
56
|
const taskScriptPath = () => join(storeDir(), 'task.sh')
|
|
57
|
+
const taskRunnerPath = () => join(storeDir(), 'task-runner.cjs')
|
|
58
|
+
const taskSpecPath = () => join(storeDir(), 'task-spec.json')
|
|
57
59
|
const taskLogPath = () => join(storeDir(), 'task.log')
|
|
58
60
|
const taskStatusPath = () => join(storeDir(), 'task-status.txt')
|
|
59
61
|
|
|
@@ -73,6 +75,16 @@ function safeName(value) {
|
|
|
73
75
|
return typeof value === 'string' && (PKG_NAME.test(value) || SAFE_DIR.test(value))
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
/** A single directory name directly under the plugins root. */
|
|
79
|
+
function safeDirName(value) {
|
|
80
|
+
return typeof value === 'string' && value !== '.' && value !== '..' && SAFE_DIR.test(value)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Token used in task log markers; keeps `@@ action name start` one line and inert. */
|
|
84
|
+
function markerName(value) {
|
|
85
|
+
return String(value).replace(/[^A-Za-z0-9._@/-]/g, '_').slice(0, 80) || '_'
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
function safeRel(value) {
|
|
77
89
|
if (typeof value !== 'string' || value.length === 0 || value.length > 200) return false
|
|
78
90
|
if (value.includes('\\') || value.includes('\0') || value.startsWith('/') || value.includes('..')) return false
|
|
@@ -121,7 +133,7 @@ function buildSyncCode(plugins) {
|
|
|
121
133
|
hash: plugin.hash,
|
|
122
134
|
relDir: plugin.relDir,
|
|
123
135
|
depSpec: plugin.depSpec,
|
|
124
|
-
files:
|
|
136
|
+
files: safeDirName(plugin.relDir) && existsSync(plugin.dir)
|
|
125
137
|
? readPluginTextFiles(plugin.dir)
|
|
126
138
|
: {},
|
|
127
139
|
}))
|
|
@@ -144,17 +156,19 @@ function buildSyncCode(plugins) {
|
|
|
144
156
|
function decodeSyncCode(text) {
|
|
145
157
|
const trimmed = String(text || '').trim().replace(/\s+/g, '')
|
|
146
158
|
if (!trimmed.startsWith(CODE_PREFIX)) return { error: '不是同步码' }
|
|
159
|
+
const body = trimmed.slice(CODE_PREFIX.length)
|
|
160
|
+
if (body.length > 100_000) return { error: '同步码太大' }
|
|
147
161
|
let doc
|
|
148
162
|
try {
|
|
149
|
-
doc = JSON.parse(inflateRawSync(Buffer.from(
|
|
163
|
+
doc = JSON.parse(inflateRawSync(Buffer.from(body, 'base64url'), { maxOutputLength: 2 * 1024 * 1024 }).toString('utf8'))
|
|
150
164
|
} catch {
|
|
151
|
-
return { error: '
|
|
165
|
+
return { error: '同步码损坏或过大' }
|
|
152
166
|
}
|
|
153
167
|
if (!doc || doc.v !== 2 || doc.t !== 'dsh-go-plugin-sync' || !Array.isArray(doc.plugins)) return { error: '同步码版本不对' }
|
|
154
168
|
const plugins = []
|
|
155
169
|
for (const raw of doc.plugins.slice(0, 200)) {
|
|
156
170
|
if (!raw || typeof raw.name !== 'string' || !safeName(raw.name)) continue
|
|
157
|
-
const relDir =
|
|
171
|
+
const relDir = safeDirName(raw.relDir) ? raw.relDir : null
|
|
158
172
|
const files = {}
|
|
159
173
|
if (raw.files && typeof raw.files === 'object') {
|
|
160
174
|
for (const [rel, content] of Object.entries(raw.files)) {
|
|
@@ -171,6 +185,7 @@ function decodeSyncCode(text) {
|
|
|
171
185
|
files,
|
|
172
186
|
})
|
|
173
187
|
}
|
|
188
|
+
if (plugins.length === 0) return { error: '同步码里没有可同步插件' }
|
|
174
189
|
return {
|
|
175
190
|
plugins,
|
|
176
191
|
manifest: {
|
|
@@ -187,7 +202,7 @@ function decodeSyncCode(text) {
|
|
|
187
202
|
function writeCodeFiles(decoded) {
|
|
188
203
|
let written = 0
|
|
189
204
|
for (const plugin of decoded.plugins) {
|
|
190
|
-
if (!plugin.relDir || Object.keys(plugin.files).length === 0) continue
|
|
205
|
+
if (!safeDirName(plugin.relDir) || Object.keys(plugin.files).length === 0) continue
|
|
191
206
|
const dir = join(pluginsRoot(), plugin.relDir)
|
|
192
207
|
if (existsSync(dir)) continue
|
|
193
208
|
try {
|
|
@@ -452,7 +467,7 @@ function validManifest(doc) {
|
|
|
452
467
|
version: typeof raw.version === 'string' ? raw.version : '0.0.0',
|
|
453
468
|
title: typeof raw.title === 'string' ? raw.title.slice(0, 40) : '',
|
|
454
469
|
hash: typeof raw.hash === 'string' ? raw.hash.slice(0, 64) : null,
|
|
455
|
-
relDir:
|
|
470
|
+
relDir: safeDirName(raw.relDir) ? raw.relDir : null,
|
|
456
471
|
depSpec: typeof raw.depSpec === 'string' ? raw.depSpec.slice(0, 200) : null,
|
|
457
472
|
installed: raw.installed === true,
|
|
458
473
|
})
|
|
@@ -666,8 +681,16 @@ function readTaskResults() {
|
|
|
666
681
|
|
|
667
682
|
// ---------------------------------------------------------------- task runner
|
|
668
683
|
|
|
669
|
-
function
|
|
684
|
+
function taskRunning() {
|
|
685
|
+
const status = readTaskStatus()
|
|
686
|
+
return Boolean(status?.running && Date.now() - status.startedAt < 15 * 60 * 1000)
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/** Start one background task; returns `{ ok }` or an explanation of why it did not start. */
|
|
690
|
+
function startTask(kind, lines, win) {
|
|
691
|
+
if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
|
|
670
692
|
ensureStore()
|
|
693
|
+
if (process.platform === 'win32') return startWindowsTask(kind, win)
|
|
671
694
|
const script = [
|
|
672
695
|
'#!/bin/sh',
|
|
673
696
|
`LOG=${shQuote(taskLogPath())}`,
|
|
@@ -685,6 +708,98 @@ function startTask(kind, lines) {
|
|
|
685
708
|
const child = spawn('/bin/sh', [taskScriptPath()], { detached: true, stdio: 'ignore', env: process.env })
|
|
686
709
|
child.on('error', () => {})
|
|
687
710
|
child.unref()
|
|
711
|
+
return { ok: true }
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** `dsh` entry point that also works from a packaged Windows runtime. */
|
|
715
|
+
function dshCommand() {
|
|
716
|
+
const entry = typeof process.argv[1] === 'string' ? process.argv[1] : ''
|
|
717
|
+
if (/\.(?:c|m)?js$/i.test(entry)) return { command: process.execPath, args: [entry] }
|
|
718
|
+
const bin = process.env.DSH_BIN || ''
|
|
719
|
+
if (/\.(?:c|m)?js$/i.test(bin)) return { command: process.execPath, args: [bin] }
|
|
720
|
+
if (bin) return { command: bin, args: [] }
|
|
721
|
+
return { command: process.execPath, args: [entry] }
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/** Windows has no `/bin/sh`; install jobs run through Node instead of the POSIX task script. */
|
|
725
|
+
function startWindowsTask(kind, win) {
|
|
726
|
+
const installs = kind === 'apply' && Array.isArray(win?.installs)
|
|
727
|
+
? win.installs.filter((job) => job && typeof job.name === 'string' && typeof job.target === 'string' && job.target !== '')
|
|
728
|
+
: []
|
|
729
|
+
if (kind === 'apply' && (win?.other || 0) > 0) {
|
|
730
|
+
return { ok: false, error: 'Windows 上暂不支持 SSH 推/拉,请先只选安装项' }
|
|
731
|
+
}
|
|
732
|
+
if (installs.length === 0) return { ok: false, error: 'Windows 上暂不支持 Git 中转 / SSH,请用同步码安装' }
|
|
733
|
+
const dsh = dshCommand()
|
|
734
|
+
const spec = {
|
|
735
|
+
kind,
|
|
736
|
+
log: taskLogPath(),
|
|
737
|
+
status: taskStatusPath(),
|
|
738
|
+
items: installs.map((job) => ({
|
|
739
|
+
action: 'install',
|
|
740
|
+
name: markerName(job.name),
|
|
741
|
+
commands: [{ command: dsh.command, args: [...dsh.args, 'plugin', '--profile', profileName(), 'add', job.target] }],
|
|
742
|
+
})),
|
|
743
|
+
}
|
|
744
|
+
writeFileSync(taskRunnerPath(), windowsTaskRunnerSource())
|
|
745
|
+
writeFileSync(taskSpecPath(), JSON.stringify(spec, null, 2) + '\n')
|
|
746
|
+
writeFileSync(taskLogPath(), '')
|
|
747
|
+
writeFileSync(taskStatusPath(), `running ${Math.floor(Date.now() / 1000)} ${kind}\n`)
|
|
748
|
+
try {
|
|
749
|
+
const child = spawn(process.execPath, [taskRunnerPath(), taskSpecPath()], { detached: true, stdio: 'ignore', env: process.env })
|
|
750
|
+
child.on('error', () => {})
|
|
751
|
+
child.unref()
|
|
752
|
+
} catch (error) {
|
|
753
|
+
writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${installs.length} ${kind}\n`)
|
|
754
|
+
return { ok: false, error: `启动安装任务失败:${String(error?.message || error)}` }
|
|
755
|
+
}
|
|
756
|
+
return { ok: true }
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function windowsTaskRunnerSource() {
|
|
760
|
+
return `'use strict'
|
|
761
|
+
const { spawn } = require('node:child_process')
|
|
762
|
+
const fs = require('node:fs')
|
|
763
|
+
const spec = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))
|
|
764
|
+
const log = fs.openSync(spec.log, 'w')
|
|
765
|
+
const say = (line) => fs.writeSync(log, line + '\\n')
|
|
766
|
+
const status = (line) => fs.writeFileSync(spec.status, line + '\\n')
|
|
767
|
+
status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind)
|
|
768
|
+
function run(command, args) {
|
|
769
|
+
return new Promise((resolve) => {
|
|
770
|
+
let child
|
|
771
|
+
try {
|
|
772
|
+
child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env })
|
|
773
|
+
} catch (error) {
|
|
774
|
+
say(String(error && error.message ? error.message : error))
|
|
775
|
+
resolve(1)
|
|
776
|
+
return
|
|
777
|
+
}
|
|
778
|
+
child.stdout.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
779
|
+
child.stderr.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
780
|
+
child.on('error', (error) => { say(String(error && error.message ? error.message : error)); resolve(1) })
|
|
781
|
+
child.on('exit', (code) => resolve(code === 0 ? 0 : 1))
|
|
782
|
+
})
|
|
783
|
+
}
|
|
784
|
+
;(async () => {
|
|
785
|
+
let failed = 0
|
|
786
|
+
for (const item of spec.items) {
|
|
787
|
+
say('@@ ' + item.action + ' ' + item.name + ' start')
|
|
788
|
+
let code = 0
|
|
789
|
+
for (const command of item.commands) {
|
|
790
|
+
if (await run(command.command, command.args) !== 0) code = 1
|
|
791
|
+
}
|
|
792
|
+
if (code === 0) say('@@ ' + item.action + ' ' + item.name + ' ok')
|
|
793
|
+
else { failed += 1; say('@@ ' + item.action + ' ' + item.name + ' fail') }
|
|
794
|
+
}
|
|
795
|
+
fs.closeSync(log)
|
|
796
|
+
status('done ' + Math.floor(Date.now() / 1000) + ' ' + failed + ' ' + spec.kind)
|
|
797
|
+
})().catch((error) => {
|
|
798
|
+
try { say(String(error && error.stack ? error.stack : error)) } catch {}
|
|
799
|
+
try { fs.closeSync(log) } catch {}
|
|
800
|
+
try { status('done ' + Math.floor(Date.now() / 1000) + ' 1 ' + spec.kind) } catch {}
|
|
801
|
+
})
|
|
802
|
+
`
|
|
688
803
|
}
|
|
689
804
|
|
|
690
805
|
function localAddCommand(dir) {
|
|
@@ -693,7 +808,7 @@ function localAddCommand(dir) {
|
|
|
693
808
|
|
|
694
809
|
/** One result-reporting item: start marker, commands, ok/fail marker. */
|
|
695
810
|
function itemLines(action, name, commands) {
|
|
696
|
-
const tag = `${action} ${name}`
|
|
811
|
+
const tag = `${action} ${markerName(name)}`
|
|
697
812
|
const lines = [`say "@@ ${tag} start"`, 'itemfailed=0']
|
|
698
813
|
for (const command of commands) {
|
|
699
814
|
lines.push(`${command} >> "$LOG" 2>&1 || itemfailed=$((itemfailed + 1))`)
|
|
@@ -739,7 +854,7 @@ function buildRelayPush(cfg, plugins, manifestPath) {
|
|
|
739
854
|
' mkdir -p "$WORK/$RELAY_DIR/plugins"',
|
|
740
855
|
]
|
|
741
856
|
for (const plugin of plugins) {
|
|
742
|
-
if (!
|
|
857
|
+
if (!safeDirName(plugin.relDir)) continue
|
|
743
858
|
lines.push(` tar -C ${shQuote(pluginsRoot())} -cf - --exclude=node_modules --exclude=.git ${shQuote(plugin.relDir)} | tar -C "$WORK/$RELAY_DIR/plugins" -xf - >> "$LOG" 2>&1 || failed=$((failed + 1))`)
|
|
744
859
|
}
|
|
745
860
|
lines.push(
|
|
@@ -817,6 +932,18 @@ function buildSshPull(cfg, jobs) {
|
|
|
817
932
|
return lines
|
|
818
933
|
}
|
|
819
934
|
|
|
935
|
+
function installTargets(jobs) {
|
|
936
|
+
return jobs
|
|
937
|
+
.filter((job) => job.action === 'install')
|
|
938
|
+
.map((job) => ({ name: job.name, target: job.localDir || job.registrySpec }))
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** Windows task payload: install jobs only, plus how many push/pull jobs were left out. */
|
|
942
|
+
function winTask(jobs) {
|
|
943
|
+
const installs = installTargets(jobs)
|
|
944
|
+
return { installs, other: jobs.length - installs.length }
|
|
945
|
+
}
|
|
946
|
+
|
|
820
947
|
function buildApply(cfg, jobs) {
|
|
821
948
|
const lines = []
|
|
822
949
|
const installs = jobs.filter((job) => job.action === 'install')
|
|
@@ -1246,79 +1373,19 @@ function webSnapshot(ctx) {
|
|
|
1246
1373
|
})),
|
|
1247
1374
|
task: readTaskStatus(),
|
|
1248
1375
|
results: readTaskResults(),
|
|
1249
|
-
config:
|
|
1376
|
+
config: cfg,
|
|
1377
|
+
configPath: configPathFor(ctx, scope),
|
|
1250
1378
|
}
|
|
1251
1379
|
}
|
|
1252
1380
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
:root{color-scheme:light dark}
|
|
1262
|
-
body{font:14px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;padding:16px;max-width:820px;margin-inline:auto}
|
|
1263
|
-
h1{font-size:20px;margin:0 0 4px}h2{font-size:15px;margin:20px 0 8px}
|
|
1264
|
-
.muted{opacity:.65}.row{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0}
|
|
1265
|
-
button{font:inherit;padding:7px 12px;border-radius:8px;border:1px solid #8884;background:#8881;cursor:pointer}
|
|
1266
|
-
button.primary{background:#3D6FD6;border-color:#3D6FD6;color:#fff}
|
|
1267
|
-
button:disabled{opacity:.5;cursor:default}
|
|
1268
|
-
textarea{width:100%;box-sizing:border-box;min-height:88px;font:12px/1.4 ui-monospace,monospace;padding:8px;border-radius:8px;border:1px solid #8884;background:#8881}
|
|
1269
|
-
ul{list-style:none;padding:0;margin:0}
|
|
1270
|
-
li.item{display:flex;align-items:center;gap:8px;padding:6px 4px;border-bottom:1px solid #8882}
|
|
1271
|
-
li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opacity:.7}
|
|
1272
|
-
.status{font-size:12px;opacity:.8}.bad{color:#c62828}.good{color:#2e7d32}
|
|
1273
|
-
</style>
|
|
1274
|
-
</head>
|
|
1275
|
-
<body>
|
|
1276
|
-
<h1>插件同步</h1>
|
|
1277
|
-
<div id="addr" class="muted"></div>
|
|
1278
|
-
<div class="muted">复制同步码到另一台主机导入;只安装缺少的插件,不卸载、不覆盖。</div>
|
|
1279
|
-
<div id="config" class="muted"></div>
|
|
1280
|
-
|
|
1281
|
-
<h2>发送(本机 → 同步码)</h2>
|
|
1282
|
-
<ul id="plugins"></ul>
|
|
1283
|
-
<div class="row">
|
|
1284
|
-
<button id="all">全选</button>
|
|
1285
|
-
<button id="none">清空</button>
|
|
1286
|
-
<button id="copy" class="primary">复制同步码</button>
|
|
1287
|
-
</div>
|
|
1288
|
-
<textarea id="code" placeholder="生成的同步码会显示在这里" readonly></textarea>
|
|
1289
|
-
|
|
1290
|
-
<h2>接收(同步码 → 本机)</h2>
|
|
1291
|
-
<textarea id="importCode" placeholder="粘贴 DSHSYNC1: 开头的同步码"></textarea>
|
|
1292
|
-
<div class="row"><button id="import" class="primary">导入同步码</button></div>
|
|
1293
|
-
<ul id="diff"></ul>
|
|
1294
|
-
<div class="row"><button id="apply" class="primary">安装选中</button></div>
|
|
1295
|
-
|
|
1296
|
-
<h2>状态</h2>
|
|
1297
|
-
<div id="status" class="status"></div>
|
|
1298
|
-
<div id="results"></div>
|
|
1299
|
-
<script>
|
|
1300
|
-
(function(){
|
|
1301
|
-
var localSelected=new Set(), diffSelected=new Set(), current={};
|
|
1302
|
-
function el(t,c,x){var n=document.createElement(t);if(c)n.className=c;if(x!=null)n.textContent=x;return n}
|
|
1303
|
-
(function(){var a=document.getElementById('addr');if(a)a.textContent='地址:'+location.origin+'/dsh-go-plugin-sync/'})();
|
|
1304
|
-
function api(p,b){var o=b===undefined?{}:{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify(b)};return fetch('api/'+p,o).then(function(r){return r.json()})}
|
|
1305
|
-
function setStatus(t,c){var n=document.getElementById('status');n.textContent=t;n.className='status'+(c?' '+c:'')}
|
|
1306
|
-
function renderPlugins(list){var ul=document.getElementById('plugins');ul.textContent='';(list||[]).forEach(function(p){var li=el('li','item');var cb=el('input');cb.type='checkbox';cb.checked=localSelected.has(p.name);cb.onchange=function(){if(cb.checked)localSelected.add(p.name);else localSelected.delete(p.name)};li.appendChild(cb);li.appendChild(el('span','name',p.name));li.appendChild(el('span','meta','v'+p.version+(p.installed?' · 已安装':' · 未安装')));ul.appendChild(li)})}
|
|
1307
|
-
function renderDiff(rows){var ul=document.getElementById('diff');ul.textContent='';if(!rows||!rows.length){ul.appendChild(el('li','muted','导入后在这里选择要安装的插件'));return}rows.forEach(function(r){var li=el('li','item');var cb=el('input');cb.type='checkbox';cb.disabled=!r.action;cb.checked=diffSelected.has(r.name);cb.onchange=function(){if(cb.checked)diffSelected.add(r.name);else diffSelected.delete(r.name)};li.appendChild(cb);li.appendChild(el('span','name',r.name));li.appendChild(el('span','meta',r.subtitle));ul.appendChild(li)})}
|
|
1308
|
-
function renderResults(list){var box=document.getElementById('results');box.textContent='';(list||[]).forEach(function(r){box.appendChild(el('div',r.ok?'good':'bad',(r.ok?'✓ ':'✗ ')+r.name+(r.message?' — '+r.message:'')))})}
|
|
1309
|
-
function renderTask(t){if(!t){setStatus('就绪');return}if(t.running){setStatus('正在执行…');return}setStatus(t.ok===false?('上次失败 '+t.failed+' 项'):'上次完成',t.ok===false?'bad':'good')}
|
|
1310
|
-
function refresh(){return api('state').then(function(s){if(s.error){setStatus(s.error,'bad');return}current=s;localSelected=new Set(s.selected||[]);diffSelected=new Set(s.selected||[]);renderPlugins(s.plugins);renderDiff(s.rows);renderResults(s.results);renderTask(s.task);var c=s.config||{};document.getElementById('config').textContent='中转:'+(c.relay?'已配置':'未配置')+' · SSH:'+(c.ssh?'已配置':'未配置')})}
|
|
1311
|
-
function poll(){api('status').then(function(s){if(s.task)renderTask(s.task);if(s.results)renderResults(s.results);if(s.task&&!s.task.running)refresh()}).catch(function(){})}
|
|
1312
|
-
document.getElementById('all').onclick=function(){(current.plugins||[]).forEach(function(p){localSelected.add(p.name)});renderPlugins(current.plugins)};
|
|
1313
|
-
document.getElementById('none').onclick=function(){localSelected.clear();renderPlugins(current.plugins)};
|
|
1314
|
-
document.getElementById('copy').onclick=function(){api('export',{names:Array.from(localSelected)}).then(function(r){if(r.error){setStatus(r.error,'bad');return}document.getElementById('code').value=r.code;if(navigator.clipboard)navigator.clipboard.writeText(r.code).catch(function(){});setStatus('已生成 '+r.count+' 个插件的同步码','good')})};
|
|
1315
|
-
document.getElementById('import').onclick=function(){var code=document.getElementById('importCode').value.trim();if(!code){setStatus('先粘贴同步码','bad');return}api('import',{code:code}).then(function(r){if(r.error){setStatus(r.error,'bad');return}setStatus('已导入 '+r.count+' 个插件,选中 '+r.selected+' 个','good');refresh()})};
|
|
1316
|
-
document.getElementById('apply').onclick=function(){var names=Array.from(diffSelected);if(!names.length){setStatus('先选择要安装的插件','bad');return}api('apply',{names:names}).then(function(r){if(r.error){setStatus(r.error,'bad');return}setStatus('已开始安装 '+r.count+' 项','good');refresh()})};
|
|
1317
|
-
refresh();setInterval(poll,3000);
|
|
1318
|
-
})();
|
|
1319
|
-
</script>
|
|
1320
|
-
</body>
|
|
1321
|
-
</html>`
|
|
1381
|
+
/** Where the next saved config will live: an existing workspace file, else the store. */
|
|
1382
|
+
function configPathFor(ctx, scope) {
|
|
1383
|
+
const ws = writableDir(ctx, scope)
|
|
1384
|
+
if (ws) {
|
|
1385
|
+
const path = join(ws, CONFIG_FILE)
|
|
1386
|
+
if (existsSync(path)) return path
|
|
1387
|
+
}
|
|
1388
|
+
return join(storeDir(), CONFIG_FILE)
|
|
1322
1389
|
}
|
|
1323
1390
|
|
|
1324
1391
|
// ---------------------------------------------------------------- plugin
|
|
@@ -1355,7 +1422,7 @@ export function apply(ctx) {
|
|
|
1355
1422
|
const cfg = loadConfig(ctx, scope)
|
|
1356
1423
|
if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
|
|
1357
1424
|
const local = localPlugins()
|
|
1358
|
-
const pushable = local.filter((plugin) =>
|
|
1425
|
+
const pushable = local.filter((plugin) => safeDirName(plugin.relDir))
|
|
1359
1426
|
if (pushable.length === 0) return { toast: '本机没有可推送的插件' }
|
|
1360
1427
|
const manifest = buildManifest(local)
|
|
1361
1428
|
try {
|
|
@@ -1364,7 +1431,8 @@ export function apply(ctx) {
|
|
|
1364
1431
|
} catch {
|
|
1365
1432
|
return { toast: '写清单失败' }
|
|
1366
1433
|
}
|
|
1367
|
-
startTask('relay-push', buildRelayPush(cfg, pushable, pushManifestFile()))
|
|
1434
|
+
const started = startTask('relay-push', buildRelayPush(cfg, pushable, pushManifestFile()))
|
|
1435
|
+
if (!started.ok) return { toast: started.error }
|
|
1368
1436
|
return [{ toast: `已开始推送 ${pushable.length} 个插件` }, { refresh: true }]
|
|
1369
1437
|
}
|
|
1370
1438
|
|
|
@@ -1373,14 +1441,16 @@ export function apply(ctx) {
|
|
|
1373
1441
|
if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
|
|
1374
1442
|
const state = stateFor(scope)
|
|
1375
1443
|
state.relayLoadedAt = 0
|
|
1376
|
-
startTask('relay-pull', buildRelayPull(cfg))
|
|
1444
|
+
const started = startTask('relay-pull', buildRelayPull(cfg))
|
|
1445
|
+
if (!started.ok) return { toast: started.error }
|
|
1377
1446
|
return [{ toast: '已开始拉取中转' }, { refresh: true }]
|
|
1378
1447
|
}
|
|
1379
1448
|
|
|
1380
1449
|
const sshTest = (scope) => {
|
|
1381
1450
|
const cfg = loadConfig(ctx, scope)
|
|
1382
1451
|
if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
|
|
1383
|
-
startTask('ssh-test', buildSshTest(cfg))
|
|
1452
|
+
const started = startTask('ssh-test', buildSshTest(cfg))
|
|
1453
|
+
if (!started.ok) return { toast: started.error }
|
|
1384
1454
|
return [{ toast: '正在测试 SSH' }, { refresh: true }]
|
|
1385
1455
|
}
|
|
1386
1456
|
|
|
@@ -1389,7 +1459,8 @@ export function apply(ctx) {
|
|
|
1389
1459
|
if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
|
|
1390
1460
|
const state = stateFor(scope)
|
|
1391
1461
|
state.sshLoadedAt = 0
|
|
1392
|
-
startTask('ssh-scan', buildSshScan(cfg))
|
|
1462
|
+
const started = startTask('ssh-scan', buildSshScan(cfg))
|
|
1463
|
+
if (!started.ok) return { toast: started.error }
|
|
1393
1464
|
return [{ toast: '正在拉远端清单' }, { refresh: true }]
|
|
1394
1465
|
}
|
|
1395
1466
|
|
|
@@ -1405,7 +1476,8 @@ export function apply(ctx) {
|
|
|
1405
1476
|
if (jobs.some((row) => row.action === 'push' || row.action === 'pull') && !cfg.ssh.host) {
|
|
1406
1477
|
return { toast: '先配置 ssh.host' }
|
|
1407
1478
|
}
|
|
1408
|
-
startTask('apply', buildApply(cfg, jobs))
|
|
1479
|
+
const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
|
|
1480
|
+
if (!started.ok) return { toast: started.error }
|
|
1409
1481
|
return [{ toast: `重试 ${jobs.length} 项` }, { refresh: true }]
|
|
1410
1482
|
}
|
|
1411
1483
|
|
|
@@ -1530,7 +1602,8 @@ export function apply(ctx) {
|
|
|
1530
1602
|
if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
|
|
1531
1603
|
return { toast: '推/拉远端要先配置 ssh.host' }
|
|
1532
1604
|
}
|
|
1533
|
-
startTask('apply', buildApply(cfg, jobs))
|
|
1605
|
+
const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
|
|
1606
|
+
if (!started.ok) return { toast: started.error }
|
|
1534
1607
|
state.selected.clear()
|
|
1535
1608
|
return [{ toast: `已开始处理 ${jobs.length} 项` }, { refresh: true }]
|
|
1536
1609
|
},
|
|
@@ -1600,16 +1673,6 @@ export function apply(ctx) {
|
|
|
1600
1673
|
if (rejection !== undefined) { res.writeHead(rejection); res.end(); return }
|
|
1601
1674
|
const url = new URL(req.url || '/', 'http://dsh.local')
|
|
1602
1675
|
const path = url.pathname.replace(/\/+$/, '') || '/'
|
|
1603
|
-
if (url.pathname === '/local-plugin-sync' || url.pathname.startsWith('/local-plugin-sync/')) {
|
|
1604
|
-
res.writeHead(302, { location: `/dsh-go-plugin-sync${url.pathname.slice('/local-plugin-sync'.length)}${url.search || ''}` })
|
|
1605
|
-
res.end()
|
|
1606
|
-
return
|
|
1607
|
-
}
|
|
1608
|
-
if (req.method === 'GET' && (path === '/dsh-go-plugin-sync' || url.pathname === '/dsh-go-plugin-sync/')) {
|
|
1609
|
-
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
|
|
1610
|
-
res.end(webPageHtml())
|
|
1611
|
-
return
|
|
1612
|
-
}
|
|
1613
1676
|
if (req.method === 'GET' && path === '/dsh-go-plugin-sync/api/state') {
|
|
1614
1677
|
webJson(res, 200, webSnapshot(ctx))
|
|
1615
1678
|
return
|
|
@@ -1618,6 +1681,22 @@ export function apply(ctx) {
|
|
|
1618
1681
|
webJson(res, 200, { task: readTaskStatus(), results: readTaskResults() })
|
|
1619
1682
|
return
|
|
1620
1683
|
}
|
|
1684
|
+
if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/config') {
|
|
1685
|
+
const body = JSON.parse((await webReadBody(req)) || '{}')
|
|
1686
|
+
const next = normalizeConfig(body.config || {})
|
|
1687
|
+
const scope = { sessionId: 'web-ui' }
|
|
1688
|
+
const target = configPathFor(ctx, scope)
|
|
1689
|
+
try {
|
|
1690
|
+
ensureStore()
|
|
1691
|
+
mkdirSync(dirname(target), { recursive: true })
|
|
1692
|
+
writeFileSync(target, JSON.stringify(next, null, 2) + '\n')
|
|
1693
|
+
} catch {
|
|
1694
|
+
webJson(res, 200, { error: '保存配置失败' })
|
|
1695
|
+
return
|
|
1696
|
+
}
|
|
1697
|
+
webJson(res, 200, { ok: true, config: next, path: target })
|
|
1698
|
+
return
|
|
1699
|
+
}
|
|
1621
1700
|
if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/export') {
|
|
1622
1701
|
const body = JSON.parse((await webReadBody(req)) || '{}')
|
|
1623
1702
|
const names = Array.isArray(body.names) ? body.names.filter((n) => typeof n === 'string') : []
|
|
@@ -1649,7 +1728,9 @@ export function apply(ctx) {
|
|
|
1649
1728
|
if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
|
|
1650
1729
|
webJson(res, 200, { error: '先配置 ssh.host' }); return
|
|
1651
1730
|
}
|
|
1652
|
-
startTask('apply', buildApply(cfg, jobs))
|
|
1731
|
+
const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
|
|
1732
|
+
if (!started.ok) { webJson(res, 200, { error: started.error }); return }
|
|
1733
|
+
state.selected.clear()
|
|
1653
1734
|
webJson(res, 200, { ok: true, count: jobs.length })
|
|
1654
1735
|
return
|
|
1655
1736
|
}
|
|
@@ -1665,7 +1746,7 @@ export function apply(ctx) {
|
|
|
1665
1746
|
const host = String(ws.host || '127.0.0.1')
|
|
1666
1747
|
const shown = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host
|
|
1667
1748
|
const bracketed = shown.includes(':') ? `[${shown}]` : shown
|
|
1668
|
-
console.log(`[dsh-go-plugin-sync]
|
|
1749
|
+
console.log(`[dsh-go-plugin-sync] 设置页 API:${ws.protocol || 'http:'}//${bracketed}:${ws.port}/dsh-go-plugin-sync/api/`)
|
|
1669
1750
|
} catch {}
|
|
1670
1751
|
})
|
|
1671
1752
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-go-plugin-sync",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"dsh": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"platform": "web",
|
|
12
12
|
"immediately": true,
|
|
13
13
|
"inject": [
|
|
14
|
-
"@deepseek-ai/dsh-client-ui-
|
|
14
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
15
15
|
]
|
|
16
16
|
}
|
|
17
17
|
},
|