dsh-go-plugin-sync 0.3.1 → 0.3.3

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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.3 — 2026-12-04
4
+
5
+ ### 修复
6
+ - **Windows**:「安装选中」恢复可用;安装任务改由 Node 直接执行,不再依赖 `/bin/sh`
7
+ - **Windows**:Git 中转 / SSH 不再假装开始,直接提示当前平台不支持
8
+ - **清单校验**:`relDir` 只接受插件根目录下的单级目录名,拒绝绝对路径和 `.`/`..`
9
+ - **网页版**:刷新或任务完成后不再重置用户勾选;应用后清空已选项
10
+ - **网页版**:有任务在运行时拒绝再次提交,避免并发任务互相覆盖
11
+ - **空同步码** / 全部条目无效的同步码按错误处理,不再显示“已导入 0 个”
12
+ - 同步码解压限制 2 MB,异常压缩包不再拖垮引擎
13
+ - 任务日志里的插件名做安全转义,避免特殊名称破坏任务脚本
14
+
15
+ ### 说明
16
+ - Git 中转和 SSH 推/拉仍只在 Linux / macOS 上工作
17
+ - 只增不删的行为不变:冲突、清单外、缺文件仍然只提示
18
+
19
+ ## 0.3.2 — 2026-12-04
20
+
21
+ - 修复 README 里的网页地址:实际路径是 `/dsh-go-plugin-sync/`;旧的 `/local-plugin-sync/` 自动跳转
22
+ - 电脑端插件详情页新增**打开插件同步网页**按钮,直接在浏览器里打开当前 DSH 地址下的同步页
23
+ - 网页顶部显示当前地址;引擎启动日志会打印同步页的完整 URL
24
+ - 网页版不再需要用户自己拼地址和端口
25
+
3
26
  ## 0.3.1 — 2026-12-04
4
27
 
5
28
  - 包名改为 `dsh-go-plugin-sync`,发布到 npm
package/README.md CHANGED
@@ -45,12 +45,14 @@ dsh plugin --profile web add ./dshgochajiantongbucha
45
45
 
46
46
  ## 网页版(电脑)
47
47
 
48
- 电脑上的 DSH Web 可以直接打开内置同步页面,不需要 dsh-go 桥接:
48
+ 电脑上的 DSH Web 可以直接打开内置同步页面,不需要 dsh-go 桥接。装好插件并重启 DSH 后,打开**插件**页,进入「插件同步」详情,点标题旁的**打开插件同步网页**,会在浏览器新标签页打开:
49
49
 
50
50
  ```text
51
- http://<DSH 地址>:<端口>/local-plugin-sync/
51
+ http://<DSH 地址>:<端口>/dsh-go-plugin-sync/
52
52
  ```
53
53
 
54
+ 地址就是当前 DSH Web 的地址和端口(例如 `http://127.0.0.1:3080/dsh-go-plugin-sync/`)。旧地址 `/local-plugin-sync/` 会自动跳转过来。
55
+
54
56
  页面提供和手机端一样的发送/接收:
55
57
 
56
58
  1. 勾选要同步的插件,点**复制同步码**
@@ -58,6 +60,10 @@ http://<DSH 地址>:<端口>/local-plugin-sync/
58
60
  3. 默认选中同步码里的插件,可以取消;点**安装选中**
59
61
  4. 页面下方显示任务状态和逐项结果
60
62
 
63
+ 如果页面返回 401:用已经登录 DSH 的同一个浏览器打开;如果返回 404:确认插件已启用并重启过 DSH。
64
+
65
+ Windows 上网页版的同步码发送、导入和「安装选中」都可用;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
66
+
61
67
  注意:电脑上装完插件后同样要重启一次 DSH。
62
68
 
63
69
  ## 只增不删
@@ -103,6 +109,7 @@ http://<DSH 地址>:<端口>/local-plugin-sync/
103
109
  - Cordis 插件可能依赖 DSH 版本或平台,装不上会进失败清单
104
110
  - 不同步插件的启用状态和插件配置
105
111
  - 首次两端都要手动安装本插件
112
+ - Windows 只支持同步码安装;Git 中转和 SSH 暂不支持
106
113
 
107
114
  ## 安全
108
115
 
package/lib/client.js ADDED
@@ -0,0 +1,56 @@
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-go-plugin-sync',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const PKG = 'dsh-go-plugin-sync'
7
+ const BUTTON = {
8
+ padding: '5px 12px',
9
+ borderRadius: '6px',
10
+ border: '1px solid rgba(128,128,128,.35)',
11
+ background: 'transparent',
12
+ color: 'inherit',
13
+ font: 'inherit',
14
+ fontSize: '13px',
15
+ cursor: 'pointer',
16
+ }
17
+
18
+ const isOurs = (subject) => Boolean(
19
+ subject
20
+ && (subject.kind === 'bundle' || subject.kind === 'row')
21
+ && subject.pkg
22
+ && subject.pkg.name === PKG,
23
+ )
24
+
25
+ function syncUrl() {
26
+ const url = new URL('/dsh-go-plugin-sync/', window.location.href)
27
+ url.search = window.location.search || ''
28
+ url.hash = window.location.hash || ''
29
+ return url.href
30
+ }
31
+
32
+ function OpenSync(props) {
33
+ if (!isOurs(props && props.subject)) return null
34
+ const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
35
+ return h('button', {
36
+ type: 'button',
37
+ title: syncUrl(),
38
+ style: BUTTON,
39
+ onClick() {
40
+ window.open(syncUrl(), '_blank', 'noopener')
41
+ },
42
+ }, zh ? '打开插件同步网页' : 'Open plugin sync page')
43
+ }
44
+
45
+ return {
46
+ inject: ['slots'],
47
+ apply(ctx) {
48
+ ctx.slots.inject('plugins.detail.actions', () => ctx.slots.register({
49
+ name: 'plugins.detail.actions',
50
+ id: 'dsh-go-plugin-sync-open',
51
+ order: 100,
52
+ }, OpenSync))
53
+ },
54
+ }
55
+ },
56
+ })
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: plugin.relDir && SAFE_DIR.test(plugin.relDir) && existsSync(plugin.dir)
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(trimmed.slice(CODE_PREFIX.length), 'base64url')).toString('utf8'))
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 = typeof raw.relDir === 'string' && SAFE_DIR.test(raw.relDir) ? raw.relDir : null
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: typeof raw.relDir === 'string' && !raw.relDir.includes('..') ? raw.relDir : null,
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 startTask(kind, lines) {
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 (!plugin.relDir || !SAFE_DIR.test(plugin.relDir)) continue
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')
@@ -1274,6 +1401,7 @@ li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opac
1274
1401
  </head>
1275
1402
  <body>
1276
1403
  <h1>插件同步</h1>
1404
+ <div id="addr" class="muted"></div>
1277
1405
  <div class="muted">复制同步码到另一台主机导入;只安装缺少的插件,不卸载、不覆盖。</div>
1278
1406
  <div id="config" class="muted"></div>
1279
1407
 
@@ -1297,21 +1425,23 @@ li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opac
1297
1425
  <div id="results"></div>
1298
1426
  <script>
1299
1427
  (function(){
1300
- var localSelected=new Set(), diffSelected=new Set(), current={};
1428
+ var localSelected=new Set(), diffSelected=new Set(), current={}, lastKey=null, wasRunning=false;
1301
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/'})();
1302
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()})}
1303
1432
  function setStatus(t,c){var n=document.getElementById('status');n.textContent=t;n.className='status'+(c?' '+c:'')}
1304
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)})}
1305
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)})}
1306
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:'')))})}
1307
1436
  function renderTask(t){if(!t){setStatus('就绪');return}if(t.running){setStatus('正在执行…');return}setStatus(t.ok===false?('上次失败 '+t.failed+' 项'):'上次完成',t.ok===false?'bad':'good')}
1308
- 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?'已配置':'未配置')})}
1309
- 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(){})}
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(){})}
1310
1440
  document.getElementById('all').onclick=function(){(current.plugins||[]).forEach(function(p){localSelected.add(p.name)});renderPlugins(current.plugins)};
1311
1441
  document.getElementById('none').onclick=function(){localSelected.clear();renderPlugins(current.plugins)};
1312
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')})};
1313
- 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()})};
1314
- 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()})};
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()})};
1315
1445
  refresh();setInterval(poll,3000);
1316
1446
  })();
1317
1447
  </script>
@@ -1353,7 +1483,7 @@ export function apply(ctx) {
1353
1483
  const cfg = loadConfig(ctx, scope)
1354
1484
  if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
1355
1485
  const local = localPlugins()
1356
- const pushable = local.filter((plugin) => plugin.relDir && SAFE_DIR.test(plugin.relDir))
1486
+ const pushable = local.filter((plugin) => safeDirName(plugin.relDir))
1357
1487
  if (pushable.length === 0) return { toast: '本机没有可推送的插件' }
1358
1488
  const manifest = buildManifest(local)
1359
1489
  try {
@@ -1362,7 +1492,8 @@ export function apply(ctx) {
1362
1492
  } catch {
1363
1493
  return { toast: '写清单失败' }
1364
1494
  }
1365
- startTask('relay-push', buildRelayPush(cfg, pushable, pushManifestFile()))
1495
+ const started = startTask('relay-push', buildRelayPush(cfg, pushable, pushManifestFile()))
1496
+ if (!started.ok) return { toast: started.error }
1366
1497
  return [{ toast: `已开始推送 ${pushable.length} 个插件` }, { refresh: true }]
1367
1498
  }
1368
1499
 
@@ -1371,14 +1502,16 @@ export function apply(ctx) {
1371
1502
  if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
1372
1503
  const state = stateFor(scope)
1373
1504
  state.relayLoadedAt = 0
1374
- startTask('relay-pull', buildRelayPull(cfg))
1505
+ const started = startTask('relay-pull', buildRelayPull(cfg))
1506
+ if (!started.ok) return { toast: started.error }
1375
1507
  return [{ toast: '已开始拉取中转' }, { refresh: true }]
1376
1508
  }
1377
1509
 
1378
1510
  const sshTest = (scope) => {
1379
1511
  const cfg = loadConfig(ctx, scope)
1380
1512
  if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
1381
- startTask('ssh-test', buildSshTest(cfg))
1513
+ const started = startTask('ssh-test', buildSshTest(cfg))
1514
+ if (!started.ok) return { toast: started.error }
1382
1515
  return [{ toast: '正在测试 SSH' }, { refresh: true }]
1383
1516
  }
1384
1517
 
@@ -1387,7 +1520,8 @@ export function apply(ctx) {
1387
1520
  if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
1388
1521
  const state = stateFor(scope)
1389
1522
  state.sshLoadedAt = 0
1390
- startTask('ssh-scan', buildSshScan(cfg))
1523
+ const started = startTask('ssh-scan', buildSshScan(cfg))
1524
+ if (!started.ok) return { toast: started.error }
1391
1525
  return [{ toast: '正在拉远端清单' }, { refresh: true }]
1392
1526
  }
1393
1527
 
@@ -1403,7 +1537,8 @@ export function apply(ctx) {
1403
1537
  if (jobs.some((row) => row.action === 'push' || row.action === 'pull') && !cfg.ssh.host) {
1404
1538
  return { toast: '先配置 ssh.host' }
1405
1539
  }
1406
- startTask('apply', buildApply(cfg, jobs))
1540
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1541
+ if (!started.ok) return { toast: started.error }
1407
1542
  return [{ toast: `重试 ${jobs.length} 项` }, { refresh: true }]
1408
1543
  }
1409
1544
 
@@ -1528,7 +1663,8 @@ export function apply(ctx) {
1528
1663
  if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1529
1664
  return { toast: '推/拉远端要先配置 ssh.host' }
1530
1665
  }
1531
- startTask('apply', buildApply(cfg, jobs))
1666
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1667
+ if (!started.ok) return { toast: started.error }
1532
1668
  state.selected.clear()
1533
1669
  return [{ toast: `已开始处理 ${jobs.length} 项` }, { refresh: true }]
1534
1670
  },
@@ -1598,6 +1734,11 @@ export function apply(ctx) {
1598
1734
  if (rejection !== undefined) { res.writeHead(rejection); res.end(); return }
1599
1735
  const url = new URL(req.url || '/', 'http://dsh.local')
1600
1736
  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
+ }
1601
1742
  if (req.method === 'GET' && (path === '/dsh-go-plugin-sync' || url.pathname === '/dsh-go-plugin-sync/')) {
1602
1743
  res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
1603
1744
  res.end(webPageHtml())
@@ -1642,7 +1783,9 @@ export function apply(ctx) {
1642
1783
  if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1643
1784
  webJson(res, 200, { error: '先配置 ssh.host' }); return
1644
1785
  }
1645
- startTask('apply', buildApply(cfg, jobs))
1786
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1787
+ if (!started.ok) { webJson(res, 200, { error: started.error }); return }
1788
+ state.selected.clear()
1646
1789
  webJson(res, 200, { ok: true, count: jobs.length })
1647
1790
  return
1648
1791
  }
@@ -1653,5 +1796,12 @@ export function apply(ctx) {
1653
1796
  }
1654
1797
  }
1655
1798
  ctx.effect(() => webCtx.webServer.register({ kind: 'prefix', path: '/dsh-go-plugin-sync', handler }), 'dsh-go-plugin-sync: web ui')
1799
+ try {
1800
+ const ws = webCtx.webServer
1801
+ const host = String(ws.host || '127.0.0.1')
1802
+ const shown = host === '0.0.0.0' || host === '::' ? '127.0.0.1' : host
1803
+ const bracketed = shown.includes(':') ? `[${shown}]` : shown
1804
+ console.log(`[dsh-go-plugin-sync] 插件同步网页:${ws.protocol || 'http:'}//${bracketed}:${ws.port}/dsh-go-plugin-sync/`)
1805
+ } catch {}
1656
1806
  })
1657
1807
  }
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "dsh-go-plugin-sync",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {
7
7
  "bundle": {
8
8
  "patch": "./cordis.patch.yml"
9
+ },
10
+ "client": {
11
+ "platform": "web",
12
+ "immediately": true,
13
+ "inject": [
14
+ "@deepseek-ai/dsh-client-ui-plugin-manager"
15
+ ]
9
16
  }
10
17
  },
11
18
  "engines": {
@@ -86,5 +93,10 @@
86
93
  "cordis.patch.yml",
87
94
  "README.md",
88
95
  "CHANGELOG.md"
89
- ]
96
+ ],
97
+ "exports": {
98
+ ".": "./lib/index.js",
99
+ "./client": "./lib/client.js",
100
+ "./package.json": "./package.json"
101
+ }
90
102
  }