dsh-go-plugin-sync 0.3.3 → 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 +10 -0
- package/README.md +8 -17
- package/lib/client.js +191 -30
- package/lib/index.js +27 -82
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 0.3.3 — 2026-12-04
|
|
4
14
|
|
|
5
15
|
### 修复
|
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,26 +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. 页面下方显示任务状态和逐项结果
|
|
62
|
-
|
|
63
|
-
如果页面返回 401:用已经登录 DSH 的同一个浏览器打开;如果返回 404:确认插件已启用并重启过 DSH。
|
|
51
|
+
1. 粘贴同步码,点**导入同步码**
|
|
52
|
+
2. 在插件列表里勾选要安装的项(默认选中同步码里的插件)
|
|
53
|
+
3. 点**安装选中**,下方显示任务状态
|
|
54
|
+
4. 在同一页填写 **Git 中转**(仓库地址 / 分支 / 目录)和 **SSH**(主机 / 端口 / 用户 / 私钥 / profile),点**保存配置**
|
|
64
55
|
|
|
65
|
-
Windows
|
|
56
|
+
Windows 上支持同步码导入和安装;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
|
|
66
57
|
|
|
67
58
|
注意:电脑上装完插件后同样要重启一次 DSH。
|
|
68
59
|
|
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
|
@@ -1373,80 +1373,19 @@ function webSnapshot(ctx) {
|
|
|
1373
1373
|
})),
|
|
1374
1374
|
task: readTaskStatus(),
|
|
1375
1375
|
results: readTaskResults(),
|
|
1376
|
-
config:
|
|
1376
|
+
config: cfg,
|
|
1377
|
+
configPath: configPathFor(ctx, scope),
|
|
1377
1378
|
}
|
|
1378
1379
|
}
|
|
1379
1380
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
:root{color-scheme:light dark}
|
|
1389
|
-
body{font:14px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;padding:16px;max-width:820px;margin-inline:auto}
|
|
1390
|
-
h1{font-size:20px;margin:0 0 4px}h2{font-size:15px;margin:20px 0 8px}
|
|
1391
|
-
.muted{opacity:.65}.row{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0}
|
|
1392
|
-
button{font:inherit;padding:7px 12px;border-radius:8px;border:1px solid #8884;background:#8881;cursor:pointer}
|
|
1393
|
-
button.primary{background:#3D6FD6;border-color:#3D6FD6;color:#fff}
|
|
1394
|
-
button:disabled{opacity:.5;cursor:default}
|
|
1395
|
-
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}
|
|
1396
|
-
ul{list-style:none;padding:0;margin:0}
|
|
1397
|
-
li.item{display:flex;align-items:center;gap:8px;padding:6px 4px;border-bottom:1px solid #8882}
|
|
1398
|
-
li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opacity:.7}
|
|
1399
|
-
.status{font-size:12px;opacity:.8}.bad{color:#c62828}.good{color:#2e7d32}
|
|
1400
|
-
</style>
|
|
1401
|
-
</head>
|
|
1402
|
-
<body>
|
|
1403
|
-
<h1>插件同步</h1>
|
|
1404
|
-
<div id="addr" class="muted"></div>
|
|
1405
|
-
<div class="muted">复制同步码到另一台主机导入;只安装缺少的插件,不卸载、不覆盖。</div>
|
|
1406
|
-
<div id="config" class="muted"></div>
|
|
1407
|
-
|
|
1408
|
-
<h2>发送(本机 → 同步码)</h2>
|
|
1409
|
-
<ul id="plugins"></ul>
|
|
1410
|
-
<div class="row">
|
|
1411
|
-
<button id="all">全选</button>
|
|
1412
|
-
<button id="none">清空</button>
|
|
1413
|
-
<button id="copy" class="primary">复制同步码</button>
|
|
1414
|
-
</div>
|
|
1415
|
-
<textarea id="code" placeholder="生成的同步码会显示在这里" readonly></textarea>
|
|
1416
|
-
|
|
1417
|
-
<h2>接收(同步码 → 本机)</h2>
|
|
1418
|
-
<textarea id="importCode" placeholder="粘贴 DSHSYNC1: 开头的同步码"></textarea>
|
|
1419
|
-
<div class="row"><button id="import" class="primary">导入同步码</button></div>
|
|
1420
|
-
<ul id="diff"></ul>
|
|
1421
|
-
<div class="row"><button id="apply" class="primary">安装选中</button></div>
|
|
1422
|
-
|
|
1423
|
-
<h2>状态</h2>
|
|
1424
|
-
<div id="status" class="status"></div>
|
|
1425
|
-
<div id="results"></div>
|
|
1426
|
-
<script>
|
|
1427
|
-
(function(){
|
|
1428
|
-
var localSelected=new Set(), diffSelected=new Set(), current={}, lastKey=null, wasRunning=false;
|
|
1429
|
-
function el(t,c,x){var n=document.createElement(t);if(c)n.className=c;if(x!=null)n.textContent=x;return n}
|
|
1430
|
-
(function(){var a=document.getElementById('addr');if(a)a.textContent='地址:'+location.origin+'/dsh-go-plugin-sync/'})();
|
|
1431
|
-
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()})}
|
|
1432
|
-
function setStatus(t,c){var n=document.getElementById('status');n.textContent=t;n.className='status'+(c?' '+c:'')}
|
|
1433
|
-
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)})}
|
|
1434
|
-
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)})}
|
|
1435
|
-
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:'')))})}
|
|
1436
|
-
function renderTask(t){if(!t){setStatus('就绪');return}if(t.running){setStatus('正在执行…');return}setStatus(t.ok===false?('上次失败 '+t.failed+' 项'):'上次完成',t.ok===false?'bad':'good')}
|
|
1437
|
-
function manifestKey(s){var m=s&&s.manifest;return (m&&m.exportedAt||'')+'|'+((m&&m.plugins)||[]).map(function(p){return p.name}).join(',')}
|
|
1438
|
-
function refresh(){return api('state').then(function(s){if(s.error){setStatus(s.error,'bad');return}current=s;var key=manifestKey(s);if(key!==lastKey){lastKey=key;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?'已配置':'未配置')})}
|
|
1439
|
-
function poll(){api('status').then(function(s){if(s.task){renderTask(s.task);if(wasRunning&&!s.task.running)refresh();wasRunning=s.task.running}else{wasRunning=false}if(s.results)renderResults(s.results)}).catch(function(){})}
|
|
1440
|
-
document.getElementById('all').onclick=function(){(current.plugins||[]).forEach(function(p){localSelected.add(p.name)});renderPlugins(current.plugins)};
|
|
1441
|
-
document.getElementById('none').onclick=function(){localSelected.clear();renderPlugins(current.plugins)};
|
|
1442
|
-
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')})};
|
|
1443
|
-
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}lastKey=null;setStatus('已导入 '+r.count+' 个插件,选中 '+r.selected+' 个','good');refresh()})};
|
|
1444
|
-
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}names.forEach(function(n){diffSelected.delete(n)});setStatus('已开始安装 '+r.count+' 项','good');refresh()})};
|
|
1445
|
-
refresh();setInterval(poll,3000);
|
|
1446
|
-
})();
|
|
1447
|
-
</script>
|
|
1448
|
-
</body>
|
|
1449
|
-
</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)
|
|
1450
1389
|
}
|
|
1451
1390
|
|
|
1452
1391
|
// ---------------------------------------------------------------- plugin
|
|
@@ -1734,16 +1673,6 @@ export function apply(ctx) {
|
|
|
1734
1673
|
if (rejection !== undefined) { res.writeHead(rejection); res.end(); return }
|
|
1735
1674
|
const url = new URL(req.url || '/', 'http://dsh.local')
|
|
1736
1675
|
const path = url.pathname.replace(/\/+$/, '') || '/'
|
|
1737
|
-
if (url.pathname === '/local-plugin-sync' || url.pathname.startsWith('/local-plugin-sync/')) {
|
|
1738
|
-
res.writeHead(302, { location: `/dsh-go-plugin-sync${url.pathname.slice('/local-plugin-sync'.length)}${url.search || ''}` })
|
|
1739
|
-
res.end()
|
|
1740
|
-
return
|
|
1741
|
-
}
|
|
1742
|
-
if (req.method === 'GET' && (path === '/dsh-go-plugin-sync' || url.pathname === '/dsh-go-plugin-sync/')) {
|
|
1743
|
-
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
|
|
1744
|
-
res.end(webPageHtml())
|
|
1745
|
-
return
|
|
1746
|
-
}
|
|
1747
1676
|
if (req.method === 'GET' && path === '/dsh-go-plugin-sync/api/state') {
|
|
1748
1677
|
webJson(res, 200, webSnapshot(ctx))
|
|
1749
1678
|
return
|
|
@@ -1752,6 +1681,22 @@ export function apply(ctx) {
|
|
|
1752
1681
|
webJson(res, 200, { task: readTaskStatus(), results: readTaskResults() })
|
|
1753
1682
|
return
|
|
1754
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
|
+
}
|
|
1755
1700
|
if (req.method === 'POST' && path === '/dsh-go-plugin-sync/api/export') {
|
|
1756
1701
|
const body = JSON.parse((await webReadBody(req)) || '{}')
|
|
1757
1702
|
const names = Array.isArray(body.names) ? body.names.filter((n) => typeof n === 'string') : []
|
|
@@ -1801,7 +1746,7 @@ export function apply(ctx) {
|
|
|
1801
1746
|
const host = String(ws.host || '127.0.0.1')
|
|
1802
1747
|
const shown = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host
|
|
1803
1748
|
const bracketed = shown.includes(':') ? `[${shown}]` : shown
|
|
1804
|
-
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/`)
|
|
1805
1750
|
} catch {}
|
|
1806
1751
|
})
|
|
1807
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
|
},
|