dsh-go-plugin-sync 0.3.2 → 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,21 @@
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
+
3
19
  ## 0.3.2 — 2026-12-04
4
20
 
5
21
  - 修复 README 里的网页地址:实际路径是 `/dsh-go-plugin-sync/`;旧的 `/local-plugin-sync/` 自动跳转
package/README.md CHANGED
@@ -62,6 +62,8 @@ http://<DSH 地址>:<端口>/dsh-go-plugin-sync/
62
62
 
63
63
  如果页面返回 401:用已经登录 DSH 的同一个浏览器打开;如果返回 404:确认插件已启用并重启过 DSH。
64
64
 
65
+ Windows 上网页版的同步码发送、导入和「安装选中」都可用;安装任务由 Node 直接执行,不依赖 `/bin/sh`。Git 中转和 SSH 推/拉暂不支持 Windows。
66
+
65
67
  注意:电脑上装完插件后同样要重启一次 DSH。
66
68
 
67
69
  ## 只增不删
@@ -107,6 +109,7 @@ http://<DSH 地址>:<端口>/dsh-go-plugin-sync/
107
109
  - Cordis 插件可能依赖 DSH 版本或平台,装不上会进失败清单
108
110
  - 不同步插件的启用状态和插件配置
109
111
  - 首次两端都要手动安装本插件
112
+ - Windows 只支持同步码安装;Git 中转和 SSH 暂不支持
110
113
 
111
114
  ## 安全
112
115
 
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')
@@ -1298,7 +1425,7 @@ li.item .name{font-weight:600}li.item .meta{margin-left:auto;font-size:12px;opac
1298
1425
  <div id="results"></div>
1299
1426
  <script>
1300
1427
  (function(){
1301
- var localSelected=new Set(), diffSelected=new Set(), current={};
1428
+ var localSelected=new Set(), diffSelected=new Set(), current={}, lastKey=null, wasRunning=false;
1302
1429
  function el(t,c,x){var n=document.createElement(t);if(c)n.className=c;if(x!=null)n.textContent=x;return n}
1303
1430
  (function(){var a=document.getElementById('addr');if(a)a.textContent='地址:'+location.origin+'/dsh-go-plugin-sync/'})();
1304
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()})}
@@ -1307,13 +1434,14 @@ function renderPlugins(list){var ul=document.getElementById('plugins');ul.textCo
1307
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)})}
1308
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:'')))})}
1309
1436
  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(){})}
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(){})}
1312
1440
  document.getElementById('all').onclick=function(){(current.plugins||[]).forEach(function(p){localSelected.add(p.name)});renderPlugins(current.plugins)};
1313
1441
  document.getElementById('none').onclick=function(){localSelected.clear();renderPlugins(current.plugins)};
1314
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')})};
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()})};
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()})};
1317
1445
  refresh();setInterval(poll,3000);
1318
1446
  })();
1319
1447
  </script>
@@ -1355,7 +1483,7 @@ export function apply(ctx) {
1355
1483
  const cfg = loadConfig(ctx, scope)
1356
1484
  if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
1357
1485
  const local = localPlugins()
1358
- const pushable = local.filter((plugin) => plugin.relDir && SAFE_DIR.test(plugin.relDir))
1486
+ const pushable = local.filter((plugin) => safeDirName(plugin.relDir))
1359
1487
  if (pushable.length === 0) return { toast: '本机没有可推送的插件' }
1360
1488
  const manifest = buildManifest(local)
1361
1489
  try {
@@ -1364,7 +1492,8 @@ export function apply(ctx) {
1364
1492
  } catch {
1365
1493
  return { toast: '写清单失败' }
1366
1494
  }
1367
- 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 }
1368
1497
  return [{ toast: `已开始推送 ${pushable.length} 个插件` }, { refresh: true }]
1369
1498
  }
1370
1499
 
@@ -1373,14 +1502,16 @@ export function apply(ctx) {
1373
1502
  if (!cfg.relay.repo) return { toast: '先配置中转仓 relay.repo' }
1374
1503
  const state = stateFor(scope)
1375
1504
  state.relayLoadedAt = 0
1376
- startTask('relay-pull', buildRelayPull(cfg))
1505
+ const started = startTask('relay-pull', buildRelayPull(cfg))
1506
+ if (!started.ok) return { toast: started.error }
1377
1507
  return [{ toast: '已开始拉取中转' }, { refresh: true }]
1378
1508
  }
1379
1509
 
1380
1510
  const sshTest = (scope) => {
1381
1511
  const cfg = loadConfig(ctx, scope)
1382
1512
  if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
1383
- startTask('ssh-test', buildSshTest(cfg))
1513
+ const started = startTask('ssh-test', buildSshTest(cfg))
1514
+ if (!started.ok) return { toast: started.error }
1384
1515
  return [{ toast: '正在测试 SSH' }, { refresh: true }]
1385
1516
  }
1386
1517
 
@@ -1389,7 +1520,8 @@ export function apply(ctx) {
1389
1520
  if (!cfg.ssh.host) return { toast: '先配置 ssh.host' }
1390
1521
  const state = stateFor(scope)
1391
1522
  state.sshLoadedAt = 0
1392
- startTask('ssh-scan', buildSshScan(cfg))
1523
+ const started = startTask('ssh-scan', buildSshScan(cfg))
1524
+ if (!started.ok) return { toast: started.error }
1393
1525
  return [{ toast: '正在拉远端清单' }, { refresh: true }]
1394
1526
  }
1395
1527
 
@@ -1405,7 +1537,8 @@ export function apply(ctx) {
1405
1537
  if (jobs.some((row) => row.action === 'push' || row.action === 'pull') && !cfg.ssh.host) {
1406
1538
  return { toast: '先配置 ssh.host' }
1407
1539
  }
1408
- startTask('apply', buildApply(cfg, jobs))
1540
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1541
+ if (!started.ok) return { toast: started.error }
1409
1542
  return [{ toast: `重试 ${jobs.length} 项` }, { refresh: true }]
1410
1543
  }
1411
1544
 
@@ -1530,7 +1663,8 @@ export function apply(ctx) {
1530
1663
  if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1531
1664
  return { toast: '推/拉远端要先配置 ssh.host' }
1532
1665
  }
1533
- startTask('apply', buildApply(cfg, jobs))
1666
+ const started = startTask('apply', buildApply(cfg, jobs), winTask(jobs))
1667
+ if (!started.ok) return { toast: started.error }
1534
1668
  state.selected.clear()
1535
1669
  return [{ toast: `已开始处理 ${jobs.length} 项` }, { refresh: true }]
1536
1670
  },
@@ -1649,7 +1783,9 @@ export function apply(ctx) {
1649
1783
  if (jobs.some((job) => job.action === 'push' || job.action === 'pull') && !cfg.ssh.host) {
1650
1784
  webJson(res, 200, { error: '先配置 ssh.host' }); return
1651
1785
  }
1652
- 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()
1653
1789
  webJson(res, 200, { ok: true, count: jobs.length })
1654
1790
  return
1655
1791
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-go-plugin-sync",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "dsh": {