dsh-config-sync-plugin 0.4.11 → 0.4.13
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/README.en.md +17 -0
- package/README.md +17 -0
- package/index.js +171 -7
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -257,6 +257,23 @@ Two display fixes on top of 0.3.77:
|
|
|
257
257
|
|
|
258
258
|
The "Plugin update" card now shows an **npm download URL** line with the actual fallback addresses (domestic mirror `registry.npmmirror.com` + official `registry.npmjs.org`). When the GitHub release download is unreachable (common in mainland China), the update package automatically falls back to npm. It is still verified against the authoritative sha256 in `version.json` — switching source never relaxes verification. The two sources back each other up: the mirror can briefly 404 during its first-sync window, and the official source takes over. The npm tarball is byte-identical to the GitHub release tgz (same sha256).
|
|
259
259
|
|
|
260
|
+
### Fix npm fallback download sha256 mismatch (0.4.13)
|
|
261
|
+
|
|
262
|
+
This release fixes the npm fallback download failures introduced in v0.4.12:
|
|
263
|
+
|
|
264
|
+
- **Root cause**: `version.json` only recorded the GitHub release asset's sha256, but npm tarballs (npmmirror + official registry) are different build artifacts with different hashes. When GitHub release was unreachable and the download fell back to npm, it still used the GitHub sha256 for verification, causing all fallback downloads to fail.
|
|
265
|
+
- **Fix**: `version.json` adds an `npmSha256` field recording the npm tarball hash; download logic adds `isNpmRegistryUrl()` and `pickSha256ForUrl()` to automatically pick the correct hash by URL source (GitHub release uses `sha256`, npm registry uses `npmSha256`). GitHub release unreachable cases now correctly fall back to npm and pass verification.
|
|
266
|
+
|
|
267
|
+
### Content-level pending detection: only prompt to push when content actually changed (0.4.12)
|
|
268
|
+
|
|
269
|
+
This release changes the "pending push" rule from a timestamp check to a content-level check, fixing false positives without altering the normal push/pull flow:
|
|
270
|
+
|
|
271
|
+
- **No more mtime-only false changes**: DSH rewrites of `cordis.patch.yml`, session `projcache` / `session-index` that only touch timestamps without changing content are no longer reported as pending.
|
|
272
|
+
- **Content-fingerprint baseline + `pendingKeys`**: a content fingerprint is used as the baseline for real changes, and `pendingKeys` prevents the two sides from whitewashing each other with identical content.
|
|
273
|
+
- **No db/sqlite misses**: db/sqlite files up to 64MB use full hashing so same-size in-place updates are not missed by size/mtime-only checks.
|
|
274
|
+
- **Criteria aligned**: `autoPush` and close-time push use the same new rule, instead of one using content and the other timestamps.
|
|
275
|
+
- **Verification**: two rounds of isolated review found no blocking issues, and `selftest` had no new failures.
|
|
276
|
+
|
|
260
277
|
### Code cleanup and consistency fixes: equivalent refactor, no feature change (0.4.11)
|
|
261
278
|
|
|
262
279
|
This release is an equivalent refactor. The normal sync path is identical to 0.4.10 and no user-visible feature changes:
|
package/README.md
CHANGED
|
@@ -277,6 +277,23 @@ pwsh -File runtime\sync.ps1 pull `
|
|
|
277
277
|
|
|
278
278
|
「插件更新」卡新增一行 **npm 下载路径**,直接显示实际兜底地址(国内镜像 `registry.npmmirror.com` + 官方 `registry.npmjs.org` 两个源)。GitHub release 整段不通时(国内常见),更新包会自动兜底从 npm 下载;仍按 `version.json` 里的权威 sha256 校验,换源不放宽校验。两个源互为备份:镜像首发同步窗口期会短暂 404,官方源随即兜上。实测 npm tarball 与 GitHub release tgz 是同一份产物、sha256 完全一致。
|
|
279
279
|
|
|
280
|
+
### 修复 npm 兜底下载 sha256 校验不一致(0.4.13)
|
|
281
|
+
|
|
282
|
+
本版解决 v0.4.12 引入的 npm 兜底下载全部失败问题:
|
|
283
|
+
|
|
284
|
+
- **根因**:`version.json` 只记录 GitHub release asset 的 sha256,但 npm tarball(npmmirror + 官方 registry)打包产物不同,哈希不一致。GitHub release 不通时回退到 npm,仍用 GitHub 的 sha256 校验,导致全部失败。
|
|
285
|
+
- **修复**:`version.json` 新增 `npmSha256` 字段记录 npm tarball 哈希;下载逻辑新增 `isNpmRegistryUrl()` 与 `pickSha256ForUrl()`,按 URL 来源自动选对应哈希(GitHub release 用 `sha256`、npm registry 用 `npmSha256`)。GitHub release 不通时可正常走 npm 兜底下载并通过校验。
|
|
286
|
+
|
|
287
|
+
### 待推送判据改为内容级:实际内容变了才提示推送(0.4.12)
|
|
288
|
+
|
|
289
|
+
本版把「待推送」从时间戳判据改为内容级判据,只修误报、不改变正常推送/拉取流程:
|
|
290
|
+
|
|
291
|
+
- **消除 mtime 假变更**:DSH 重写 `cordis.patch.yml`、会话 `projcache` / `session-index` 时只改时间戳不改内容,不再被判为待推送。
|
|
292
|
+
- **内容指纹基线 + `pendingKeys`**:以内容指纹为基线识别真正变化,`pendingKeys` 防止双方同内容互相洗白。
|
|
293
|
+
- **db/sqlite 不漏检**:≤64MB 的 db/sqlite 走全量 hash,避免同尺寸原地更新只看大小/mtime 时漏检。
|
|
294
|
+
- **判据同步**:`autoPush` 与退出推送使用同一套新口径,不再一边按内容、一边按时间戳。
|
|
295
|
+
- **验证**:隔离审查两轮无阻断项,`selftest` 无新增失败。
|
|
296
|
+
|
|
280
297
|
### 代码整理与一致性修复:等价重构,功能不变(0.4.11)
|
|
281
298
|
|
|
282
299
|
本版是一次等价重构,正常同步路径与 0.4.10 完全一致,不改变任何用户可见功能:
|
package/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import { createHash } from 'node:crypto'
|
|
|
22
22
|
import { createRequire } from 'node:module'
|
|
23
23
|
import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, readFileSync, readSync, rmSync, statSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
24
24
|
import { homedir, hostname, tmpdir } from 'node:os'
|
|
25
|
-
import { basename, dirname, isAbsolute, join, relative } from 'node:path'
|
|
25
|
+
import { basename, dirname, extname, isAbsolute, join, relative } from 'node:path'
|
|
26
26
|
import { fileURLToPath } from 'node:url'
|
|
27
27
|
// 0.3.76:会话投影缓存守卫(agent-busy 自动清缓存,让缓存按日志重建)
|
|
28
28
|
import { runGuard, clearSessionCaches, appendGuardLog } from './runtime/tools/session-cache-guard.mjs'
|
|
@@ -2035,8 +2035,8 @@ function sessionTitleOf(dshHome, sessionId) {
|
|
|
2035
2035
|
}
|
|
2036
2036
|
|
|
2037
2037
|
/**
|
|
2038
|
-
* 本机 DSH
|
|
2039
|
-
*
|
|
2038
|
+
* 本机 DSH 数据里「上次同步之后内容真正变了」的文件有多少个。
|
|
2039
|
+
* 先用 mtime 快筛,再对 mtime 变过的文件比内容指纹(**不跑 capture**,那要复制整个工作区,几 GB)。
|
|
2040
2040
|
* 代价控制:跳过 node_modules / models / .git 等,最多 20000 个文件、最多 1.5 秒。
|
|
2041
2041
|
*
|
|
2042
2042
|
* 为什么要补一层内容比对:`profile\cordis.patch.yml` 这类文件 **DSH 每次启动都会重写**
|
|
@@ -2073,6 +2073,14 @@ function localPending(dshHome, lastSyncAt, profileName, ctx = {}) {
|
|
|
2073
2073
|
mirrored.set(join(profile, f), join(repoRoot, 'profile', f))
|
|
2074
2074
|
}
|
|
2075
2075
|
}
|
|
2076
|
+
// 非镜像文件的基线(会话记录 / skills / mnemon / 工作区 …)由本插件维护在本机,
|
|
2077
|
+
// 记录上次同步时刻的指纹;lastSyncAt 没变时用它判断 mtime 变化是否只是一次无内容重写。
|
|
2078
|
+
// 基线文件缺失或 lastSyncAt 对不上时先按 mtime-only 计,完整扫描结束后重建基线。
|
|
2079
|
+
// pendingKeys:建基线那一刻就已经 pending 的文件。它们后续即使指纹与基线相同也继续计入,
|
|
2080
|
+
// 防止「升级后首次 inspect 建基线 → 刷新一次就把真改动洗白」;直到 lastSyncAt 前进
|
|
2081
|
+
// (真正完成一次同步)重建基线才清除。
|
|
2082
|
+
const contentBaseline = readContentBaseline(dshHome, since)
|
|
2083
|
+
const baselineValid = Boolean(contentBaseline.lastSyncAt)
|
|
2076
2084
|
const deadline = Date.now() + 1500
|
|
2077
2085
|
let scanned = 0
|
|
2078
2086
|
let pending = 0
|
|
@@ -2081,6 +2089,11 @@ function localPending(dshHome, lastSyncAt, profileName, ctx = {}) {
|
|
|
2081
2089
|
const groupCount = new Map()
|
|
2082
2090
|
// 每组保留具体明细名称(会话记录名 / 本机 profile 文件名 …),供面板展开查看
|
|
2083
2091
|
const groupItems = new Map()
|
|
2092
|
+
// 基线失效(lastSyncAt 前进/首次)时,扫描到的当前内容就是新基准;完整扫描后一次性重建
|
|
2093
|
+
const rebuild = !baselineValid ? {} : null
|
|
2094
|
+
// 重建时记录「建基线这一刻就已经 pending」的文件 key,随基线一起落盘(兼容旧基线缺省 [])
|
|
2095
|
+
const rebuildPendingKeys = new Set()
|
|
2096
|
+
const baselinePendingKeys = new Set(Array.isArray(contentBaseline.pendingKeys) ? contentBaseline.pendingKeys : [])
|
|
2084
2097
|
const DETAIL_CAP = 50
|
|
2085
2098
|
while (stack.length && scanned < 20000 && Date.now() < deadline) {
|
|
2086
2099
|
const cur = stack.pop()
|
|
@@ -2094,14 +2107,26 @@ function localPending(dshHome, lastSyncAt, profileName, ctx = {}) {
|
|
|
2094
2107
|
continue
|
|
2095
2108
|
}
|
|
2096
2109
|
scanned++
|
|
2110
|
+
const key = contentKey(cur)
|
|
2111
|
+
const twin = mirrored.get(cur)
|
|
2112
|
+
let fp = null
|
|
2113
|
+
// 基线有效时只为 mtime>since 的文件算指纹(判定内容是否真变);重建时为所有扫描到的文件算。
|
|
2114
|
+
if (rebuild || st.mtimeMs > since) {
|
|
2115
|
+
try { fp = contentFingerprint(cur, ctx.appRoot) } catch { }
|
|
2116
|
+
}
|
|
2117
|
+
if (rebuild && fp) rebuild[key] = fp
|
|
2097
2118
|
if (st.mtimeMs > since) {
|
|
2098
2119
|
// 镜像文件的 mtime 更新可能只是宿主重写占位符:内容归一后一致就不算待推送
|
|
2099
|
-
const twin = mirrored.get(cur)
|
|
2100
2120
|
if (twin && isFile(twin)) {
|
|
2101
2121
|
try {
|
|
2102
2122
|
if (mirrorText(cur, ctx.appRoot) === mirrorText(twin, ctx.appRoot)) continue
|
|
2103
2123
|
} catch { }
|
|
2104
2124
|
}
|
|
2125
|
+
// 非镜像文件:mtime 更新后再跟「上次同步时刻的指纹」比,真正变了才算待推送。
|
|
2126
|
+
// DSH 宿主会重写会话 projcache / session-index 等文件的时间戳,字节没变时指纹相同 → 不报。
|
|
2127
|
+
// 但建基线时已经 pending 的文件(pendingKeys)不能靠「指纹==基线」洗白,必须持续计入。
|
|
2128
|
+
if (!twin && baselineValid && fp && contentBaseline.files[key] === fp && !baselinePendingKeys.has(key)) continue
|
|
2129
|
+
if (rebuild && !twin) rebuildPendingKeys.add(key)
|
|
2105
2130
|
pending++
|
|
2106
2131
|
if (st.mtimeMs > newest) newest = st.mtimeMs
|
|
2107
2132
|
const gid = pendingGroupOf(cur, dshHome, profile, workspacePaths)
|
|
@@ -2123,6 +2148,13 @@ function localPending(dshHome, lastSyncAt, profileName, ctx = {}) {
|
|
|
2123
2148
|
if (items.length < DETAIL_CAP && !items.includes(label)) items.push(label)
|
|
2124
2149
|
}
|
|
2125
2150
|
}
|
|
2151
|
+
const truncated = scanned >= 20000 || Date.now() >= deadline
|
|
2152
|
+
// 只有「基线缺失/过期 + 本次完整扫描」才重建:此时磁盘内容就是 lastSyncAt 那次同步的内容。
|
|
2153
|
+
// 基线有效时绝不更新——否则一直没同步的真实改动会被下一次面板刷新「洗白」成基线。
|
|
2154
|
+
if (rebuild && !truncated) {
|
|
2155
|
+
const fresh = { path: join(dshHome, CONTENT_BASELINE_NAME), lastSyncAt: since, complete: true, files: rebuild, pendingKeys: [...rebuildPendingKeys] }
|
|
2156
|
+
writeContentBaseline(fresh, since)
|
|
2157
|
+
}
|
|
2126
2158
|
const groups = [...groupCount.entries()]
|
|
2127
2159
|
.map(([id, count]) => ({
|
|
2128
2160
|
id,
|
|
@@ -2155,6 +2187,126 @@ function mirrorText(file, appRoot) {
|
|
|
2155
2187
|
return text
|
|
2156
2188
|
}
|
|
2157
2189
|
|
|
2190
|
+
// ---- 内容级 pending:DSH 重写 mtime 但字节没变的文件不再误报 ----
|
|
2191
|
+
// 基线由后端自己维护在 <dshHome>\.config-sync-content-baseline.json,不依赖 capture/ps1 配合。
|
|
2192
|
+
// 基线记录「上次同步时刻(lastSyncAt)」各文件的指纹;只要 lastSyncAt 没变就不更新,
|
|
2193
|
+
// 于是 mtime 被 DSH 重写但内容没变的文件(会话 projcache / session-index 等)能被识别并跳过,
|
|
2194
|
+
// 真内容变化则指纹不同继续计入 pending,直到下一次同步(lastSyncAt 变化)才重建基线。
|
|
2195
|
+
// pendingKeys 记录建基线那刻已 pending 的文件:首次建基线时真改动会被基线收录,若不额外记住,
|
|
2196
|
+
// 刷新一次就会因「指纹==基线」被洗白;这些 key 持续 pending 到 lastSyncAt 前进重建为止。
|
|
2197
|
+
// 指纹口径:文本统一 CRLF→LF、去尾部空白、把 appRoot 变体还原成 {{APP_ROOT}},再 sha256;
|
|
2198
|
+
// .db/.sqlite 家族全量分块 sha256(原地页更新,size 不变但内容可变);其他二进制(.zstd/.png/…)
|
|
2199
|
+
// 按 size + 头/中/尾采样 sha256,绝不做 UTF8 解码。
|
|
2200
|
+
const CONTENT_BASELINE_NAME = '.config-sync-content-baseline.json'
|
|
2201
|
+
const CONTENT_SAMPLE_BYTES = 262144 // 单文件最多读 256KB:几个 MB 的会话 zstd 也只读头/中/尾三段
|
|
2202
|
+
|
|
2203
|
+
function isTextContentFile(file) {
|
|
2204
|
+
const ext = extname(file).toLowerCase()
|
|
2205
|
+
if (!ext) return true // AGENTS.md 类的无扩展名文本 / README
|
|
2206
|
+
return ['.md', '.txt', '.json', '.jsonl', '.yml', '.yaml', '.ps1', '.mjs', '.js', '.ts', '.toml', '.ini', '.csv'].includes(ext)
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
function normalizeForContentHash(text, appRoot) {
|
|
2210
|
+
let s = String(text).replace(/\r\n/g, '\n').replace(/\s+$/, '')
|
|
2211
|
+
const root = String(appRoot || '').replace(/[\\/]+$/, '')
|
|
2212
|
+
if (root) {
|
|
2213
|
+
for (const variant of new Set([root, root.replace(/\\/g, '/'), root.replace(/\//g, '\\')])) {
|
|
2214
|
+
if (variant) s = s.split(variant).join('{{APP_ROOT}}')
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
return s
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
/** 原地同尺寸更新型文件(SQLite 页覆盖):头/中/尾采样会漏检中间页改动,需全量 hash。 */
|
|
2221
|
+
function isInPlaceUpdateFile(file) {
|
|
2222
|
+
return ['.db', '.sqlite', '.sqlite3', '.mdb', '.accdb', '.realm'].includes(extname(file).toLowerCase())
|
|
2223
|
+
}
|
|
2224
|
+
const CONTENT_FULL_HASH_CAP = 67108864 // 64MB:超过则退回采样,避免单个巨型 db 吃掉 1.5s 扫描预算
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* 内容指纹:小文本(<=256KB)归一后 sha256;db/sqlite 家族全量分块 sha256;
|
|
2228
|
+
* 其余大文件/二进制按 size + 头/中/尾字节采样 sha256。
|
|
2229
|
+
* 会话日志 zstd、未压缩的大 jsonl 都走采样分支,绝不做 UTF8 解码。
|
|
2230
|
+
*/
|
|
2231
|
+
function contentFingerprint(file, appRoot) {
|
|
2232
|
+
const st = statSync(file)
|
|
2233
|
+
const h = createHash('sha256')
|
|
2234
|
+
h.update(`size:${st.size}\n`)
|
|
2235
|
+
if (isTextContentFile(file) && st.size <= CONTENT_SAMPLE_BYTES) {
|
|
2236
|
+
h.update(normalizeForContentHash(readFileSync(file, 'utf8'), appRoot))
|
|
2237
|
+
} else if (isInPlaceUpdateFile(file) && st.size <= CONTENT_FULL_HASH_CAP) {
|
|
2238
|
+
// SQLite / db 是页级原地覆盖:size 不变但中间页可能已改,全量分块读,避免采样漏检。
|
|
2239
|
+
const fd = openSync(file, 'r')
|
|
2240
|
+
try {
|
|
2241
|
+
const buf = Buffer.allocUnsafe(65536)
|
|
2242
|
+
let off = 0
|
|
2243
|
+
let n
|
|
2244
|
+
while ((n = readSync(fd, buf, 0, buf.length, off)) > 0) {
|
|
2245
|
+
h.update(n === buf.length ? buf : buf.subarray(0, n))
|
|
2246
|
+
off += n
|
|
2247
|
+
}
|
|
2248
|
+
} finally { closeSync(fd) }
|
|
2249
|
+
} else {
|
|
2250
|
+
const fd = openSync(file, 'r')
|
|
2251
|
+
try {
|
|
2252
|
+
const n = st.size
|
|
2253
|
+
if (n <= CONTENT_SAMPLE_BYTES) {
|
|
2254
|
+
const buf = Buffer.allocUnsafe(n)
|
|
2255
|
+
let off = 0
|
|
2256
|
+
while (off < n) off += readSync(fd, buf, off, Math.min(65536, n - off), off)
|
|
2257
|
+
h.update(buf)
|
|
2258
|
+
} else {
|
|
2259
|
+
// 大文件:头 128KB + 中 16KB + 尾 128KB,覆盖 zstd 帧头/checksum 与末尾事件
|
|
2260
|
+
const CHUNK = 131072
|
|
2261
|
+
const buf = Buffer.allocUnsafe(CHUNK)
|
|
2262
|
+
let off = 0
|
|
2263
|
+
while (off < CHUNK) off += readSync(fd, buf, off, Math.min(65536, CHUNK - off), off)
|
|
2264
|
+
h.update(buf)
|
|
2265
|
+
const mid = Buffer.allocUnsafe(16384)
|
|
2266
|
+
off = 0
|
|
2267
|
+
const midPos = Math.floor((n - 16384) / 2)
|
|
2268
|
+
while (off < mid.length) off += readSync(fd, mid, off, Math.min(8192, mid.length - off), midPos + off)
|
|
2269
|
+
h.update(mid)
|
|
2270
|
+
const tail = Buffer.allocUnsafe(CHUNK)
|
|
2271
|
+
off = 0
|
|
2272
|
+
while (off < tail.length) off += readSync(fd, tail, off, Math.min(65536, tail.length - off), n - CHUNK + off)
|
|
2273
|
+
h.update(tail)
|
|
2274
|
+
}
|
|
2275
|
+
} finally { closeSync(fd) }
|
|
2276
|
+
}
|
|
2277
|
+
return h.digest('hex')
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
/**
|
|
2281
|
+
* 读取本机内容基线:{ lastSyncAt, files: { "<本机绝对路径(正斜杠)>": "<sha256>" }, pendingKeys: [...] }。
|
|
2282
|
+
* 只有记录的 lastSyncAt 与当前一致才有效;lastSyncAt 变化(完成一次同步)后视为过期,
|
|
2283
|
+
* 由 localPending 在扫描结束后重写基线,不依赖任何 ps1。
|
|
2284
|
+
* 旧基线(无 pendingKeys 字段)兼容为 []。
|
|
2285
|
+
*/
|
|
2286
|
+
function readContentBaseline(dshHome, since) {
|
|
2287
|
+
const p = join(dshHome, CONTENT_BASELINE_NAME)
|
|
2288
|
+
try {
|
|
2289
|
+
const parsed = JSON.parse(readFileSync(p, 'utf8'))
|
|
2290
|
+
// complete 必须是上一次完整扫描写出的;超时/超限的半截基线不采纳,下次重建。
|
|
2291
|
+
if (parsed && parsed.complete === true && parsed.lastSyncAt === since && parsed.files && typeof parsed.files === 'object' && !Array.isArray(parsed.files)) {
|
|
2292
|
+
return { path: p, lastSyncAt: parsed.lastSyncAt, complete: true, files: parsed.files, pendingKeys: Array.isArray(parsed.pendingKeys) ? parsed.pendingKeys : [] }
|
|
2293
|
+
}
|
|
2294
|
+
} catch { }
|
|
2295
|
+
return { path: p, lastSyncAt: '', complete: false, files: {}, pendingKeys: [] }
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
/** 把本次完整扫描到的指纹写回基线(含扫描到的所有文件,不只 mtime 变的那批)。 */
|
|
2299
|
+
function writeContentBaseline(baseline, since) {
|
|
2300
|
+
try {
|
|
2301
|
+
writeFileSync(baseline.path, JSON.stringify({ lastSyncAt: since, complete: true, at: Date.now(), files: baseline.files, pendingKeys: Array.isArray(baseline.pendingKeys) ? baseline.pendingKeys : [] }, null, 2) + '\n', 'utf8')
|
|
2302
|
+
} catch { /* 写不了就下次全量重建,功能不降级 */ }
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
/** 本机绝对路径(统一正斜杠、去尾斜杠)作为基线 key,避免 capture 侧会话目录 remap 造成键不匹配。 */
|
|
2306
|
+
function contentKey(file) {
|
|
2307
|
+
return String(file).replace(/\\/g, '/').replace(/\/+$/, '')
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2158
2310
|
async function repoState(repo) {
|
|
2159
2311
|
if (!repo || !isDir(join(repo, '.git'))) return { ahead: 0, dirty: 0 }
|
|
2160
2312
|
const status = await git(repo, ['status', '--porcelain'])
|
|
@@ -2426,6 +2578,17 @@ function npmTgzUrls(version) {
|
|
|
2426
2578
|
`https://registry.npmjs.org/dsh-config-sync-plugin/-/${f}`,
|
|
2427
2579
|
]
|
|
2428
2580
|
}
|
|
2581
|
+
|
|
2582
|
+
/** 判断 URL 是否为 npm registry 源(需用 npmSha256 校验) */
|
|
2583
|
+
function isNpmRegistryUrl(url) {
|
|
2584
|
+
const u = String(url || '')
|
|
2585
|
+
return u.includes('registry.npmmirror.com') || u.includes('registry.npmjs.org')
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/** 根据 URL 选择对应的 sha256:npm 源用 npmSha256,GitHub release 用 sha256 */
|
|
2589
|
+
function pickSha256ForUrl(url, githubSha256, npmSha256) {
|
|
2590
|
+
return isNpmRegistryUrl(url) ? (npmSha256 || githubSha256) : githubSha256
|
|
2591
|
+
}
|
|
2429
2592
|
// 兼容旧调用:返回首选 npm 兜底地址
|
|
2430
2593
|
function npmTgzUrl(version) {
|
|
2431
2594
|
const list = npmTgzUrls(version)
|
|
@@ -2623,16 +2786,17 @@ function updatePayload(state, settings = {}) {
|
|
|
2623
2786
|
* 候选地址逐个试(raw 常常不通,反代在前面兜着),全失败时把每个源的原因汇总抛出。
|
|
2624
2787
|
* 返回 { ok, file, size, sha256, url } 或 { ok:false, error }
|
|
2625
2788
|
*/
|
|
2626
|
-
async function downloadPackage({ urls, sha256, version, dshHome }) {
|
|
2789
|
+
async function downloadPackage({ urls, sha256, npmSha256, version, dshHome }) {
|
|
2627
2790
|
if (typeof fetch !== 'function') return { ok: false, error: t('当前运行环境没有 fetch,无法下载更新包', 'fetch is unavailable in this runtime — cannot download the update package') }
|
|
2628
2791
|
const dir = join(dshHome, 'update-staging')
|
|
2629
2792
|
try { mkdirSync(dir, { recursive: true }) } catch { }
|
|
2630
2793
|
const file = join(dir, `dsh-config-sync-plugin-${version}.tgz`)
|
|
2631
|
-
const want = String(sha256 || '').toLowerCase()
|
|
2632
2794
|
const errors = []
|
|
2633
2795
|
for (const rawUrl of urls) {
|
|
2634
2796
|
const url = String(rawUrl || '').trim()
|
|
2635
2797
|
if (!url) continue
|
|
2798
|
+
// 根据 URL 来源选择对应的 sha256:npm 源用 npmSha256,GitHub release 用 sha256
|
|
2799
|
+
const want = String(pickSha256ForUrl(url, sha256, npmSha256) || '').toLowerCase()
|
|
2636
2800
|
try {
|
|
2637
2801
|
const ctrl = typeof AbortController === 'function' ? new AbortController() : null
|
|
2638
2802
|
const timer = ctrl ? setTimeout(() => { try { ctrl.abort() } catch { } }, 120 * 1000) : null
|
|
@@ -2747,7 +2911,7 @@ async function handleUpdate(req, res, config) {
|
|
|
2747
2911
|
}
|
|
2748
2912
|
const urls = resolveTgzCandidates(remote, state.url)
|
|
2749
2913
|
if (!urls.length) throw new Error(t('version.json 里没有给 tgz 下载地址', 'version.json gives no tgz download URL'))
|
|
2750
|
-
const got = await downloadPackage({ urls, sha256: String(remote.sha256 || ''), version: String(remote.version), dshHome })
|
|
2914
|
+
const got = await downloadPackage({ urls, sha256: String(remote.sha256 || ''), npmSha256: String(remote.npmSha256 || ''), version: String(remote.version), dshHome })
|
|
2751
2915
|
if (!got.ok) throw new Error(String(got.error || t('下载失败', 'download failed')))
|
|
2752
2916
|
updateState.prepared = {
|
|
2753
2917
|
version: String(remote.version),
|
package/package.json
CHANGED