dsh-config-manager 0.2.4 → 0.3.1
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.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/adapters/self.d.ts +44 -4
- package/lib/adapters/self.js +63 -3
- package/lib/client.d.ts +11 -6
- package/lib/client.js +1254 -1183
- package/lib/core/analyzer.d.ts +3 -0
- package/lib/core/analyzer.js +32 -56
- package/lib/core/backup.d.ts +36 -0
- package/lib/core/backup.js +125 -3
- package/lib/core/import-defaults.d.ts +13 -0
- package/lib/core/import-defaults.js +14 -0
- package/lib/core/importer.d.ts +10 -1
- package/lib/core/importer.js +7 -1
- package/lib/core/messages.d.ts +4 -0
- package/lib/core/messages.js +8 -0
- package/lib/core/model-tools.js +19 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +12 -22
- package/lib/routes/import.js +3 -1
- package/lib/routes/recovery.js +226 -2
- package/lib/routes/sync.js +26 -7
- package/lib/security/integrity.d.ts +24 -0
- package/lib/security/integrity.js +30 -0
- package/lib/security/unverified-file-blocks.d.ts +73 -0
- package/lib/security/unverified-file-blocks.js +151 -0
- package/lib/sync/autosync-config.d.ts +8 -4
- package/lib/sync/autosync-config.js +2 -2
- package/lib/sync/autosync-scheduler.d.ts +61 -3
- package/lib/sync/autosync-scheduler.js +87 -10
- package/lib/sync/config-issue-reporting.d.ts +32 -0
- package/lib/sync/config-issue-reporting.js +63 -0
- package/lib/sync/gc-skip.d.ts +42 -0
- package/lib/sync/gc-skip.js +57 -0
- package/lib/sync/git/git-transport.d.ts +10 -0
- package/lib/sync/git/git-transport.js +72 -14
- package/lib/sync/merge-preview-text.d.ts +11 -0
- package/lib/sync/merge-preview-text.js +38 -0
- package/lib/sync/s3/oss4-verify.js +21 -6
- package/lib/sync/s3/s3-providers.d.ts +13 -0
- package/lib/sync/s3/s3-providers.js +6 -0
- package/lib/sync/s3/s3-transport.d.ts +30 -1
- package/lib/sync/s3/s3-transport.js +108 -23
- package/lib/sync/session-tombstones.d.ts +53 -0
- package/lib/sync/session-tombstones.js +52 -0
- package/lib/sync/sync-config.d.ts +55 -5
- package/lib/sync/sync-config.js +188 -15
- package/lib/sync/sync-engine.d.ts +21 -7
- package/lib/sync/sync-engine.js +63 -85
- package/lib/sync/webdav/webdav-transport.d.ts +11 -1
- package/lib/sync/webdav/webdav-transport.js +22 -6
- package/lib/ui/i18n.js +56 -36
- package/lib/ui/import-wizard.d.ts +1 -1
- package/lib/ui/import-wizard.js +2 -1
- package/lib/ui/overview-view.d.ts +6 -2
- package/lib/ui/overview-view.js +8 -1
- package/lib/ui/report.js +2 -1
- package/package.json +2 -2
- package/src/adapters/self.test.ts +126 -85
- package/src/adapters/self.ts +73 -6
- package/src/client/ConfigManagerSection.tsx +0 -3
- package/src/client/common/Icon.tsx +3 -0
- package/src/client/common/SectionComposition.tsx +6 -1
- package/src/client/common/info-hint-guard.test.ts +7 -5
- package/src/client/config-manager.module.css +254 -13
- package/src/client/environment/EnvironmentPanel.tsx +57 -47
- package/src/client/environment/maintenance/DiskUsageCard.tsx +3 -1
- package/src/client/export/ExportView.tsx +3 -1
- package/src/client/home/HomePanel.tsx +25 -5
- package/src/client/import/ImportWizardView.tsx +1 -3
- package/src/client/import/import-wizard-steps.tsx +1 -17
- package/src/client/library/ArtifactRow.tsx +13 -2
- package/src/client/library/LibraryPanel.tsx +12 -2
- package/src/client/locales.ts +53 -34
- package/src/client/lucide-icons.d.ts +2 -0
- package/src/client/market/MarketPanel.tsx +12 -11
- package/src/client/market/market-locales.ts +16 -16
- package/src/client/recovery/RollbackCard.tsx +4 -2
- package/src/client/recovery/recovery-locales.test.ts +4 -2
- package/src/client/recovery/recovery-locales.ts +23 -23
- package/src/client/sync/AutosyncCard.tsx +36 -10
- package/src/client/sync/SyncChannelEntryCard.tsx +18 -19
- package/src/client/sync/SyncPanel.tsx +32 -33
- package/src/client/sync/SyncProbeRow.tsx +23 -6
- package/src/client/sync/SyncSectionPickerDialog.tsx +2 -2
- package/src/client/sync/sync-locales.ts +24 -24
- package/src/core/analyzer.ts +37 -56
- package/src/core/backup.test.ts +139 -1
- package/src/core/backup.ts +145 -4
- package/src/core/import-defaults.ts +13 -0
- package/src/core/importer.ts +12 -2
- package/src/core/integrity-extra-entries.test.ts +205 -0
- package/src/core/messages.test.ts +3 -1
- package/src/core/messages.ts +8 -0
- package/src/core/model-tools.test.ts +33 -0
- package/src/core/model-tools.ts +20 -4
- package/src/index.ts +12 -21
- package/src/routes/import.ts +4 -1
- package/src/routes/recovery.test.ts +198 -1
- package/src/routes/recovery.ts +194 -1
- package/src/routes/sync.ts +27 -8
- package/src/security/integrity.ts +37 -0
- package/src/security/unverified-file-blocks.ts +192 -0
- package/src/sync/autosync-config.ts +9 -5
- package/src/sync/autosync-scheduler.test.ts +133 -6
- package/src/sync/autosync-scheduler.ts +118 -14
- package/src/sync/config-issue-reporting.test.ts +148 -0
- package/src/sync/config-issue-reporting.ts +75 -0
- package/src/sync/gc-skip.test.ts +66 -0
- package/src/sync/gc-skip.ts +64 -0
- package/src/sync/git/git-probe.test.ts +3 -2
- package/src/sync/git/git-transport.test.ts +168 -7
- package/src/sync/git/git-transport.ts +70 -14
- package/src/sync/merge-preview-text.ts +37 -0
- package/src/sync/s3/oss4-verify.ts +22 -6
- package/src/sync/s3/s3-conditional-write.test.ts +153 -3
- package/src/sync/s3/s3-delete-index-404.test.ts +26 -1
- package/src/sync/s3/s3-providers.ts +20 -0
- package/src/sync/s3/s3-transport.oss4-server.test.ts +48 -0
- package/src/sync/s3/s3-transport.ts +121 -21
- package/src/sync/session-tombstones.ts +90 -0
- package/src/sync/sync-config.test.ts +170 -1
- package/src/sync/sync-config.ts +184 -14
- package/src/sync/sync-engine.test.ts +238 -0
- package/src/sync/sync-engine.ts +79 -83
- package/src/sync/webdav/webdav-delete-index-404.test.ts +29 -1
- package/src/sync/webdav/webdav-transport.ts +26 -5
- package/src/ui/disk-usage-view.test.ts +2 -1
- package/src/ui/i18n.test.ts +47 -0
- package/src/ui/i18n.ts +58 -38
- package/src/ui/import-wizard.test.ts +18 -1
- package/src/ui/import-wizard.ts +3 -2
- package/src/ui/overview-view.test.ts +9 -0
- package/src/ui/overview-view.ts +9 -2
- package/src/ui/report.test.ts +4 -3
- package/src/ui/report.ts +2 -1
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { requestOnce } from '../../utils/proxy.js';
|
|
26
26
|
import { parseJsonSafe } from '../../utils/json.js';
|
|
27
|
+
import { GC_SKIP_REFERENCE_MISSING, GC_SKIP_REFERENCE_UNREADABLE, GC_SKIP_SNAPSHOT_UNPARSABLE } from '../gc-skip.js';
|
|
27
28
|
import { deserializeSnapshot, serializeSnapshot } from '../snapshot-json.js';
|
|
28
29
|
import { BLOB_SECTIONS, gcBlobs, isBlobRefsSection, isFilesSectionLike, referencedBlobHashes, refsToSection, sectionToBlobRefs, } from '../blob-store.js';
|
|
29
30
|
import { classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, isEncryptedSections, sectionsEqual, SyncTransportError, withSyncRetry, } from '../transport.js';
|
|
@@ -42,17 +43,32 @@ const REDACTED = '[REDACTED]';
|
|
|
42
43
|
/**
|
|
43
44
|
* 条件写头(cloud-sync 借鉴项 ①):有 ETag → If-Match(远端必须仍是我读到的那一版);
|
|
44
45
|
* 索引本来就不存在 → If-None-Match: *(防两设备同时首推);服务端不给 ETag → 空(无条件写,不改既有行为)。
|
|
46
|
+
*
|
|
47
|
+
* **阿里云 OSS 没有 If-\***(issue #109 第二层):PutObject 收到 If-Match / If-None-Match 一律回
|
|
48
|
+
* 400 InvalidArgument「A header you provided implies functionality that is not implemented.」
|
|
49
|
+
* (错误码 0017-00000245,真机报文里的 `Header: If-None-Match` 即此)。它只提供
|
|
50
|
+
* `x-oss-forbid-overwrite: true`(对象已存在即 409 FileAlreadyExists)。于是按变体的
|
|
51
|
+
* `conditionalWrite` 能力位映射:
|
|
52
|
+
* - 首推(索引本来就不存在)→ 语义完全等价,改用 x-oss-forbid-overwrite;
|
|
53
|
+
* - 索引已存在(拿到了 ETag)→ 没有对应头,退回「写前 HEAD 复核 ETag」
|
|
54
|
+
* (`assertIndexEtagUnchanged`;非原子,尽力而为)。
|
|
45
55
|
*/
|
|
46
|
-
function conditionalHeaders(etag, indexMissing) {
|
|
56
|
+
function conditionalHeaders(etag, indexMissing, mode) {
|
|
57
|
+
const guarded = mode === 'forbid-overwrite';
|
|
47
58
|
if (etag !== undefined)
|
|
48
|
-
return { 'if-match': etag };
|
|
49
|
-
|
|
59
|
+
return guarded ? {} : { 'if-match': etag };
|
|
60
|
+
if (!indexMissing)
|
|
61
|
+
return {};
|
|
62
|
+
return guarded ? { 'x-oss-forbid-overwrite': 'true' } : { 'if-none-match': '*' };
|
|
50
63
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
64
|
+
/**
|
|
65
|
+
* 条件写失败判定:412 恒是;409 仅在**确实带了条件写头**时才算
|
|
66
|
+
* (无条件的 409 另有含义,不吞;条件写头的存在由调用方显式告知)。
|
|
67
|
+
*/
|
|
68
|
+
function isConcurrentWrite(status, guarded) {
|
|
53
69
|
if (status === 412)
|
|
54
70
|
return true;
|
|
55
|
-
return status === 409 &&
|
|
71
|
+
return status === 409 && guarded;
|
|
56
72
|
}
|
|
57
73
|
/** S3 通道错误:继承统一错误基类(kind / retryable / status 对上层可见)。 */
|
|
58
74
|
export class S3TransportError extends SyncTransportError {
|
|
@@ -123,6 +139,12 @@ export class S3Transport {
|
|
|
123
139
|
type;
|
|
124
140
|
target;
|
|
125
141
|
o;
|
|
142
|
+
/** 最近一轮 blob GC 的放弃码(`null` = 跑完或未触发;SYN-04)。 */
|
|
143
|
+
gcSkip = null;
|
|
144
|
+
/** 最近一轮 blob GC 是否因「无法证明引用集完整」而整体放弃(`null` = 正常跑完),供上层给用户提示。 */
|
|
145
|
+
get lastGcSkip() {
|
|
146
|
+
return this.gcSkip;
|
|
147
|
+
}
|
|
126
148
|
constructor(options) {
|
|
127
149
|
// t79:宿主传进来的 msg(core 目录)**不包含** sync.s3.* 键,直接用会显示裸键名 —— 合并本地目录。
|
|
128
150
|
const msg = composeMsg(options.msg, s3Msg);
|
|
@@ -203,14 +225,16 @@ export class S3Transport {
|
|
|
203
225
|
const merged = idxBefore.filter((m) => m.id !== snapshot.id);
|
|
204
226
|
merged.push(meta);
|
|
205
227
|
merged.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
|
|
206
|
-
const condHeaders = conditionalHeaders(idxEtag, indexMissing);
|
|
228
|
+
const condHeaders = conditionalHeaders(idxEtag, indexMissing, this.target.conditionalWrite);
|
|
229
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
207
230
|
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
208
231
|
body: JSON.stringify(merged),
|
|
209
232
|
secret,
|
|
210
233
|
headers: condHeaders,
|
|
211
234
|
});
|
|
212
|
-
|
|
213
|
-
|
|
235
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
236
|
+
if (idxFailure !== undefined)
|
|
237
|
+
throw idxFailure;
|
|
214
238
|
if (!putIdx.res.ok) {
|
|
215
239
|
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
216
240
|
}
|
|
@@ -255,14 +279,16 @@ export class S3Transport {
|
|
|
255
279
|
const remaining = idx.filter((m) => m.id !== id);
|
|
256
280
|
if (remaining.length === idx.length && del.res.status === 404)
|
|
257
281
|
return; // 对象与索引都没有 → 静默成功
|
|
258
|
-
const condHeaders = conditionalHeaders(idxEtag, false);
|
|
282
|
+
const condHeaders = conditionalHeaders(idxEtag, false, this.target.conditionalWrite);
|
|
283
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
259
284
|
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
260
285
|
body: JSON.stringify(remaining),
|
|
261
286
|
secret,
|
|
262
287
|
headers: condHeaders,
|
|
263
288
|
});
|
|
264
|
-
|
|
265
|
-
|
|
289
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
290
|
+
if (idxFailure !== undefined)
|
|
291
|
+
throw idxFailure;
|
|
266
292
|
if (!putIdx.res.ok) {
|
|
267
293
|
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
268
294
|
}
|
|
@@ -273,6 +299,53 @@ export class S3Transport {
|
|
|
273
299
|
concurrentWrite(url, status) {
|
|
274
300
|
return new S3TransportError(this.o.msg('sync.s3.concurrentWrite', { status: String(status), url }), { kind: 'conflict', retryable: false, status });
|
|
275
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* OSS 方言的「ETag 条件写」替身(issue #109 第二层):PutObject 既无 If-Match 也无
|
|
304
|
+
* If-None-Match,`x-oss-forbid-overwrite` 只能表达「别覆盖已存在的对象」,表达不了
|
|
305
|
+
* 「远端必须还是我读到的那一版」。所以索引进已存在时改成**写前 HEAD 复核 ETag**:
|
|
306
|
+
* 变了 / 对象没了 → 按并发写中止(零写入)。
|
|
307
|
+
*
|
|
308
|
+
* **不是原子的**:复核与 PUT 之间仍有窗口(服务端不支持条件写就没有真正的解),
|
|
309
|
+
* 比无保护强、比 If-Match 弱 —— 如实登记在 docs/decisions/0003。
|
|
310
|
+
* 其它方言(etag)与「服务端不给 ETag」两种情况一律直接放行,不改既有行为。
|
|
311
|
+
*/
|
|
312
|
+
async reassertIndexEtag(etag, secret) {
|
|
313
|
+
if (this.target.conditionalWrite !== 'forbid-overwrite' || etag === undefined)
|
|
314
|
+
return;
|
|
315
|
+
const key = indexKey(this.target.prefix);
|
|
316
|
+
const url = objectUrl(this.target, key);
|
|
317
|
+
const head = await this.send('HEAD', key, { secret });
|
|
318
|
+
if (head.res.status === 404)
|
|
319
|
+
throw this.concurrentWrite(url, 409);
|
|
320
|
+
if (!head.res.ok) {
|
|
321
|
+
throw new S3TransportError(await this.failText('HEAD', head.url, head.res, secret), classifyHttpStatus(head.res.status));
|
|
322
|
+
}
|
|
323
|
+
const current = head.res.headers?.['etag'];
|
|
324
|
+
if (typeof current === 'string' && current !== '' && current !== etag) {
|
|
325
|
+
throw this.concurrentWrite(url, 409);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* 条件写失败分类(issue #109 第二层复核):`isConcurrentWrite` 只看「状态码像不像」,
|
|
330
|
+
* 这里再问报文一句确认「对象确实已存在」。OSS 的 **409 不止 FileAlreadyExists** ——
|
|
331
|
+
* FileImmutable(Bucket 数据处于保护状态,删改都会被拒)同为 409,一律按并发写报
|
|
332
|
+
* 「别的设备改过索引」就是假话。报文读不出时仍按并发写处理(宁可让用户重跑一次,
|
|
333
|
+
* 不吞掉真冲突)。412 是 If-Match 语义,恒为并发写。
|
|
334
|
+
*/
|
|
335
|
+
async conditionalFailure(method, url, res, guarded, secret) {
|
|
336
|
+
if (!isConcurrentWrite(res.status, guarded))
|
|
337
|
+
return undefined;
|
|
338
|
+
if (res.status !== 409)
|
|
339
|
+
return this.concurrentWrite(url, res.status);
|
|
340
|
+
// 只有 forbid-overwrite 方言的 409 有两种含义(FileAlreadyExists / FileImmutable);
|
|
341
|
+
// etag 方言的 409 由各家自定语义,报文不可当作判据 —— 沿用「带条件头的 409 = 并发写」。
|
|
342
|
+
if (this.target.conditionalWrite !== 'forbid-overwrite')
|
|
343
|
+
return this.concurrentWrite(url, res.status);
|
|
344
|
+
const body = await this.errorBody(res);
|
|
345
|
+
if (body === '' || body.includes('FileAlreadyExists'))
|
|
346
|
+
return this.concurrentWrite(url, res.status);
|
|
347
|
+
return new S3TransportError(this.failMessage(method, url, res.status, body, secret), classifyHttpStatus(res.status));
|
|
348
|
+
}
|
|
276
349
|
/**
|
|
277
350
|
* 连通性探针(cloud-sync 借鉴项 ②):HEAD 桶证明端点/凭据/桶可达,再读一次索引回报快照数。
|
|
278
351
|
* 重定向(301/307/308)时读 x-amz-bucket-region 直接把「region 该填什么」告诉用户 ——
|
|
@@ -361,22 +434,27 @@ export class S3Transport {
|
|
|
361
434
|
throw new S3TransportError(this.o.msg('sync.s3.requestError', { method, url, err: this.mask(rawMsg, opts.secret) }), { ...classifyNetworkErrorText(rawMsg), cause: err });
|
|
362
435
|
}
|
|
363
436
|
}
|
|
364
|
-
/**
|
|
365
|
-
async
|
|
366
|
-
let body = '';
|
|
437
|
+
/** 读错误响应体(未脱敏原文,截断到 ERR_BODY_MAX;读不出按空串) */
|
|
438
|
+
async errorBody(res) {
|
|
367
439
|
try {
|
|
368
|
-
|
|
440
|
+
return (await res.text()).slice(0, ERR_BODY_MAX);
|
|
369
441
|
}
|
|
370
442
|
catch {
|
|
371
|
-
|
|
443
|
+
return '';
|
|
372
444
|
}
|
|
445
|
+
}
|
|
446
|
+
/** 构造 HTTP 非 2xx 失败消息:附上脱敏后的响应体片段(截断) */
|
|
447
|
+
failMessage(method, url, status, body, secret) {
|
|
373
448
|
return this.o.msg('sync.s3.requestFailed', {
|
|
374
449
|
method,
|
|
375
450
|
url,
|
|
376
|
-
status: String(
|
|
451
|
+
status: String(status),
|
|
377
452
|
err: this.mask(body, secret),
|
|
378
453
|
});
|
|
379
454
|
}
|
|
455
|
+
async failText(method, url, res, secret) {
|
|
456
|
+
return this.failMessage(method, url, res.status, await this.errorBody(res), secret);
|
|
457
|
+
}
|
|
380
458
|
/** 识别超时错误(AbortError / TimeoutError) */
|
|
381
459
|
isTimeout(err) {
|
|
382
460
|
const name = err?.name ?? '';
|
|
@@ -593,24 +671,31 @@ export class S3Transport {
|
|
|
593
671
|
return { ...snapshot, sections: next };
|
|
594
672
|
}
|
|
595
673
|
/** blob 仓 GC:逐份读仍存在的快照收集引用,删除无人引用且超保护窗的 blob;
|
|
596
|
-
*
|
|
674
|
+
* 读不坏任何一份快照 → 正常回收,否则本轮整体放弃(宁可留垃圾,不可删在用的)。
|
|
675
|
+
* SYN-04(P1):**404 也放弃本轮** —— 条目在但文件 404 = 拿不到内容 = 无法证明「没人引用」,
|
|
676
|
+
* 按残集回收会删掉仍在用的 blob(与 WebDAV 同型,口径一致)。 */
|
|
597
677
|
async gcBlobStore(secret, remaining) {
|
|
678
|
+
this.gcSkip = null;
|
|
598
679
|
const index = await this.readBlobIndex(secret);
|
|
599
680
|
if (Object.keys(index).length === 0)
|
|
600
681
|
return;
|
|
601
682
|
const referenced = new Set();
|
|
602
683
|
for (const meta of remaining) {
|
|
603
684
|
const sent = await this.send('GET', snapshotKey(this.target.prefix, meta.id), { secret });
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
continue;
|
|
607
|
-
if (!sent.res.ok)
|
|
685
|
+
if (sent.res.status === 404) {
|
|
686
|
+
this.gcSkip = GC_SKIP_REFERENCE_MISSING;
|
|
608
687
|
return;
|
|
688
|
+
}
|
|
689
|
+
if (!sent.res.ok) {
|
|
690
|
+
this.gcSkip = GC_SKIP_REFERENCE_UNREADABLE;
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
609
693
|
let snap;
|
|
610
694
|
try {
|
|
611
695
|
snap = deserializeSnapshot(await sent.res.text());
|
|
612
696
|
}
|
|
613
697
|
catch {
|
|
698
|
+
this.gcSkip = GC_SKIP_SNAPSHOT_UNPARSABLE;
|
|
614
699
|
return;
|
|
615
700
|
}
|
|
616
701
|
const plain = snap.sections;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SectionData } from '../schema/types.ts';
|
|
2
|
+
import type { SyncSnapshotMeta, SyncTransport } from './transport.ts';
|
|
1
3
|
/** 会话单元 id 前缀(与 SessionsAdapter.unitIdOf 同口径:`sessions:<projectKey>/<sessionId>`)。 */
|
|
2
4
|
export declare const SESSION_UNIT_PREFIX = "sessions:";
|
|
3
5
|
/** 墓碑上限(FIFO 保留最新 N 条):防止 manifest 无限膨胀(真机会话库 ~660 条,5000 足够宽裕)。 */
|
|
@@ -37,3 +39,54 @@ export declare function stripTombstonedUnits(section: unknown, tombstones: reado
|
|
|
37
39
|
export declare function sessionUnitIdsOfSection(section: unknown): string[];
|
|
38
40
|
/** 内容哈希(用于报告/去重;调用方需要时可对单元清单取指纹)。 */
|
|
39
41
|
export declare function unitSetFingerprint(units: readonly string[]): string;
|
|
42
|
+
/**
|
|
43
|
+
* 一次远端 list() 的读取结果。
|
|
44
|
+
*
|
|
45
|
+
* `metas` 为空**且**无 `reason` 才代表「远端确实为空」;有 reason = 读不到(按「看不到远端」
|
|
46
|
+
* 处理,调用方告警后继续,绝不把它当成「远端没东西」而误判)。
|
|
47
|
+
*/
|
|
48
|
+
export interface RemoteSnapshotIndex {
|
|
49
|
+
metas: SyncSnapshotMeta[];
|
|
50
|
+
reason?: string;
|
|
51
|
+
}
|
|
52
|
+
/** 读一次远端快照索引(只读、零写入)。push 的「是否被推进」判定与墓碑继承共用这一份。 */
|
|
53
|
+
export declare function listRemoteSnapshotIndex(transport: Pick<SyncTransport, 'list'>): Promise<RemoteSnapshotIndex>;
|
|
54
|
+
/**
|
|
55
|
+
* 远端最新快照携带的会话删除墓碑(去重、去空、保序)。
|
|
56
|
+
*
|
|
57
|
+
* 只取**最新一份**:manifest.deletedSessions 是累积清单(见文件头),旧快照的墓碑必然被后续
|
|
58
|
+
* 快照包含;把整段历史并起来只会让「已经在别处撤销的墓碑」复活。
|
|
59
|
+
* 远端为空 / 老快照缺字段 → 空数组(行为与改造前逐字一致:不继承任何墓碑)。
|
|
60
|
+
*/
|
|
61
|
+
export declare function remoteTombstonesOf(metas: readonly SyncSnapshotMeta[]): string[];
|
|
62
|
+
/** 一次 push 的会话簿记结果(manifest / baseline / 告警共用这一份)。 */
|
|
63
|
+
export interface SessionBookkeepingResult {
|
|
64
|
+
/** false = 本次没有可用的会话枚举(没推 sessions / 适配器不支持 / 枚举失败或为空) */
|
|
65
|
+
tracked: boolean;
|
|
66
|
+
sessionUnits: string[];
|
|
67
|
+
tombstones: string[];
|
|
68
|
+
/** 本次**新**发现的删除(之前推过、这次本机没了) */
|
|
69
|
+
deletedNow: string[];
|
|
70
|
+
/** 从远端继承来的墓碑条数(本机此前没有、且本机也没有实体) */
|
|
71
|
+
inherited: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 墓碑集合的唯一计算点(本机删除 + 远端继承合进同一条累积链)。
|
|
75
|
+
*
|
|
76
|
+
* 去重、FIFO 上限、以及「本机还有实体 ⇒ 撤销墓碑」这条不变量对继承来的墓碑同样适用:
|
|
77
|
+
* 另一台设备删了、本机仍有 → 用户在本机显然没删,绝不把它记成本机删除。
|
|
78
|
+
*/
|
|
79
|
+
export declare function planSessionBookkeeping(args: {
|
|
80
|
+
previousUnits: readonly string[];
|
|
81
|
+
previousTombstones: readonly string[];
|
|
82
|
+
localUnits: readonly string[];
|
|
83
|
+
exportedSessions: SectionData | undefined;
|
|
84
|
+
remoteTombstones: readonly string[];
|
|
85
|
+
}): Omit<SessionBookkeepingResult, 'tracked'>;
|
|
86
|
+
/** 按墓碑剔除**将要导入**的会话(旧快照不得复活已删除的对话)。只动载荷,不动本机数据。 */
|
|
87
|
+
export declare function stripTombstonedSessionsInPlace<P extends {
|
|
88
|
+
manifest: {
|
|
89
|
+
deletedSessions?: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
sections: unknown;
|
|
92
|
+
}>(snapshot: P): string[];
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* 本次不实现(保留信息可见,不代用户删数据)。
|
|
19
19
|
*/
|
|
20
20
|
import { sha256Hex } from '../utils/hashing.js';
|
|
21
|
+
import { isEncryptedSections } from './transport.js';
|
|
21
22
|
/** 会话单元 id 前缀(与 SessionsAdapter.unitIdOf 同口径:`sessions:<projectKey>/<sessionId>`)。 */
|
|
22
23
|
export const SESSION_UNIT_PREFIX = 'sessions:';
|
|
23
24
|
/** 墓碑上限(FIFO 保留最新 N 条):防止 manifest 无限膨胀(真机会话库 ~660 条,5000 足够宽裕)。 */
|
|
@@ -122,4 +123,55 @@ export function sessionUnitIdsOfSection(section) {
|
|
|
122
123
|
export function unitSetFingerprint(units) {
|
|
123
124
|
return sha256Hex([...units].sort().join('\n'));
|
|
124
125
|
}
|
|
126
|
+
/** 读一次远端快照索引(只读、零写入)。push 的「是否被推进」判定与墓碑继承共用这一份。 */
|
|
127
|
+
export async function listRemoteSnapshotIndex(transport) {
|
|
128
|
+
try {
|
|
129
|
+
return { metas: await transport.list() };
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return { metas: [], reason: error instanceof Error ? error.message : String(error) };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* 远端最新快照携带的会话删除墓碑(去重、去空、保序)。
|
|
137
|
+
*
|
|
138
|
+
* 只取**最新一份**:manifest.deletedSessions 是累积清单(见文件头),旧快照的墓碑必然被后续
|
|
139
|
+
* 快照包含;把整段历史并起来只会让「已经在别处撤销的墓碑」复活。
|
|
140
|
+
* 远端为空 / 老快照缺字段 → 空数组(行为与改造前逐字一致:不继承任何墓碑)。
|
|
141
|
+
*/
|
|
142
|
+
export function remoteTombstonesOf(metas) {
|
|
143
|
+
const latest = metas.length === 0 ? undefined : metas[metas.length - 1];
|
|
144
|
+
const list = latest?.manifest.deletedSessions ?? [];
|
|
145
|
+
return [...new Set(list.filter((id) => typeof id === 'string' && id !== ''))];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 墓碑集合的唯一计算点(本机删除 + 远端继承合进同一条累积链)。
|
|
149
|
+
*
|
|
150
|
+
* 去重、FIFO 上限、以及「本机还有实体 ⇒ 撤销墓碑」这条不变量对继承来的墓碑同样适用:
|
|
151
|
+
* 另一台设备删了、本机仍有 → 用户在本机显然没删,绝不把它记成本机删除。
|
|
152
|
+
*/
|
|
153
|
+
export function planSessionBookkeeping(args) {
|
|
154
|
+
const known = args.previousTombstones;
|
|
155
|
+
const knownSet = new Set(known);
|
|
156
|
+
const localSet = new Set(args.localUnits);
|
|
157
|
+
const inherited = args.remoteTombstones.filter((id) => !knownSet.has(id) && !localSet.has(id)).length;
|
|
158
|
+
const { tombstones, deletedNow } = nextSessionTombstones({
|
|
159
|
+
previousUnits: [...args.previousUnits],
|
|
160
|
+
localUnits: [...args.localUnits],
|
|
161
|
+
previousTombstones: [...known, ...args.remoteTombstones],
|
|
162
|
+
});
|
|
163
|
+
return { sessionUnits: sessionUnitIdsOfSection(args.exportedSessions), tombstones, deletedNow, inherited };
|
|
164
|
+
}
|
|
165
|
+
/** 按墓碑剔除**将要导入**的会话(旧快照不得复活已删除的对话)。只动载荷,不动本机数据。 */
|
|
166
|
+
export function stripTombstonedSessionsInPlace(snapshot) {
|
|
167
|
+
const tombstones = snapshot.manifest.deletedSessions ?? [];
|
|
168
|
+
if (tombstones.length === 0 || isEncryptedSections(snapshot.sections))
|
|
169
|
+
return [];
|
|
170
|
+
const plain = snapshot.sections;
|
|
171
|
+
const stripped = stripTombstonedUnits(plain['sessions'], tombstones);
|
|
172
|
+
if (stripped.removed.length === 0)
|
|
173
|
+
return [];
|
|
174
|
+
plain['sessions'] = stripped.section;
|
|
175
|
+
return stripped.removed;
|
|
176
|
+
}
|
|
125
177
|
//# sourceMappingURL=session-tombstones.js.map
|
|
@@ -98,18 +98,21 @@ export declare function isGistConfig(cfg: SyncConfig): cfg is Extract<SyncConfig
|
|
|
98
98
|
* 读取同步通道配置;文件不存在/损坏/不支持 schema → null(视为未配置,UI 显示空表单)。
|
|
99
99
|
* 兼容旧文件:缺 schemaVersion 字段视为 v1(git 通道)。
|
|
100
100
|
* 恒返回 schemaVersion=2 的规范形态(v1 读取时归一为 git)。
|
|
101
|
+
*
|
|
102
|
+
* `issues` 可选:传数组时,被丢弃的 git repoUrl(白名单校验不通过)以结构化成因追加进去,
|
|
103
|
+
* 供 UI/日志如实呈现(不静默吞掉)。
|
|
101
104
|
*/
|
|
102
|
-
export declare function readSyncConfig(dir: string): Promise<SyncConfig | null>;
|
|
105
|
+
export declare function readSyncConfig(dir: string, issues?: SyncConfigIssue[]): Promise<SyncConfig | null>;
|
|
103
106
|
/**
|
|
104
107
|
* 读取完整的双命名空间配置(供 status 路由回填另一通道的 repoUrl/url)。
|
|
105
108
|
* 文件不存在/损坏/无任何通道配置 → null(视为未配置)。
|
|
106
109
|
*/
|
|
107
|
-
export declare function readFullSyncConfig(dir: string): Promise<FullSyncConfig | null>;
|
|
110
|
+
export declare function readFullSyncConfig(dir: string, issues?: SyncConfigIssue[]): Promise<FullSyncConfig | null>;
|
|
108
111
|
/**
|
|
109
112
|
* 读取指定通道的同步通道配置(供自动同步调度器按通道运行)。
|
|
110
113
|
* 从完整双命名空间配置取对应通道构造可辨识联合 SyncConfig;该通道未配置 → null。
|
|
111
114
|
*/
|
|
112
|
-
export declare function readSyncConfigFor(dir: string, channel: SyncTransportType): Promise<SyncConfig | null>;
|
|
115
|
+
export declare function readSyncConfigFor(dir: string, channel: SyncTransportType, issues?: SyncConfigIssue[]): Promise<SyncConfig | null>;
|
|
113
116
|
/**
|
|
114
117
|
* 保存同步通道配置(自动创建目录;恒写 schemaVersion=3 双命名空间)。
|
|
115
118
|
* - 写入当前通道的命名空间(git/webdav);
|
|
@@ -142,10 +145,57 @@ export interface ClearSyncChannelResult {
|
|
|
142
145
|
* 它们分别住在 DSH credentials 与 autosync.json,由路由层显式清除(本模块只碰 sync-config.json)。
|
|
143
146
|
*/
|
|
144
147
|
export declare function clearSyncChannel(dir: string, channel: SyncTransportType): Promise<ClearSyncChannelResult>;
|
|
148
|
+
/** repoUrl 形态:网络地址(http/https/ssh,含 scp 式)或本机路径 */
|
|
149
|
+
export type RepoUrlKind = 'http' | 'https' | 'ssh' | 'local';
|
|
150
|
+
/**
|
|
151
|
+
* 已落盘 repoUrl 校验失败的**结构化**结果(SEC-01 读侧)。
|
|
152
|
+
* 读取侧不能只是返回 null:调用方要能如实告诉用户「你的配置被丢弃了,原因是地址不合法」。
|
|
153
|
+
*/
|
|
154
|
+
export interface SyncConfigIssue {
|
|
155
|
+
code: 'repo-url-invalid';
|
|
156
|
+
channel: SyncTransportType;
|
|
157
|
+
message: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* repoUrl 形态分类;null = 不认识的形态。
|
|
161
|
+
*
|
|
162
|
+
* 为什么要分类而不是只做正则:git 对同一个「地址」支持 http(s)、ssh、scp 式与本机路径,
|
|
163
|
+
* 而这三类的安全含义完全不同(网络地址要防 SSRF,本机路径要防 argv 注入)。先判形态,
|
|
164
|
+
* 再按形态分别收紧,比一堆互相打架的正则清楚。
|
|
165
|
+
*/
|
|
166
|
+
export declare function classifyRepoUrl(repoUrl: string): {
|
|
167
|
+
kind: RepoUrlKind;
|
|
168
|
+
host: string;
|
|
169
|
+
} | null;
|
|
170
|
+
/**
|
|
171
|
+
* 环回 / 私网 / 链路本地 / 未指定地址(含云元数据 169.254.169.254)判定。
|
|
172
|
+
* SEC-03:这类地址让「客户端」去访问内网或本机端口,等于给 SSRF 开一扇门。
|
|
173
|
+
*
|
|
174
|
+
* **已知行为变更(有意,非副作用)**:SEC-02/03 之前 `https://192.168.1.10/…`、`http://127.0.0.1:3000/…`、
|
|
175
|
+
* `http://nas.local/…` 这类地址可以被接受。收紧后一律拒绝 —— 代价是「拿家里 NAS / 局域网 git 服务器
|
|
176
|
+
* 当同步目标」这条路走不通,收益是「包里的 repoUrl 无法把家目录配置推给内网监听者或云元数据端点」。
|
|
177
|
+
* 取舍判据:本插件的同步目标是「用户自己的远端仓库」,公网 http(s)/ssh 已覆盖该用途;本机目录仓库
|
|
178
|
+
* 仍走 `local` 分支(不由本函数判定)。真要支持内网目标,应做成显式开关 + 用户逐目标确认,
|
|
179
|
+
* 不能靠「地址字符串看起来像内网就放行」——那正是攻击者可控的判据。
|
|
180
|
+
*/
|
|
181
|
+
export declare function isPrivateRepoHost(host: string): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* 文案里回显地址用:剥掉 userinfo(token 可能就藏在这一段),host/path 原样保留。
|
|
184
|
+
*
|
|
185
|
+
* 为什么不整串换成 `[REPO_URL]` 占位符:这里拒绝的是**用户自己刚填的**地址,他需要认出
|
|
186
|
+
* 「被拒的是哪一个」才能改;剥掉 `user:pass@` 之后剩下的部分正是修复所需的定位信息。
|
|
187
|
+
* 为什么解析失败也要剥:`https://user:tok@` 这类半截地址 `new URL` 会抛,但前缀照样是凭据。
|
|
188
|
+
*/
|
|
189
|
+
export declare function sanitizeRepoUrlForMessage(url: string): string;
|
|
145
190
|
/**
|
|
146
191
|
* 仓库地址合法性校验(返回错误消息;null = 合法)。
|
|
147
|
-
*
|
|
148
|
-
*
|
|
192
|
+
*
|
|
193
|
+
* 白名单口径(SEC-02/03/12,写入侧与读取侧共用同一份实现):
|
|
194
|
+
* - 只认 http(s)/ssh/scp 式网络地址与本机路径;file://、ext::、ftp://、git:// 一律拒绝;
|
|
195
|
+
* - 整串以 '-' 开头拒绝(git argv 位置参数以 '-' 开头会被当选项,可执行任意命令);
|
|
196
|
+
* - 网络地址拒绝环回/私网/链路本地主机(SSRF)—— 文案单独一条(sync.configPrivateHost),
|
|
197
|
+
* 不能复用「无法解析」:用户看到「解析不了」只会反复改写法,实际原因是地址指向内网;
|
|
198
|
+
* - 带 scheme 的地址一律拒绝 userinfo(username[:password]@)—— token 只许放凭据字段。
|
|
149
199
|
*/
|
|
150
200
|
export declare function validateRepoUrl(repoUrl: string, msg?: MsgFunc): string | null;
|
|
151
201
|
/**
|