dsh-go-plugin-sync 0.4.6 → 0.4.7
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 +14 -0
- package/lib/client.js +1 -1
- package/lib/index.js +70 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.8 — 2026-12-05
|
|
4
|
+
|
|
5
|
+
### 改进
|
|
6
|
+
- 同步码改用 v3 紧凑数组编码:每个插件按固定顺序打包成数组,不再重复存字段名;实测同数据 1184→1108 字符,约省 6.5%。旧 v2 同步码仍可正常导入,双向互导不受影响
|
|
7
|
+
- 同步码长度上限从 2000 提到 6000(保留文件预算 5800),dsh-go 面板输入框同步放开;贪婪实测 22 个插件约 1107 字符、50 个约 1452、100 个约 1929、300 个约 3735,能覆盖更大规模的插件清单
|
|
8
|
+
- 解码端插件数量上限从 200 提到 1000,配合更长的同步码;体积超限仍会明确提示「同步码太大」,不会静默截断
|
|
9
|
+
|
|
10
|
+
## 0.4.7 — 2026-12-05
|
|
11
|
+
|
|
12
|
+
### 改进
|
|
13
|
+
- 放宽 kind 判定:电脑/网页端声明的 bundle 插件在 dsh-go 端不再被强制标成「仅电脑/网页」而无法选择,改为可尝试安装,是否生效以实际运行为准
|
|
14
|
+
- 同步码新增 `from` 字段(dshgo / web),记录来源端;旧同步码无此字段仍可正常导入
|
|
15
|
+
- 双端增加中性文案提示:来自另一端的插件标注「来自另一端,可尝试安装」,不再用绝对化的「仅电脑/网页」字样
|
|
16
|
+
|
|
3
17
|
## 0.4.6 — 2026-12-05
|
|
4
18
|
|
|
5
19
|
### 文档
|
package/lib/client.js
CHANGED
|
@@ -277,7 +277,7 @@ window.__ModuleLoader__.load({
|
|
|
277
277
|
|
|
278
278
|
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
|
|
279
279
|
h('div', { style: { fontSize: '13px', opacity: 0.7 } },
|
|
280
|
-
T('从同步码安装缺少的插件;已有版本不动,冲突以本机为准,更新交给 DSH
|
|
280
|
+
T('从同步码安装缺少的插件;已有版本不动,冲突以本机为准,更新交给 DSH 本体。标为来自另一端的插件也能尝试安装,是否生效以实际运行为准。', 'Install missing plugins from a sync code; conflicts keep the local copy and updates are left to DSH. Plugins marked as from the other end can still be tried; whether they work depends on the host.')),
|
|
281
281
|
|
|
282
282
|
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
283
283
|
h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
|
package/lib/index.js
CHANGED
|
@@ -30,7 +30,9 @@ const MANIFEST_V = 1
|
|
|
30
30
|
const MANIFEST_FILE = 'plugin-sync-manifest.json'
|
|
31
31
|
const CONFIG_FILE = 'plugin-sync-config.json'
|
|
32
32
|
const CODE_PREFIX = 'DSHSYNC1:'
|
|
33
|
-
const CODE_BUDGET =
|
|
33
|
+
const CODE_BUDGET = 5800
|
|
34
|
+
const CODE_MAX = 6000
|
|
35
|
+
const MAX_SYNC_PLUGINS = 1000
|
|
34
36
|
const TEXT_EXT = new Set(['.js', '.mjs', '.cjs', '.json', '.yml', '.yaml', '.md', '.txt', '.css', '.html', '.svg', '.ts'])
|
|
35
37
|
const REL_RE = /^[A-Za-z0-9._@-]+(?:\/[A-Za-z0-9._@-]+)*$/
|
|
36
38
|
const PKG_NAME = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/i
|
|
@@ -156,8 +158,31 @@ function encodeSyncPayload(payload) {
|
|
|
156
158
|
return CODE_PREFIX + deflateRawSync(Buffer.from(JSON.stringify(payload), 'utf8')).toString('base64url')
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
/** v3 packs each plugin as a fixed-order array so repeated object keys are not stored. */
|
|
162
|
+
function packPluginEntry(entry) {
|
|
163
|
+
const packed = [
|
|
164
|
+
entry.name,
|
|
165
|
+
entry.version,
|
|
166
|
+
entry.hash,
|
|
167
|
+
entry.relDir,
|
|
168
|
+
entry.depSpec,
|
|
169
|
+
entry.kind,
|
|
170
|
+
entry.files && Object.keys(entry.files).length ? entry.files : undefined,
|
|
171
|
+
]
|
|
172
|
+
while (packed.length && (packed[packed.length - 1] === undefined || packed[packed.length - 1] === null)) packed.pop()
|
|
173
|
+
return packed
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function unpackPluginEntry(raw) {
|
|
177
|
+
if (Array.isArray(raw)) {
|
|
178
|
+
const [name, version, hash, relDir, depSpec, kind, files] = raw
|
|
179
|
+
return { name, version, hash, relDir, depSpec, kind, files: files || {} }
|
|
180
|
+
}
|
|
181
|
+
return raw
|
|
182
|
+
}
|
|
183
|
+
|
|
159
184
|
/** Compact sync code: manifest + (when it fits) text files of local plugins. */
|
|
160
|
-
function buildSyncCode(plugins) {
|
|
185
|
+
function buildSyncCode(plugins, host = {}) {
|
|
161
186
|
const entries = plugins
|
|
162
187
|
.filter((plugin) => plugin.name !== name)
|
|
163
188
|
.map((plugin) => ({
|
|
@@ -172,18 +197,16 @@ function buildSyncCode(plugins) {
|
|
|
172
197
|
: {},
|
|
173
198
|
}))
|
|
174
199
|
if (entries.length === 0) return { error: 'empty' }
|
|
175
|
-
|
|
176
|
-
|
|
200
|
+
const from = host.dshGo === true ? 'dshgo' : 'web'
|
|
201
|
+
const at = new Date().toISOString()
|
|
202
|
+
const payload = (list) => ({ v: 3, t: 'dsh-go-plugin-sync', from, at, plugins: list.map(packPluginEntry) })
|
|
203
|
+
let code = encodeSyncPayload(payload(entries))
|
|
204
|
+
let withFiles = entries.filter((entry) => Object.keys(entry.files || {}).length > 0).length
|
|
177
205
|
if (code.length > CODE_BUDGET) {
|
|
178
|
-
code = encodeSyncPayload({
|
|
179
|
-
v: 2,
|
|
180
|
-
t: 'dsh-go-plugin-sync',
|
|
181
|
-
at: new Date().toISOString(),
|
|
182
|
-
plugins: entries.map(({ files, ...rest }) => rest),
|
|
183
|
-
})
|
|
206
|
+
code = encodeSyncPayload(payload(entries.map(({ files, ...rest }) => rest)))
|
|
184
207
|
withFiles = 0
|
|
185
208
|
}
|
|
186
|
-
if (code.length >
|
|
209
|
+
if (code.length > CODE_MAX) return { error: 'too-large' }
|
|
187
210
|
return { code, plugins: entries.length, withFiles }
|
|
188
211
|
}
|
|
189
212
|
|
|
@@ -198,9 +221,10 @@ function decodeSyncCode(text) {
|
|
|
198
221
|
} catch {
|
|
199
222
|
return { error: '同步码损坏或过大' }
|
|
200
223
|
}
|
|
201
|
-
if (!doc || doc.v !== 2 || doc.t !== 'dsh-go-plugin-sync' || !Array.isArray(doc.plugins)) return { error: '同步码版本不对' }
|
|
224
|
+
if (!doc || (doc.v !== 2 && doc.v !== 3) || doc.t !== 'dsh-go-plugin-sync' || !Array.isArray(doc.plugins)) return { error: '同步码版本不对' }
|
|
202
225
|
const plugins = []
|
|
203
|
-
for (const
|
|
226
|
+
for (const packed of doc.plugins.slice(0, MAX_SYNC_PLUGINS)) {
|
|
227
|
+
const raw = unpackPluginEntry(packed)
|
|
204
228
|
if (!raw || typeof raw.name !== 'string' || !safeName(raw.name)) continue
|
|
205
229
|
const relDir = safeDirName(raw.relDir) ? raw.relDir : null
|
|
206
230
|
const files = {}
|
|
@@ -221,13 +245,15 @@ function decodeSyncCode(text) {
|
|
|
221
245
|
})
|
|
222
246
|
}
|
|
223
247
|
if (plugins.length === 0) return { error: '同步码里没有可同步插件' }
|
|
248
|
+
const from = doc.from === 'dshgo' || doc.from === 'web' ? doc.from : null
|
|
224
249
|
return {
|
|
250
|
+
from,
|
|
225
251
|
plugins,
|
|
226
252
|
manifest: {
|
|
227
253
|
v: MANIFEST_V,
|
|
228
254
|
generator: 'dsh-go-plugin-sync',
|
|
229
255
|
exportedAt: typeof doc.at === 'string' ? doc.at : null,
|
|
230
|
-
host: { profile: 'sync-code' },
|
|
256
|
+
host: { profile: 'sync-code', from },
|
|
231
257
|
plugins: plugins.map(({ files, ...rest }) => rest),
|
|
232
258
|
},
|
|
233
259
|
}
|
|
@@ -273,7 +299,7 @@ function applySyncCode(scope, text, sourceName, host = {}) {
|
|
|
273
299
|
if (decoded.error) return { error: decoded.error }
|
|
274
300
|
const state = stateFor(scope)
|
|
275
301
|
state.manifest = decoded.manifest
|
|
276
|
-
state.manifestSource = { kind: 'code' }
|
|
302
|
+
state.manifestSource = { kind: 'code', from: decoded.from }
|
|
277
303
|
state.importedAt = new Date().toISOString()
|
|
278
304
|
state.sourceName = sourceName
|
|
279
305
|
state.showAll = false
|
|
@@ -543,8 +569,12 @@ function diffRows(local, manifest, source, host = {}) {
|
|
|
543
569
|
const here = localByName.get(remote.name)
|
|
544
570
|
const remoteDir = remote.relDir || remote.name
|
|
545
571
|
const kind = remote.kind || here?.kind || null
|
|
572
|
+
// A bundle plugin may work on the dsh-go host too; don't hard-block it as web-only.
|
|
573
|
+
// Keep a neutral hint instead so the user can try it manually.
|
|
574
|
+
const from = source?.from || null
|
|
575
|
+
const crossEnd = nativeHost && kind === 'bundle' && from !== 'dshgo'
|
|
546
576
|
if (!nativeHost && kind === 'native') {
|
|
547
|
-
rows.push({ name: remote.name, version: remote.version, remoteVersion: remote.version, status: 'native-only', action: null, kind })
|
|
577
|
+
rows.push({ name: remote.name, version: remote.version, remoteVersion: remote.version, status: 'native-only', action: null, kind, from })
|
|
548
578
|
continue
|
|
549
579
|
}
|
|
550
580
|
if (!here) {
|
|
@@ -573,9 +603,11 @@ function diffRows(local, manifest, source, host = {}) {
|
|
|
573
603
|
name: remote.name,
|
|
574
604
|
version: remote.version,
|
|
575
605
|
remoteVersion: remote.version,
|
|
576
|
-
status: action ?
|
|
606
|
+
status: action ? 'installable' : 'missing',
|
|
577
607
|
action,
|
|
578
608
|
kind,
|
|
609
|
+
from,
|
|
610
|
+
crossEnd,
|
|
579
611
|
localDir,
|
|
580
612
|
registrySpec,
|
|
581
613
|
dirName: remoteDir,
|
|
@@ -584,11 +616,11 @@ function diffRows(local, manifest, source, host = {}) {
|
|
|
584
616
|
}
|
|
585
617
|
const same = (!remote.hash || !here.hash || remote.hash === here.hash) && remote.version === here.version
|
|
586
618
|
if (!same) {
|
|
587
|
-
rows.push({ name: here.name, version: here.version, remoteVersion: remote.version, status: 'conflict', action: null, kind })
|
|
619
|
+
rows.push({ name: here.name, version: here.version, remoteVersion: remote.version, status: 'conflict', action: null, kind, from, crossEnd })
|
|
588
620
|
} else if (!here.installed) {
|
|
589
|
-
rows.push({ name: here.name, version: here.version, status:
|
|
621
|
+
rows.push({ name: here.name, version: here.version, status: 'install', action: 'install', kind, from, crossEnd, localDir: here.dir })
|
|
590
622
|
} else {
|
|
591
|
-
rows.push({ name: here.name, version: here.version, status: 'same', action: null, kind })
|
|
623
|
+
rows.push({ name: here.name, version: here.version, status: 'same', action: null, kind, from, crossEnd })
|
|
592
624
|
}
|
|
593
625
|
}
|
|
594
626
|
for (const here of local) {
|
|
@@ -1424,6 +1456,14 @@ function enableText(caps) {
|
|
|
1424
1456
|
return String(caps?.locale || '').toLowerCase().startsWith('en')
|
|
1425
1457
|
}
|
|
1426
1458
|
|
|
1459
|
+
// Neutral hint for plugins declared for one end but appearing on the other.
|
|
1460
|
+
// Not a hard block: the user may still try to install it.
|
|
1461
|
+
function crossEndHint(row, en) {
|
|
1462
|
+
if (!row.crossEnd) return ''
|
|
1463
|
+
if (en) return ' · from other end, may still work'
|
|
1464
|
+
return ' · 来自另一端,可尝试安装'
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1427
1467
|
function statusLine(row, en) {
|
|
1428
1468
|
let text = {
|
|
1429
1469
|
same: en ? 'already here' : '本地已有',
|
|
@@ -1445,7 +1485,7 @@ function statusLine(row, en) {
|
|
|
1445
1485
|
const version = row.status === 'conflict' && row.remoteVersion && row.remoteVersion !== row.version
|
|
1446
1486
|
? `${row.version} → ${row.remoteVersion}`
|
|
1447
1487
|
: row.version
|
|
1448
|
-
return `${version} · ${text}`
|
|
1488
|
+
return `${version} · ${text}${crossEndHint(row, en)}`
|
|
1449
1489
|
}
|
|
1450
1490
|
|
|
1451
1491
|
const STATUS_BRIEF = {
|
|
@@ -1462,7 +1502,8 @@ const STATUS_BRIEF = {
|
|
|
1462
1502
|
|
|
1463
1503
|
function statusBrief(row, en) {
|
|
1464
1504
|
const pair = STATUS_BRIEF[row.status]
|
|
1465
|
-
|
|
1505
|
+
const base = pair ? pair[en ? 1 : 0] : row.status
|
|
1506
|
+
return base + crossEndHint(row, en)
|
|
1466
1507
|
}
|
|
1467
1508
|
|
|
1468
1509
|
function statusTone(status) {
|
|
@@ -1496,8 +1537,8 @@ function buildView(scope, caps, ctx) {
|
|
|
1496
1537
|
const children = []
|
|
1497
1538
|
|
|
1498
1539
|
children.push({ type: 'text', text: en
|
|
1499
|
-
? 'Copy a sync code (all or selected), or paste one below. Sync only installs missing plugins; conflicts keep the local copy, updates are left to DSH.'
|
|
1500
|
-
: '复制同步码(全部或选中),或在下面粘贴导入。同步只安装缺少的插件,已有版本不动;冲突以本机为准,更新交给 DSH
|
|
1540
|
+
? 'Copy a sync code (all or selected), or paste one below. Sync only installs missing plugins; conflicts keep the local copy, updates are left to DSH. Plugins marked as from the other end can still be tried.'
|
|
1541
|
+
: '复制同步码(全部或选中),或在下面粘贴导入。同步只安装缺少的插件,已有版本不动;冲突以本机为准,更新交给 DSH 本体。标为来自另一端的插件也能尝试安装,是否生效以实际运行为准。' })
|
|
1501
1542
|
|
|
1502
1543
|
if (canForm) {
|
|
1503
1544
|
children.push({ type: 'form', submit: 'import-code', submitLabel: en ? 'Import code' : '导入同步码', children: [
|
|
@@ -1507,7 +1548,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1507
1548
|
bind: 'data.paste.code',
|
|
1508
1549
|
multiline: true,
|
|
1509
1550
|
maxLines: 8,
|
|
1510
|
-
maxLength:
|
|
1551
|
+
maxLength: CODE_MAX,
|
|
1511
1552
|
placeholder: en ? 'Paste DSHSYNC1:… here' : '在这里粘贴 DSHSYNC1: 开头的同步码',
|
|
1512
1553
|
},
|
|
1513
1554
|
] })
|
|
@@ -1791,6 +1832,8 @@ function webSnapshot(ctx) {
|
|
|
1791
1832
|
status: row.status,
|
|
1792
1833
|
action: row.action || null,
|
|
1793
1834
|
kind: row.kind || null,
|
|
1835
|
+
crossEnd: Boolean(row.crossEnd),
|
|
1836
|
+
from: row.from || null,
|
|
1794
1837
|
subtitle: statusLine(row, false),
|
|
1795
1838
|
})),
|
|
1796
1839
|
cleared,
|
|
@@ -1841,7 +1884,7 @@ export function apply(ctx) {
|
|
|
1841
1884
|
const chosen = state.selected.size > 0
|
|
1842
1885
|
? all.filter((plugin) => state.selected.has(plugin.name))
|
|
1843
1886
|
: all
|
|
1844
|
-
const result = buildSyncCode(chosen)
|
|
1887
|
+
const result = buildSyncCode(chosen, { dshGo: true })
|
|
1845
1888
|
if (result.error === 'empty') return { toast: '除本插件外没有其他插件' }
|
|
1846
1889
|
if (result.error) return { toast: '同步码太大,改用导出清单' }
|
|
1847
1890
|
const label = state.selected.size > 0 ? '已复制选中' : '已复制全部'
|
|
@@ -2340,7 +2383,7 @@ export function apply(ctx) {
|
|
|
2340
2383
|
const names = Array.isArray(body.names) ? body.names.filter((n) => typeof n === 'string') : []
|
|
2341
2384
|
const all = localPlugins()
|
|
2342
2385
|
const chosen = names.length > 0 ? all.filter((plugin) => names.includes(plugin.name)) : all
|
|
2343
|
-
const result = buildSyncCode(chosen)
|
|
2386
|
+
const result = buildSyncCode(chosen, { dshGo: Boolean(ctx.get?.('dshGo')) })
|
|
2344
2387
|
if (result.error === 'empty') { webJson(res, 200, { error: '没有可同步的插件' }); return }
|
|
2345
2388
|
if (result.error) { webJson(res, 200, { error: '同步码太大,请减少插件或改用中转' }); return }
|
|
2346
2389
|
webJson(res, 200, { code: result.code, count: result.plugins, withFiles: result.withFiles })
|