dsh-config-manager 0.5.0 → 0.7.0
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/lib/client.d.ts +8 -0
- package/lib/client.js +748 -602
- package/lib/core/local-plugin-host.d.ts +9 -0
- package/lib/core/local-plugin-host.js +174 -1
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +16 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/run-registry.d.ts +10 -0
- package/lib/core/run-registry.js +17 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +20 -19
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/import.js +6 -1
- package/lib/routes/route-support.d.ts +2 -1
- package/lib/routes/route-support.js +8 -3
- package/lib/routes/sync.js +5 -2
- package/lib/sync/autosync-config.d.ts +9 -1
- package/lib/sync/autosync-config.js +10 -2
- package/lib/sync/autosync-scheduler.js +18 -6
- package/lib/sync/git/git-transport.d.ts +31 -1
- package/lib/sync/git/git-transport.js +119 -23
- package/lib/sync/sync-config.d.ts +34 -3
- package/lib/sync/sync-config.js +38 -5
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/ui/sync-settings-view.d.ts +4 -0
- package/lib/ui/sync-settings-view.js +3 -0
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/package.json +1 -1
- package/src/client/config-manager.module.css +21 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/run-store.test.ts +1 -1
- package/src/client/run-store.ts +5 -0
- package/src/client/sync/ChannelConfigDialog.tsx +47 -2
- package/src/client/sync/SyncPanel.tsx +17 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/sync-api.ts +2 -0
- package/src/client/sync/sync-locales.ts +10 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/local-plugin-host.test.ts +31 -2
- package/src/core/local-plugin-host.ts +175 -2
- package/src/core/messages.ts +16 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/run-registry-runs.test.ts +26 -1
- package/src/core/run-registry.ts +18 -0
- package/src/index.sync.test.ts +27 -0
- package/src/index.ts +21 -21
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/import.ts +6 -1
- package/src/routes/route-support.ts +7 -3
- package/src/routes/sync.ts +5 -2
- package/src/sync/autosync-config.ts +10 -2
- package/src/sync/autosync-scheduler.test.ts +61 -1
- package/src/sync/autosync-scheduler.ts +17 -5
- package/src/sync/git/git-transport.test.ts +117 -0
- package/src/sync/git/git-transport.ts +131 -23
- package/src/sync/sync-config.test.ts +59 -1
- package/src/sync/sync-config.ts +51 -5
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/ui/sync-settings-view.test.ts +1 -0
- package/src/ui/sync-settings-view.ts +7 -0
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
|
@@ -31,7 +31,7 @@ import type { SnapshotDirManifest } from '../layout.ts';
|
|
|
31
31
|
import { BLOB_SECTIONS, gcBlobs, referencedBlobHashes } from '../blob-store.ts';
|
|
32
32
|
import type { BlobSink } from '../blob-store.ts';
|
|
33
33
|
import { deserializeSnapshot, serializeSnapshot } from '../snapshot-json.ts';
|
|
34
|
-
import { classifyRepoUrl, isPrivateRepoHost } from '../sync-config.ts';
|
|
34
|
+
import { classifyRepoUrl, isPrivateRepoHost, normalizeGitSubdir } from '../sync-config.ts';
|
|
35
35
|
import {
|
|
36
36
|
classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, isEncryptedSections,
|
|
37
37
|
SyncTransportError, withSyncRetry,
|
|
@@ -120,13 +120,24 @@ const inspectFactsCache = new Map<string, { at: number; detail: boolean; facts:
|
|
|
120
120
|
*/
|
|
121
121
|
const INSPECT_WORKDIR_LOCK_TIMEOUT_MS = 1_500;
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
/**
|
|
124
|
+
* 工作副本布局身份的进程内缓存(key = workDir,值同 `readStoredSubdir()`,issue #131)。
|
|
125
|
+
*
|
|
126
|
+
* 为什么缓存:每次操作都要校验布局,而读一次 git 本地配置就是一次 git 子进程启动
|
|
127
|
+
* (Windows 真机约 80 ms,正是 L-04 在削的那笔开销)。布局身份是**工作副本的属性**,
|
|
128
|
+
* 只有本类写入(clone / adopt)与重建(reclone)会改它 —— 那三处显式更新缓存。
|
|
129
|
+
*/
|
|
130
|
+
const storedSubdirCache = new Map<string, string | null>();
|
|
131
|
+
|
|
132
|
+
function inspectFactsCacheKey(workDir: string, repoUrl: string, subdir: string): string {
|
|
133
|
+
// 子目录前缀必须进 key:同一工作副本路径在不同前缀下的「远端快照数」是不同的答案(issue #131)。
|
|
134
|
+
return workDir + '\u0000' + repoUrl + '\u0000' + subdir;
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
/** 清空自检缓存(测试隔离用;生产路径由 `withWorkdir` 逐 key 失效)。 */
|
|
128
138
|
export function clearInspectFactsCache(): void {
|
|
129
139
|
inspectFactsCache.clear();
|
|
140
|
+
storedSubdirCache.clear();
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
/** 凭据提供者:token 只从这里读取,绝不在任何地方持久化 */
|
|
@@ -139,6 +150,12 @@ export interface GitAuthor { name: string; email: string; }
|
|
|
139
150
|
export interface GitTransportOptions {
|
|
140
151
|
/** 远端私有仓库地址(https/ssh/本地路径);token 绝不拼入此 URL */
|
|
141
152
|
repoUrl: string;
|
|
153
|
+
/**
|
|
154
|
+
* 仓库内子目录前缀(issue #131,可缺省):快照布局落在 `<subdir>/snapshots`、
|
|
155
|
+
* `<subdir>/snapshots-encrypted`、`<subdir>/blobs`;空串/缺省 = 仓库根(历史行为)。
|
|
156
|
+
* 多工具共用同一个私有备份仓库时,每个工具各占一个子目录。
|
|
157
|
+
*/
|
|
158
|
+
subdir?: string;
|
|
142
159
|
/** 本地 git 工作副本目录(不存在则创建;已 clone 则复用) */
|
|
143
160
|
workDir: string;
|
|
144
161
|
/** token 提供者(http(s) 远端必填;本地/ssh 远端不会被调用) */
|
|
@@ -190,7 +207,22 @@ const ADOPT_ROOT_ALLOW = new Set<string>([SNAPSHOTS_REL, SNAPSHOTS_ENCRYPTED_REL
|
|
|
190
207
|
* 远端仓库比同步内容大几个数量级时(报告者现场:1.8 GB 仓库 / 6 MB 内容),全量 clone 与全量 fetch
|
|
191
208
|
* 都要拉完整对象图,而工作副本真正需要的只有这三个目录。
|
|
192
209
|
*/
|
|
193
|
-
|
|
210
|
+
/* 具体的 sparse 面在 `syncDirs()` 里按子目录前缀派生(issue #131),基名与 ADOPT_ROOT_ALLOW 同源。 */
|
|
211
|
+
/**
|
|
212
|
+
* 工作副本的**布局身份**键(git 本地配置,issue #131):记录这份工作副本是按哪个子目录前缀建的。
|
|
213
|
+
*
|
|
214
|
+
* 为什么必须落盘:sparse-checkout 只在首次 clone 时生效 —— 前缀从「仓库根」改成 `DSH备份` 后,
|
|
215
|
+
* 旧工作副本里根本没有 `DSH备份/` 这棵树,pull 会成功、list 会读空,用户看到的是
|
|
216
|
+
* 「远端没有快照」(issue #104 那类最难自查的假象)。存成 git 本地配置而不是工作树里的文件:
|
|
217
|
+
* 工作树文件会让 `status --porcelain` 恒 dirty,adopt 直接拒绝。
|
|
218
|
+
*/
|
|
219
|
+
const SUBDIR_CONFIG_KEY = 'dsh.syncSubdir';
|
|
220
|
+
/**
|
|
221
|
+
* 标记值的版本前缀(issue #131)。为什么带前缀:读侧必须能区分「本插件写的」与「任何别的值」——
|
|
222
|
+
* 值不匹配前缀一律按「读不出」处理(回落历史布局 = 仓库根),这样伪造/污染的配置不会凭空
|
|
223
|
+
* 造出一条假的「布局已变」错误。空子目录写作 `1:`,仍是可判读的有效标记。
|
|
224
|
+
*/
|
|
225
|
+
const SUBDIR_MARKER_PREFIX = '1:';
|
|
194
226
|
/**
|
|
195
227
|
* 走网络的 git 子命令:一律附加低速上限(issue #122)。
|
|
196
228
|
*
|
|
@@ -378,6 +410,8 @@ export class GitTransport implements SyncTransport {
|
|
|
378
410
|
private readonly msg: MsgFunc;
|
|
379
411
|
/** repoUrl 是否为网络地址(本地目录仓库 == false):决定要不要额外禁 file 传输(SEC-12)。 */
|
|
380
412
|
private readonly networkRepo: boolean;
|
|
413
|
+
/** 仓库内子目录前缀('' = 仓库根):快照布局、sparse 面与 adopt 判据都从它派生(issue #131)。 */
|
|
414
|
+
private readonly subdir: string;
|
|
381
415
|
|
|
382
416
|
constructor(options: GitTransportOptions) {
|
|
383
417
|
if (typeof options.repoUrl !== 'string' || options.repoUrl.length === 0) {
|
|
@@ -401,6 +435,12 @@ export class GitTransport implements SyncTransport {
|
|
|
401
435
|
throw new GitTransportError(this.msg('sync.git.repoUrlInvalid', { url: REPO_URL_PLACEHOLDER }));
|
|
402
436
|
}
|
|
403
437
|
this.networkRepo = repoShape.kind !== 'local';
|
|
438
|
+
// issue #131:子目录前缀在构造期就收窄(与 repoUrl 同一条纪律:非法值绝不进 git 子进程)。
|
|
439
|
+
const subdirCheck = normalizeGitSubdir(options.subdir ?? '');
|
|
440
|
+
if (!subdirCheck.ok) {
|
|
441
|
+
throw new GitTransportError(this.msg('sync.git.subdirInvalid', { subdir: String(options.subdir ?? '') }));
|
|
442
|
+
}
|
|
443
|
+
this.subdir = subdirCheck.value;
|
|
404
444
|
this.o = {
|
|
405
445
|
repoUrl: options.repoUrl,
|
|
406
446
|
workDir: options.workDir,
|
|
@@ -498,7 +538,7 @@ export class GitTransport implements SyncTransport {
|
|
|
498
538
|
await fsx.writeFile(file, new TextEncoder().encode(serializeSnapshot(snapshot)));
|
|
499
539
|
// 同 id 旧散文件目录残留 → 一并清理(形态切换不残留)
|
|
500
540
|
await fsx.remove(this.snapshotDir(snapshot.id));
|
|
501
|
-
rel = `${SNAPSHOTS_ENCRYPTED_REL}/${snapshot.id}.json`;
|
|
541
|
+
rel = `${this.relDir(SNAPSHOTS_ENCRYPTED_REL)}/${snapshot.id}.json`;
|
|
502
542
|
} else {
|
|
503
543
|
const dir = this.snapshotDir(snapshot.id);
|
|
504
544
|
if (await fsx.exists(dir)) await fsx.remove(dir); // 覆盖语义:先清旧目录,避免残留旧文件
|
|
@@ -519,11 +559,11 @@ export class GitTransport implements SyncTransport {
|
|
|
519
559
|
}
|
|
520
560
|
// 同 id 旧密文单文件残留 → 一并清理(形态切换不残留)
|
|
521
561
|
await fsx.remove(this.encryptedSnapshotFile(snapshot.id));
|
|
522
|
-
rel = `${SNAPSHOTS_REL}/${snapshot.id}`;
|
|
562
|
+
rel = `${this.relDir(SNAPSHOTS_REL)}/${snapshot.id}`;
|
|
523
563
|
}
|
|
524
564
|
// blob 仓与快照同一次提交:引用文件与它引用的字节绝不跨 commit 分离
|
|
525
565
|
const hasBlobs = await fsx.exists(this.blobsDir());
|
|
526
|
-
await this.runGit(hasBlobs ? ['add', '--', rel, BLOBS_REL] : ['add', '--', rel]);
|
|
566
|
+
await this.runGit(hasBlobs ? ['add', '--', rel, this.relDir(BLOBS_REL)] : ['add', '--', rel]);
|
|
527
567
|
const diff = await this.runGit(['diff', '--cached', '--quiet'], { allowNonZero: true });
|
|
528
568
|
if (diff.code !== 0) {
|
|
529
569
|
const verb = existed ? 'update' : 'add';
|
|
@@ -588,10 +628,10 @@ export class GitTransport implements SyncTransport {
|
|
|
588
628
|
let rel: string;
|
|
589
629
|
if (plainExists) {
|
|
590
630
|
await fsx.remove(plainDir);
|
|
591
|
-
rel = `${SNAPSHOTS_REL}/${id}`;
|
|
631
|
+
rel = `${this.relDir(SNAPSHOTS_REL)}/${id}`;
|
|
592
632
|
} else {
|
|
593
633
|
await fsx.remove(encFile);
|
|
594
|
-
rel = `${SNAPSHOTS_ENCRYPTED_REL}/${id}.json`;
|
|
634
|
+
rel = `${this.relDir(SNAPSHOTS_ENCRYPTED_REL)}/${id}.json`;
|
|
595
635
|
}
|
|
596
636
|
await this.runGit(['add', '-A', '--', rel]);
|
|
597
637
|
const diff = await this.runGit(['diff', '--cached', '--quiet'], { allowNonZero: true });
|
|
@@ -684,7 +724,7 @@ export class GitTransport implements SyncTransport {
|
|
|
684
724
|
} finally {
|
|
685
725
|
// 除纯只读自检外,任何操作都可能改变工作副本状态(push 改 ahead、fetch 改远端引用、
|
|
686
726
|
// 重建删目录、失败也可能已留下 commit)→ 收尾即丢弃自检缓存,绝不让「写后读」看到旧事实。
|
|
687
|
-
if (opts.readonly !== true) inspectFactsCache.delete(inspectFactsCacheKey(this.o.workDir, this.o.repoUrl));
|
|
727
|
+
if (opts.readonly !== true) inspectFactsCache.delete(inspectFactsCacheKey(this.o.workDir, this.o.repoUrl, this.subdir));
|
|
688
728
|
}
|
|
689
729
|
}
|
|
690
730
|
|
|
@@ -699,6 +739,8 @@ export class GitTransport implements SyncTransport {
|
|
|
699
739
|
// 而失败面表现为旧地址的网络超时(真机:局域网地址 → Tailscale 地址后同步长期失败),
|
|
700
740
|
// 用户会误判成网络/凭据问题。
|
|
701
741
|
await this.reconcileOrigin();
|
|
742
|
+
// issue #131:布局身份(子目录前缀)与当前配置不一致 ⇒ 明确报「需重建」,绝不照常同步
|
|
743
|
+
await this.assertLayoutMatches();
|
|
702
744
|
// 真机 issue:仓库级提交身份此前**只在首次 clone 时**写过(见本方法末尾),已有 .git 的分支
|
|
703
745
|
// 直接 return —— 换机器/换工作副本/用户清过本地配置之后,每次 commit 都以 exit 128 失败
|
|
704
746
|
// ("unable to auto-detect email address"),交易停在 NEEDS_ATTENTION,用户只看到
|
|
@@ -724,6 +766,8 @@ export class GitTransport implements SyncTransport {
|
|
|
724
766
|
// 仓库级提交身份(写入远端历史,可经 author 选项覆盖;不改全局配置)
|
|
725
767
|
await this.runGit(['config', 'user.name', this.o.author.name]);
|
|
726
768
|
await this.runGit(['config', 'user.email', this.o.author.email]);
|
|
769
|
+
// 记录布局身份(issue #131):此后前缀再变,assertLayoutMatches 能把它判出来
|
|
770
|
+
await this.writeLayoutMarker();
|
|
727
771
|
this.repoReady = true;
|
|
728
772
|
}
|
|
729
773
|
|
|
@@ -755,6 +799,48 @@ export class GitTransport implements SyncTransport {
|
|
|
755
799
|
}
|
|
756
800
|
}
|
|
757
801
|
|
|
802
|
+
/**
|
|
803
|
+
* 工作副本是按哪个子目录前缀建的(issue #131):读 git 本地配置 `dsh.syncSubdir`。
|
|
804
|
+
* null = 键不存在 ⇒ 本功能上线前建的工作副本,布局 = 仓库根(历史行为)。
|
|
805
|
+
*/
|
|
806
|
+
private async readStoredSubdir(): Promise<string | null> {
|
|
807
|
+
const cached = storedSubdirCache.get(this.o.workDir);
|
|
808
|
+
if (cached !== undefined) return cached;
|
|
809
|
+
try {
|
|
810
|
+
const r = await this.runGit(['config', '--get', SUBDIR_CONFIG_KEY], { allowNonZero: true });
|
|
811
|
+
const raw = r.code === 0 ? r.stdout.trim() : '';
|
|
812
|
+
// 键不存在 / 前缀不符(不是本插件写的标记,或被人改坏)⇒ 不知道,按历史布局处理
|
|
813
|
+
const value = raw.startsWith(SUBDIR_MARKER_PREFIX) ? raw.slice(SUBDIR_MARKER_PREFIX.length) : null;
|
|
814
|
+
storedSubdirCache.set(this.o.workDir, value);
|
|
815
|
+
return value;
|
|
816
|
+
} catch {
|
|
817
|
+
return null; // 读不出 = 不知道,按历史布局处理(不拿猜测阻断同步;失败不进缓存,下次再读)
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** 写入布局身份标记(issue #131):git 本地配置 + 同步更新进程内缓存。 */
|
|
822
|
+
private async writeLayoutMarker(): Promise<void> {
|
|
823
|
+
await this.runGit(['config', SUBDIR_CONFIG_KEY, SUBDIR_MARKER_PREFIX + this.subdir]);
|
|
824
|
+
storedSubdirCache.set(this.o.workDir, this.subdir);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* 布局身份校验(issue #131):工作副本建好时的前缀必须与当前配置一致。
|
|
829
|
+
*
|
|
830
|
+
* 为什么必须显式报错而不是「照常同步」:sparse-checkout 只在首次 clone 生效 —— 前缀换了以后,
|
|
831
|
+
* 旧工作副本里根本没有 `<新前缀>/` 这棵树,pull 成功、list 读空,用户看到的是
|
|
832
|
+
* 「远端没有快照」。这条错误把出口指回既有的「重建工作副本(重新克隆)」。
|
|
833
|
+
*/
|
|
834
|
+
private async assertLayoutMatches(): Promise<void> {
|
|
835
|
+
const stored = (await this.readStoredSubdir()) ?? '';
|
|
836
|
+
if (stored === this.subdir) return;
|
|
837
|
+
const label = (prefix: string): string => (prefix === '' ? this.msg('sync.git.subdirRoot') : prefix);
|
|
838
|
+
throw new GitTransportError(
|
|
839
|
+
this.msg('sync.git.subdirChanged', { stored: label(stored), expected: label(this.subdir) }),
|
|
840
|
+
{ kind: 'protocol', retryable: false },
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
|
|
758
844
|
/**
|
|
759
845
|
* 首次 clone(issue #122):partial clone + sparse-checkout,只落地同步内容。
|
|
760
846
|
*
|
|
@@ -784,7 +870,8 @@ export class GitTransport implements SyncTransport {
|
|
|
784
870
|
const head = await this.runGit(['rev-parse', '--verify', '--quiet', 'HEAD'], { allowNonZero: true });
|
|
785
871
|
if (head.code !== 0) return; // 空仓库:没有可 checkout 的树,后续 push 会建分支
|
|
786
872
|
const target = branch === '' ? 'HEAD' : branch;
|
|
787
|
-
|
|
873
|
+
// issue #131:sparse 面跟着子目录前缀走 —— 共用仓库里其它工具的目录绝不被 materialize
|
|
874
|
+
const sparse = await this.runGit(['sparse-checkout', 'set', '--cone', ...this.syncDirs()], { allowNonZero: true });
|
|
788
875
|
if (sparse.code !== 0) {
|
|
789
876
|
// 老 git 没有 cone 模式:宁可全量落地(修复前行为),也不留下一个空工作树
|
|
790
877
|
await this.runGit(['checkout', target], { allowNonZero: true });
|
|
@@ -891,7 +978,7 @@ export class GitTransport implements SyncTransport {
|
|
|
891
978
|
* 因此放进 `detail: true`(供「重建工作副本」前评估数据量等场景显式索取)。
|
|
892
979
|
*/
|
|
893
980
|
async inspectWorkDir(opts: { detail?: boolean } = {}): Promise<GitWorkDirFacts> {
|
|
894
|
-
const key = inspectFactsCacheKey(this.o.workDir, this.o.repoUrl);
|
|
981
|
+
const key = inspectFactsCacheKey(this.o.workDir, this.o.repoUrl, this.subdir);
|
|
895
982
|
const detail = opts.detail === true;
|
|
896
983
|
const hit = inspectFactsCache.get(key);
|
|
897
984
|
// 命中即返回:不必排队等锁,也不必再 spawn 一条 git(这是首页/切页/轮询的常态路径)。
|
|
@@ -947,8 +1034,8 @@ export class GitTransport implements SyncTransport {
|
|
|
947
1034
|
// 每个快照是一级子项;`.gitkeep` 只是占位,不是快照
|
|
948
1035
|
.filter((line) => line !== '' && !line.endsWith(SNAPSHOT_KEEP_FILE)).length;
|
|
949
1036
|
};
|
|
950
|
-
const plain = await countTree(`origin/${branch}:${SNAPSHOTS_REL}`);
|
|
951
|
-
const encrypted = await countTree(`origin/${branch}:${SNAPSHOTS_ENCRYPTED_REL}`);
|
|
1037
|
+
const plain = await countTree(`origin/${branch}:${this.relDir(SNAPSHOTS_REL)}`);
|
|
1038
|
+
const encrypted = await countTree(`origin/${branch}:${this.relDir(SNAPSHOTS_ENCRYPTED_REL)}`);
|
|
952
1039
|
// 两个目录都不存在 = 远端分支根本没有快照布局(0);分支/引用读不出 = null(不猜)
|
|
953
1040
|
remoteSnapshots = plain === null && encrypted === null ? 0 : (plain ?? 0) + (encrypted ?? 0);
|
|
954
1041
|
}
|
|
@@ -1006,6 +1093,7 @@ export class GitTransport implements SyncTransport {
|
|
|
1006
1093
|
return;
|
|
1007
1094
|
}
|
|
1008
1095
|
await fs.rm(this.o.workDir, { recursive: true, force: true });
|
|
1096
|
+
storedSubdirCache.delete(this.o.workDir); // 旧副本连同它的布局身份一起没了
|
|
1009
1097
|
await this.ensureRepo();
|
|
1010
1098
|
}
|
|
1011
1099
|
|
|
@@ -1047,6 +1135,8 @@ export class GitTransport implements SyncTransport {
|
|
|
1047
1135
|
);
|
|
1048
1136
|
}
|
|
1049
1137
|
await this.reconcileOrigin();
|
|
1138
|
+
// issue #131:采纳远端历史也不许跨布局 —— 前缀变了要先重建工作副本
|
|
1139
|
+
await this.assertLayoutMatches();
|
|
1050
1140
|
const branchRes = await this.runGit(['rev-parse', '--abbrev-ref', 'HEAD'], { allowNonZero: true });
|
|
1051
1141
|
const branch = branchRes.code === 0 ? branchRes.stdout.trim() : '';
|
|
1052
1142
|
if (branch === '' || branch === 'HEAD') {
|
|
@@ -1079,9 +1169,13 @@ export class GitTransport implements SyncTransport {
|
|
|
1079
1169
|
{ kind: 'protocol', retryable: false },
|
|
1080
1170
|
);
|
|
1081
1171
|
}
|
|
1082
|
-
// ②
|
|
1083
|
-
|
|
1084
|
-
|
|
1172
|
+
// ② 同步布局只能是那三个目录。配了子目录前缀时校验的是 <subdir>/ **子树**(issue #131):
|
|
1173
|
+
// 共用仓库里其它工具的目录在仓库根,那不是本插件的同步内容,也不该被判成「污染」。
|
|
1174
|
+
const treeish = this.subdir === '' ? `origin/${branch}` : `origin/${branch}:${this.subdir}`;
|
|
1175
|
+
const treeRes = await this.runGit(['ls-tree', '--name-only', treeish], { allowNonZero: true });
|
|
1176
|
+
// 子树不存在 = 远端还没有该前缀的同步内容(首次 push 会建它),不是错误;
|
|
1177
|
+
// 仓库根读不出来才是真异常(引用在上面已验过存在)。
|
|
1178
|
+
if (treeRes.code !== 0 && this.subdir === '') {
|
|
1085
1179
|
throw new GitTransportError(
|
|
1086
1180
|
this.msg('sync.git.cmdFailed', {
|
|
1087
1181
|
args: `ls-tree --name-only origin/${branch}`,
|
|
@@ -1091,7 +1185,7 @@ export class GitTransport implements SyncTransport {
|
|
|
1091
1185
|
{ kind: 'unknown', retryable: true },
|
|
1092
1186
|
);
|
|
1093
1187
|
}
|
|
1094
|
-
const unknownEntries = treeRes.stdout
|
|
1188
|
+
const unknownEntries = (treeRes.code === 0 ? treeRes.stdout : '')
|
|
1095
1189
|
.split('\n')
|
|
1096
1190
|
.map((name) => name.trim().replace(/\/$/, ''))
|
|
1097
1191
|
.filter((name) => name !== '' && !ADOPT_ROOT_ALLOW.has(name));
|
|
@@ -1112,6 +1206,7 @@ export class GitTransport implements SyncTransport {
|
|
|
1112
1206
|
}
|
|
1113
1207
|
// 让后续 pull --ff-only 有 upstream 可用(忽略失败:分支可能已被删/重命名)
|
|
1114
1208
|
await this.runGit(['branch', '--set-upstream-to', `origin/${branch}`, branch], { allowNonZero: true });
|
|
1209
|
+
await this.writeLayoutMarker();
|
|
1115
1210
|
this.repoReady = true;
|
|
1116
1211
|
}
|
|
1117
1212
|
|
|
@@ -1395,8 +1490,21 @@ export class GitTransport implements SyncTransport {
|
|
|
1395
1490
|
: this.msg('sync.git.hostKeyUnverified', { host });
|
|
1396
1491
|
}
|
|
1397
1492
|
|
|
1493
|
+
/** 子目录前缀下的同步布局相对路径('' 前缀 = 历史布局,逐字不变)。 */
|
|
1494
|
+
private relDir(base: string): string {
|
|
1495
|
+
return this.subdir === '' ? base : `${this.subdir}/${base}`;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* 三个同步根目录(带前缀):sparse 面、add 路径、adopt 判据都从这里取 ——
|
|
1500
|
+
* 任何一处漏加前缀都会让「写入 A、读取 B」(issue #131 的失败面)。
|
|
1501
|
+
*/
|
|
1502
|
+
private syncDirs(): string[] {
|
|
1503
|
+
return [this.relDir(SNAPSHOTS_REL), this.relDir(SNAPSHOTS_ENCRYPTED_REL), this.relDir(BLOBS_REL)];
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1398
1506
|
private blobsDir(): string {
|
|
1399
|
-
return path.join(this.o.workDir, BLOBS_REL);
|
|
1507
|
+
return path.join(this.o.workDir, this.relDir(BLOBS_REL));
|
|
1400
1508
|
}
|
|
1401
1509
|
|
|
1402
1510
|
/**
|
|
@@ -1464,7 +1572,7 @@ export class GitTransport implements SyncTransport {
|
|
|
1464
1572
|
if (!readable) return;
|
|
1465
1573
|
const deleted = await gcBlobs({ sink: this.blobSink(fsx), referenced, nowMs: Date.now() });
|
|
1466
1574
|
if (deleted.length === 0) return;
|
|
1467
|
-
await this.runGit(['add', '-A', '--', BLOBS_REL]);
|
|
1575
|
+
await this.runGit(['add', '-A', '--', this.relDir(BLOBS_REL)]);
|
|
1468
1576
|
const diff = await this.runGit(['diff', '--cached', '--quiet'], { allowNonZero: true });
|
|
1469
1577
|
if (diff.code === 0) return;
|
|
1470
1578
|
await this.runGit(['commit', '-m', `sync: gc ${deleted.length} blob(s)`]);
|
|
@@ -1482,12 +1590,12 @@ export class GitTransport implements SyncTransport {
|
|
|
1482
1590
|
}
|
|
1483
1591
|
|
|
1484
1592
|
private snapshotsDir(): string {
|
|
1485
|
-
return joinFs(this.o.workDir, SNAPSHOTS_REL);
|
|
1593
|
+
return joinFs(this.o.workDir, this.relDir(SNAPSHOTS_REL));
|
|
1486
1594
|
}
|
|
1487
1595
|
|
|
1488
|
-
/** 加密快照密文单文件目录(<workDir>/snapshots-encrypted
|
|
1596
|
+
/** 加密快照密文单文件目录(<workDir>/snapshots-encrypted/;配了前缀则在 <subdir>/ 下) */
|
|
1489
1597
|
private encryptedSnapshotsDir(): string {
|
|
1490
|
-
return joinFs(this.o.workDir, SNAPSHOTS_ENCRYPTED_REL);
|
|
1598
|
+
return joinFs(this.o.workDir, this.relDir(SNAPSHOTS_ENCRYPTED_REL));
|
|
1491
1599
|
}
|
|
1492
1600
|
|
|
1493
1601
|
/** 加密快照密文单文件路径(<id>.json) */
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
SYNC_CONFIG_FILE, SYNC_CONFIG_SCHEMA_VERSION, SYNC_CONFIG_SUPPORTED_VERSIONS, CLOUD_SYNC_CONFIG_FILE,
|
|
27
27
|
validateWebDavUrl, validateRepoUrl, type SyncConfig, type SyncConfigIssue,
|
|
28
28
|
SYNC_CHANNELS, channelOf, channelMap, isSyncTransportType, parseSyncChannel, clearSyncChannel,
|
|
29
|
-
S3_COMPAT_PROVIDERS, CLOUD_SYNC_PROVIDERS, cloudSecretRef,
|
|
29
|
+
S3_COMPAT_PROVIDERS, CLOUD_SYNC_PROVIDERS, cloudSecretRef, normalizeGitSubdir,
|
|
30
30
|
} from './sync-config.ts';
|
|
31
31
|
// t88 跨侧常量守卫:共享零依赖常量 + 客户端镜像(见文件末尾的 t88 用例)
|
|
32
32
|
import { S3_COMPAT_PROVIDERS as SHARED_S3_COMPAT_PROVIDERS, cloudSecretRefName } from '../utils/shared-constants.ts';
|
|
@@ -919,3 +919,61 @@ test('validateRepoUrl(RV1-F7):带 scheme 的 userinfo —— ssh 的 token
|
|
|
919
919
|
assert.ok(half !== null);
|
|
920
920
|
assert.ok(!half.includes('ghp_halfsecret'), '无法解析的地址同样不得回显凭据: ' + half);
|
|
921
921
|
});
|
|
922
|
+
|
|
923
|
+
test('issue #131:normalizeGitSubdir —— 中文与嵌套放行,绝对路径/../反斜杠/空段/.git 段拒绝', () => {
|
|
924
|
+
const ok = (raw: unknown): string => {
|
|
925
|
+
const r = normalizeGitSubdir(raw);
|
|
926
|
+
assert.equal(r.ok, true, '应放行: ' + String(raw));
|
|
927
|
+
return r.ok ? r.value : '';
|
|
928
|
+
};
|
|
929
|
+
const bad = (raw: unknown): void => {
|
|
930
|
+
assert.equal(normalizeGitSubdir(raw).ok, false, '应拒绝: ' + String(raw));
|
|
931
|
+
};
|
|
932
|
+
assert.equal(ok(undefined), '', '缺省 = 仓库根');
|
|
933
|
+
assert.equal(ok(''), '', '空串 = 仓库根');
|
|
934
|
+
assert.equal(ok(' '), '', '纯空白 = 仓库根');
|
|
935
|
+
assert.equal(ok(' DSH备份 '), 'DSH备份', '去首尾空白,保留 UTF-8');
|
|
936
|
+
assert.equal(ok('tools/dsh'), 'tools/dsh', '允许嵌套');
|
|
937
|
+
for (const raw of ['/abs', 'a/', '/', 'a//b', '..', 'a/../b', './a', 'a/.', '.git', 'a/.git/b', 'a/.GIT', 'a\\b', 'a\u0000b', 123, true]) bad(raw);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
test('issue #131:git 子目录前缀往返 —— 写入保留字段,空/缺省按仓库根读回,旧 v2 文件不受影响', async () => {
|
|
941
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-cfg-subdir-'));
|
|
942
|
+
try {
|
|
943
|
+
const cfg: SyncConfig = {
|
|
944
|
+
schemaVersion: 2,
|
|
945
|
+
transport: 'git',
|
|
946
|
+
git: { repoUrl: 'git@github.com:foo/bar.git', subdir: 'DSH备份' },
|
|
947
|
+
};
|
|
948
|
+
await writeSyncConfig(dir, cfg);
|
|
949
|
+
assert.deepEqual(await readSyncConfig(dir), cfg, '子目录前缀必须原样往返');
|
|
950
|
+
const raw = JSON.parse(await fs.readFile(path.join(dir, SYNC_CONFIG_FILE), 'utf8'));
|
|
951
|
+
assert.equal(raw.git.subdir, 'DSH备份');
|
|
952
|
+
assert.equal(raw.schemaVersion, SYNC_CONFIG_SCHEMA_VERSION, '带新字段的文件按当前版本写');
|
|
953
|
+
|
|
954
|
+
// 旧 v2 文件(无 subdir)→ 读成仓库根布局,不因新字段缺失而丢配置
|
|
955
|
+
await fs.writeFile(path.join(dir, SYNC_CONFIG_FILE), JSON.stringify({
|
|
956
|
+
schemaVersion: 2,
|
|
957
|
+
transport: 'git',
|
|
958
|
+
git: { repoUrl: 'git@github.com:foo/bar.git' },
|
|
959
|
+
}));
|
|
960
|
+
assert.deepEqual(await readSyncConfig(dir), {
|
|
961
|
+
schemaVersion: 2,
|
|
962
|
+
transport: 'git',
|
|
963
|
+
git: { repoUrl: 'git@github.com:foo/bar.git' },
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
// 非法 subdir(历史文件被人改坏)→ 丢弃该字段而不是整份配置报错
|
|
967
|
+
await fs.writeFile(path.join(dir, SYNC_CONFIG_FILE), JSON.stringify({
|
|
968
|
+
schemaVersion: 2,
|
|
969
|
+
transport: 'git',
|
|
970
|
+
git: { repoUrl: 'git@github.com:foo/bar.git', subdir: '../escape' },
|
|
971
|
+
}));
|
|
972
|
+
assert.deepEqual(await readSyncConfig(dir), {
|
|
973
|
+
schemaVersion: 2,
|
|
974
|
+
transport: 'git',
|
|
975
|
+
git: { repoUrl: 'git@github.com:foo/bar.git' },
|
|
976
|
+
}, '非法前缀按仓库根处理(不拿坏值去拼路径)');
|
|
977
|
+
} finally { await fs.rm(dir, { recursive: true, force: true }); }
|
|
978
|
+
});
|
|
979
|
+
|
package/src/sync/sync-config.ts
CHANGED
|
@@ -87,14 +87,26 @@ export function channelMap<T>(make: (channel: SyncTransportType) => T): Record<S
|
|
|
87
87
|
return out;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 当前 sync-config.json schema 版本号(v4:git 通道新增可选 `subdir` 子目录前缀,issue #131)。
|
|
92
|
+
*
|
|
93
|
+
* 为什么必须升版而不是只加一个可选字段:老版本插件读到带 `subdir` 的配置会**丢掉这个字段**
|
|
94
|
+
* 然后照旧往仓库根写快照 —— 在「多工具共用一个备份仓库」的现场,那等于把快照撒进别人的目录布局。
|
|
95
|
+
* 升版后老版本读到 v4 直接判为不支持(显示未配置),宁可让用户看见「要升级」,也不静默写错位置。
|
|
96
|
+
*/
|
|
97
|
+
export const SYNC_CONFIG_SCHEMA_VERSION = 4;
|
|
98
|
+
/** 历史可读取版本:v1、v2、v3、v4。 */
|
|
99
|
+
export const SYNC_CONFIG_SUPPORTED_VERSIONS: readonly number[] = [1, 2, 3, 4];
|
|
94
100
|
|
|
95
101
|
/** git 通道配置(不含任何凭据;git 可执行文件固定使用系统 PATH 中的 git) */
|
|
96
102
|
export interface GitConfig {
|
|
97
103
|
repoUrl: string;
|
|
104
|
+
/**
|
|
105
|
+
* 仓库内子目录前缀(issue #131,可缺省):快照布局落在 `<subdir>/snapshots`、
|
|
106
|
+
* `<subdir>/snapshots-encrypted`、`<subdir>/blobs`。缺省 = 仓库根(历史行为逐字不变)。
|
|
107
|
+
* 多工具共用同一个私有备份仓库时,每个工具各占一个子目录。
|
|
108
|
+
*/
|
|
109
|
+
subdir?: string;
|
|
98
110
|
}
|
|
99
111
|
|
|
100
112
|
/** webdav 通道配置(不含 password;password 走 DSH credentials) */
|
|
@@ -149,7 +161,12 @@ export function isGistConfig(cfg: SyncConfig): cfg is Extract<SyncConfig, { tran
|
|
|
149
161
|
/** 从 v1 扁平形态解析 git 配置;缺 repoUrl → null(gitBin 已废弃:始终使用系统 PATH 中的 git) */
|
|
150
162
|
function parseV1Git(obj: Record<string, unknown>): GitConfig | null {
|
|
151
163
|
if (typeof obj['repoUrl'] !== 'string' || obj['repoUrl'] === '') return null;
|
|
152
|
-
|
|
164
|
+
// issue #131:子目录前缀必须在这里**显式搬运** —— 本函数只构造已知字段,漏搬就是静默丢掉用户配置。
|
|
165
|
+
// 读侧同口径校验:非法值当作「未设置」(落在仓库根),绝不把可疑路径继续交给 git 子进程。
|
|
166
|
+
const subdir = normalizeGitSubdir(obj['subdir']);
|
|
167
|
+
return subdir.ok && subdir.value !== ''
|
|
168
|
+
? { repoUrl: obj['repoUrl'], subdir: subdir.value }
|
|
169
|
+
: { repoUrl: obj['repoUrl'] };
|
|
153
170
|
}
|
|
154
171
|
|
|
155
172
|
/** 从 v2 git 命名空间解析;缺有效 repoUrl → null */
|
|
@@ -917,6 +934,35 @@ export function validateCloudBucket(bucket: string): CloudConfigIssueCode | null
|
|
|
917
934
|
return null;
|
|
918
935
|
}
|
|
919
936
|
|
|
937
|
+
/**
|
|
938
|
+
* git 通道子目录前缀的归一化与校验(issue #131)。
|
|
939
|
+
*
|
|
940
|
+
* 为什么单独一个函数而不是复用 validateCloudPrefix:对象键前缀与仓库内目录名不是同一套约束 ——
|
|
941
|
+
* 目录名要允许 UTF-8(报告者现场就是 `DSH备份/` 这种中文目录)与多级嵌套,而对象键前缀按
|
|
942
|
+
* 存储桶语义只关心「不是绝对路径、没有 ..」。
|
|
943
|
+
*
|
|
944
|
+
* 接受:空串(= 仓库根,历史行为)、UTF-8 段、多级嵌套(`a/b`)。
|
|
945
|
+
* 拒绝:绝对路径(首部 /)、尾部 /、反斜杠、空段(含 `a//b`)、`.` / `..` 段、控制字符、
|
|
946
|
+
* `.git` 段(写进去会撞 git 自己的元数据目录名,任何大小写都算)。
|
|
947
|
+
*/
|
|
948
|
+
export type GitSubdirCheck = { ok: true; value: string } | { ok: false; reason: 'gitSubdirInvalid' };
|
|
949
|
+
|
|
950
|
+
export function normalizeGitSubdir(raw: unknown): GitSubdirCheck {
|
|
951
|
+
// 缺省(字段不存在)与空串同义:仓库根。只有「显式写了但不是字符串」才算非法。
|
|
952
|
+
if (raw === undefined || raw === null) return { ok: true, value: '' };
|
|
953
|
+
if (typeof raw !== 'string') return { ok: false, reason: 'gitSubdirInvalid' };
|
|
954
|
+
const p = raw.trim();
|
|
955
|
+
if (p === '') return { ok: true, value: '' };
|
|
956
|
+
if (p.startsWith('/') || p.endsWith('/')) return { ok: false, reason: 'gitSubdirInvalid' };
|
|
957
|
+
if (p.includes('\\') || /[\u0000-\u001f\u007f]/.test(p)) return { ok: false, reason: 'gitSubdirInvalid' };
|
|
958
|
+
const segments = p.split('/');
|
|
959
|
+
for (const seg of segments) {
|
|
960
|
+
if (seg === '' || seg === '.' || seg === '..') return { ok: false, reason: 'gitSubdirInvalid' };
|
|
961
|
+
if (seg.toLowerCase() === '.git') return { ok: false, reason: 'gitSubdirInvalid' };
|
|
962
|
+
}
|
|
963
|
+
return { ok: true, value: segments.join('/') };
|
|
964
|
+
}
|
|
965
|
+
|
|
920
966
|
/** 对象键前缀校验(可缺省 = 根前缀;不得以 / 开头、不得含 .. / 反斜杠 / 空段)。 */
|
|
921
967
|
export function validateCloudPrefix(prefix: string): CloudConfigIssueCode | null {
|
|
922
968
|
if (typeof prefix !== 'string') return 'cloud.prefixInvalid';
|
|
@@ -9,7 +9,7 @@ import assert from 'node:assert/strict'
|
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
formatRepoUpdatedAt, normalizeRepoUrl, repoCreateBody, repoNameError, repoPickerOptions,
|
|
12
|
-
repoPickerRepos, repoPickerValueFor, repoShortName, REPO_NAME_MAX_LENGTH,
|
|
12
|
+
repoPickerRepos, repoPickerValueFor, repoShortName, shouldAutoLoadRepos, REPO_NAME_MAX_LENGTH,
|
|
13
13
|
REPO_PICKER_CREATE_VALUE, type RepoPickerRepo,
|
|
14
14
|
} from './sync-repository-picker.ts'
|
|
15
15
|
|
|
@@ -128,3 +128,36 @@ test('formatRepoUpdatedAt:空串→空串,非法→原样,合法→本地
|
|
|
128
128
|
assert.ok(shown.includes('2026'), '应包含年份,实际:' + shown)
|
|
129
129
|
assert.ok(!shown.includes('Invalid'), '绝不显示 Invalid Date,实际:' + shown)
|
|
130
130
|
})
|
|
131
|
+
|
|
132
|
+
/* ---------- 仓库列表的自动加载判定(2026-11-08 用户反馈:登录成功后列表不出现、必须手点下拉) */
|
|
133
|
+
|
|
134
|
+
/** 基线:弹窗打开、未登录、地址为空、什么都没加载过 */
|
|
135
|
+
const autoBase = {
|
|
136
|
+
open: true,
|
|
137
|
+
signedIn: null as boolean | null,
|
|
138
|
+
loaded: false,
|
|
139
|
+
loading: false,
|
|
140
|
+
failed: false,
|
|
141
|
+
repoUrl: '',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
test('shouldAutoLoadRepos:登录成功(signedIn true)即自动加载 —— 用户不必再点开下拉', () => {
|
|
145
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true }), true)
|
|
146
|
+
// 已登录 + 表单里已有地址同样自动加载(保持既有行为)
|
|
147
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true, repoUrl: 'https://github.com/u/r.git' }), true)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test('shouldAutoLoadRepos:未登录且地址为空 → 不加载(必然 401,白跑网络)', () => {
|
|
151
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: null }), false)
|
|
152
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: false }), false)
|
|
153
|
+
// 未登录但地址已填:照旧自动拉(既有行为,可能与手填的 token 一起生效)
|
|
154
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: false, repoUrl: ' https://github.com/u/r.git ' }), true)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('shouldAutoLoadRepos:弹窗关闭 / 已加载 / 加载中 / 失败后 → 一律不重复发请求', () => {
|
|
158
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true, open: false }), false)
|
|
159
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true, loaded: true }), false)
|
|
160
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true, loading: true }), false)
|
|
161
|
+
// 失败不自动重试:否则每次重渲染都会打一次必然失败的请求(重试走「刷新列表」或登录态复位)
|
|
162
|
+
assert.equal(shouldAutoLoadRepos({ ...autoBase, signedIn: true, failed: true }), false)
|
|
163
|
+
})
|
|
@@ -178,3 +178,27 @@ export function formatRepoUpdatedAt(iso: string, locale?: string): string {
|
|
|
178
178
|
const date = new Date(ms)
|
|
179
179
|
return locale === undefined ? date.toLocaleString() : date.toLocaleString(locale)
|
|
180
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* 仓库列表是否该**自动加载**(不要求用户先点开下拉)。
|
|
183
|
+
*
|
|
184
|
+
* 用户反馈(2026-11-08):GitHub 登录成功后界面没有任何提示,列表也不会自己出现 ——
|
|
185
|
+
* 必须手动点一下「从我的仓库中选择」才知道成功了。这里把「该拉列表」的判定收成一条纯函数,
|
|
186
|
+
* 三个触发点共用:弹窗打开、登录状态由「未登录」变「已登录」、表单里已经有地址。
|
|
187
|
+
*
|
|
188
|
+
* 规则:
|
|
189
|
+
* - 弹窗没打开 / 已加载过 / 正在加载 → 不重复发请求;
|
|
190
|
+
* - `failed` 为真 → 不自动重试(否则每次重渲染都会打一次必然失败的请求;重试由「刷新列表」或
|
|
191
|
+
* 登录状态变化后的复位负责)。
|
|
192
|
+
* - 未登录且地址为空 → 保持惰性(此时拉列表必然 401,白跑一次网络)。
|
|
193
|
+
*/
|
|
194
|
+
export function shouldAutoLoadRepos(input: {
|
|
195
|
+
open: boolean
|
|
196
|
+
signedIn: boolean | null
|
|
197
|
+
loaded: boolean
|
|
198
|
+
loading: boolean
|
|
199
|
+
failed: boolean
|
|
200
|
+
repoUrl: string
|
|
201
|
+
}): boolean {
|
|
202
|
+
if (!input.open || input.loaded || input.loading || input.failed) return false
|
|
203
|
+
return input.signedIn === true || input.repoUrl.trim() !== ''
|
|
204
|
+
}
|
|
@@ -35,6 +35,7 @@ function form(overrides: Partial<SyncFormSnapshot> = {}): SyncFormSnapshot {
|
|
|
35
35
|
return {
|
|
36
36
|
channel: 'git',
|
|
37
37
|
repoUrl: ' https://github.com/u/repo.git ',
|
|
38
|
+
gitSubdir: '',
|
|
38
39
|
token: ' GIT-TOKEN ',
|
|
39
40
|
webdavUrl: ' https://dav.example.com/dav ',
|
|
40
41
|
webdavUsername: ' alice ',
|
|
@@ -41,6 +41,8 @@ export type SyncAutosyncInterval = '5m' | '15m' | '30m' | '60m' | '6h' | '12h' |
|
|
|
41
41
|
export interface SyncFormSnapshot {
|
|
42
42
|
channel: SyncChannelName
|
|
43
43
|
repoUrl: string
|
|
44
|
+
/** 仓库内子目录前缀(空 = 仓库根;issue #131:多工具共用一个私有仓库时各自独立) */
|
|
45
|
+
gitSubdir: string
|
|
44
46
|
/** 仅内存;成功后由组件清空(已写入 DSH credentials) */
|
|
45
47
|
token: string
|
|
46
48
|
webdavUrl: string
|
|
@@ -102,6 +104,8 @@ export interface SyncPushBody {
|
|
|
102
104
|
*/
|
|
103
105
|
transport?: SyncTransportType
|
|
104
106
|
repoUrl?: string
|
|
107
|
+
/** git:仓库内子目录前缀(issue #131;空 / 缺省 = 仓库根,旧配置读出来即空) */
|
|
108
|
+
subdir?: string
|
|
105
109
|
token?: string
|
|
106
110
|
url?: string
|
|
107
111
|
username?: string
|
|
@@ -293,9 +297,12 @@ function channelAuthBody(form: SyncFormSnapshot, opts: { trimToken: boolean }):
|
|
|
293
297
|
...(token === '' ? {} : { secret: token }),
|
|
294
298
|
}
|
|
295
299
|
}
|
|
300
|
+
const subdir = form.gitSubdir.trim()
|
|
296
301
|
return {
|
|
297
302
|
transport: 'git',
|
|
298
303
|
repoUrl: form.repoUrl.trim(),
|
|
304
|
+
// 空串不携带:宿主按「缺省 = 仓库根」解析,旧配置与旧宿主都能吃这份载荷
|
|
305
|
+
...(subdir === '' ? {} : { subdir }),
|
|
299
306
|
token: form.token.trim() !== '' ? (opts.trimToken ? form.token.trim() : form.token) : undefined,
|
|
300
307
|
}
|
|
301
308
|
}
|