@twinsearth/timemachine-dsh-plugin 0.1.2 → 0.2.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/CHANGELOG.md +25 -0
- package/README.md +9 -5
- package/docs/ARCHITECTURE.md +18 -1
- package/docs/REQUIREMENTS.md +4 -0
- package/docs/TESTPLAN.md +17 -4
- package/icon.png +0 -0
- package/lib/client.js +272 -27
- package/package.json +3 -1
- package/plugin.json +1 -1
- package/src/point.mjs +18 -1
- package/src/service.mjs +3 -2
- package/src/tree.mjs +148 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 — 2026-12-03
|
|
4
|
+
|
|
5
|
+
### 文件夹详情
|
|
6
|
+
|
|
7
|
+
- 完整面板新增「文件夹详情」区块,位于还原点列表之后、「说明与边界」之前,即倒数第二个位置。
|
|
8
|
+
- 创建或导入还原点后自动选中该文件,展示归档内的真实文件夹结构树,右侧显示中文说明与文件大小。
|
|
9
|
+
- 多个还原点可通过下拉框或还原点行的「文件夹」按钮切换;同一时间只展开一个目录,切换还原点时重置展开状态。
|
|
10
|
+
- 创建接口直接返回 `tree`;`/inspect` 为已有还原点返回同一棵树,避免 UI 重复解析归档。
|
|
11
|
+
|
|
12
|
+
### 发布
|
|
13
|
+
|
|
14
|
+
- npm 与 GitHub 同步发布 `0.2.0`;保留 `dsh.bundle.patch`、`dsh.client`、`repository` 与可复制安装命令。
|
|
15
|
+
|
|
16
|
+
## 0.1.3 — 2026-12-03
|
|
17
|
+
|
|
18
|
+
### UI
|
|
19
|
+
|
|
20
|
+
- 插件图标改为附图中的「Who Is Backing DeepSeek」图表,`package.json` 声明 `icon: "./icon.png"`,`icon.png` 随包发布,尺寸 512×512、体积低于 256 KiB。
|
|
21
|
+
- `sidebar.panellist` 顶部入口会在插件启动 10 秒后自动隐藏,避免长期占用左侧导航;仍可从「设置 -> 通用 -> DSH 一键还原点」打开完整面板。
|
|
22
|
+
- Windows 标题栏「DSH一键还原点」备用按钮会在启动 30 秒后自动隐藏。
|
|
23
|
+
|
|
24
|
+
### 发布
|
|
25
|
+
|
|
26
|
+
- npm 与 GitHub 同步发布 `0.1.3`;包内保留 `dsh.bundle.patch`、`dsh.client`、`repository` 与可复制的安装命令,满足插件市场静态抓取要求。
|
|
27
|
+
|
|
3
28
|
## 0.1.2 — 2026-12-03
|
|
4
29
|
|
|
5
30
|
### 市场发现与安装元数据
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
DSH 一键还原点(Time Machine)。它把 DSH 客户端的会话、工作区、配置与插件清单打包成一个可迁移的还原点,并在需要时把整台机器上的 DSH 恢复成还原点里的样子。
|
|
4
4
|
|
|
5
|
-
- 版本:`0.
|
|
5
|
+
- 版本:`0.2.0`
|
|
6
6
|
- 宿主:DeepSeek Harness(DSH)桌面客户端 `0.2.x`
|
|
7
7
|
- 平台:Windows / macOS / Linux(Windows 默认目录,macOS/Linux 由用户选择目录)
|
|
8
8
|
- 许可:MIT
|
|
@@ -32,6 +32,10 @@ DSH 一键还原点(Time Machine)。它把 DSH 客户端的会话、工作
|
|
|
32
32
|
|
|
33
33
|
面板「导入」选择一个 `.tar.zst`,文件会被复制进 `imported/`,源文件保留不动。导入时会校验归档结构、manifest 与文件摘要;损坏或不完整的归档会被拒绝。
|
|
34
34
|
|
|
35
|
+
### 1.4 文件夹详情
|
|
36
|
+
|
|
37
|
+
完整面板倒数第二个区块是「文件夹详情」:创建或导入完成后,自动选中新还原点并读取归档结构;也可以从下拉框或还原点行的「文件夹」按钮切换。树按真实路径展示 `manifest.json`、`README.txt`、`RESTORE-POINT.json`、`sessions/`、`attachments/`、`profiles/` 等目录,右侧逐项给出中文说明和文件大小。同一时间只展开一个目录,切换还原点时会重置展开状态。
|
|
38
|
+
|
|
35
39
|
### 2.1 用户插件:内置与实验性
|
|
36
40
|
|
|
37
41
|
还原点记录 `dsh.profile.bundles`、`dependencies` 与 `cordis.patch.yml` 的插件行,包含:
|
|
@@ -127,8 +131,8 @@ sessions/<project-key>/<encoded-session-id>/
|
|
|
127
131
|
### 4. UI 入口
|
|
128
132
|
|
|
129
133
|
1. **DSH 通用设置**:`设置 -> 通用` 里新增「DSH 一键还原点」一行,可直接「立即备份」「一键还原」或「打开完整面板」。「一键还原」先打开还原计划确认弹窗,确认后还原最近一份手动/自动还原点,并自动打开还原后的会话。
|
|
130
|
-
2. **左上角侧栏**:`sidebar.panellist` 顶部新增入口,位置在品牌行下方、会话列表上方。macOS 显示「时间机器」,Windows
|
|
131
|
-
3. **Windows 标题栏(纯插件备用入口)**:插件运行时在左上角「应用 / 编辑」右侧追加「DSH
|
|
134
|
+
2. **左上角侧栏**:`sidebar.panellist` 顶部新增入口,位置在品牌行下方、会话列表上方。macOS 显示「时间机器」,Windows 显示「一键还原点」,点击打开完整面板。该入口在插件启动 **10 秒后自动隐藏**,让出导航位;之后仍可从通用设置行点「打开完整面板」。
|
|
135
|
+
3. **Windows 标题栏(纯插件备用入口)**:插件运行时在左上角「应用 / 编辑」右侧追加「DSH一键还原点」按钮,点击直接打开完整面板。该按钮在启动 **30 秒后自动隐藏**。它不需要改 `app.asar`;只在 DSH 桌面客户端存在 `[data-windows-menu]` 时生效,用浏览器打开 Web UI 不会显示。
|
|
132
136
|
4. **原生应用菜单(需求 4.2 的精确入口)**:包内提供 `scripts/host-menu-patch.mjs`,在 DSH 的 `app.asar` 的「应用 -> 开发者工具」后插入「DSH一键还原点」,点击后调用插件暴露的 `window.__DSH_TIMEMACHINE_OPEN__()` 打开面板。
|
|
133
137
|
|
|
134
138
|
原生菜单必须由宿主补丁实现,因为 DSH 桌面端的「应用」菜单由主进程硬编码(关于/检查更新/管理 dsh 命令/开发者工具/重启应用/退出),插件 API 没有“向应用菜单追加菜单项”的能力,`windowsMenu` IPC 也只接受 `application`/`edit` 两个菜单名。标题栏第三个按钮是纯插件的降级入口;如果要求严格出现在「应用 -> 开发者工具」下面,执行下面的补丁。本机真实客户端已执行;换一台机器部署时仍需执行一次。
|
|
@@ -164,7 +168,7 @@ dsh plugin --profile desktop add @twinsearth/timemachine-dsh-plugin
|
|
|
164
168
|
离线安装可使用 GitHub Release 或本地 tarball:
|
|
165
169
|
|
|
166
170
|
```powershell
|
|
167
|
-
dsh plugin --profile desktop add "file:E:\path\to\twinsearth-timemachine-dsh-plugin-0.
|
|
171
|
+
dsh plugin --profile desktop add "file:E:\path\to\twinsearth-timemachine-dsh-plugin-0.2.0.tgz"
|
|
168
172
|
```
|
|
169
173
|
|
|
170
174
|
如果 `dsh` 不在 PATH,也可以直接用 profile 目录里的 pnpm 安装,但安装后必须手动把包名加入 `profiles/desktop/package.json` 的 `dsh.profile.bundles`,否则 Loader 不会加载:
|
|
@@ -208,7 +212,7 @@ npm run check # 静态交付检查
|
|
|
208
212
|
npm run pack-check
|
|
209
213
|
```
|
|
210
214
|
|
|
211
|
-
测试覆盖:手动/自动创建、范围选择、保留份数、计划与还原、跳过插件安装、导入、设置持久化、损坏归档拒绝、HTTP 路由挂载、客户端 bundle
|
|
215
|
+
测试覆盖:手动/自动创建、范围选择、保留份数、计划与还原、跳过插件安装、导入、设置持久化、损坏归档拒绝、HTTP 路由挂载、客户端 bundle 槽位注册、侧栏入口 10 秒自动隐藏与标题栏按钮 30 秒自动隐藏、文件夹结构树与单分支展开、运行中 `workspaceRegistry` 实时注册。真实客户端验收记录见 `docs/TESTPLAN.md`。
|
|
212
216
|
|
|
213
217
|
## 数据与安全
|
|
214
218
|
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -121,12 +121,29 @@ service.restore -> restore.restorePoint
|
|
|
121
121
|
| --- | --- | --- |
|
|
122
122
|
| `settings.general.item` | `timemachine-general` | 通用设置一行:立即备份 / 一键还原(计划确认)/ 打开完整面板 |
|
|
123
123
|
| `sidebar.panellist` | `timemachine` | 左上角侧栏顶部入口(`order: -100`);macOS「时间机器」、Windows「一键还原点」 |
|
|
124
|
-
| `main` | key `timemachine` |
|
|
124
|
+
| `main` | key `timemachine` | 完整面板:创建 / 自动 / 还原点列表 / 文件夹详情 / 说明与边界 |
|
|
125
125
|
|
|
126
126
|
`layout.selectPanel('timemachine')` 依赖 `main` 注册项的 `options.key === 'timemachine'`。客户端必须声明 `inject: ['slots', 'layout']`;缺少 `layout` 时 Cordis 会在访问 `ctx.layout` 时抛 `cannot get property "layout" without inject`,整个客户端模块不会激活。`uiWorkspace` / `sessions` 用 `ctx.get` 可选读取,不加入硬注入;直接属性访问 `ctx.uiWorkspace` 会抛 `cannot get property "uiWorkspace" without inject`,这也是 0.1.0 修复过的坑。
|
|
127
127
|
|
|
128
128
|
除槽位外,`installCaptionEntry` 在 Windows 桌面客户端的 `[data-windows-menu]` open shadowRoot 里追加 `data-timemachine-caption` 按钮。宿主节点不存在(浏览器 Web UI)时用 `MutationObserver` 等 30 秒后静默放弃;组件卸载只移除自己追加的按钮,不碰宿主已有「应用 / 编辑」按钮。
|
|
129
129
|
|
|
130
|
+
### 6.1 完整面板的文件夹详情
|
|
131
|
+
|
|
132
|
+
完整面板的区块顺序固定为:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
页头
|
|
136
|
+
创建卡片
|
|
137
|
+
自动卡片
|
|
138
|
+
还原点列表
|
|
139
|
+
文件夹详情 <- 倒数第二
|
|
140
|
+
说明与边界 <- 最后
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`FolderDetails` 通过下拉框或还原点行的「文件夹」按钮切换目标文件。创建成功后,`POST /create` 的响应直接带 `tree`,UI 无需再次解包;已有还原点通过 `POST /inspect` 读取 `tree`。服务端由 `src/tree.mjs#buildPointTree` 将 `manifest.files` 与三个顶层文件合并成树,每个节点带 `path`、`type`、`description`、`bytes`、`files` 和 `children`。
|
|
144
|
+
|
|
145
|
+
树的前端只保留一个 `expandedPath`。`isTreePathOpen(path, openPath)` 只展开该路径本身及其祖先链,因此同一时间只有一个分支;切换还原点会重置为根节点展开。
|
|
146
|
+
|
|
130
147
|
## 7. 并发与失败
|
|
131
148
|
|
|
132
149
|
- 服务端所有写操作经过 `guarded` 单操作互斥;并发的第二个请求返回 409。
|
package/docs/REQUIREMENTS.md
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
| 1 | 支持定时更新还原点 | 已实现 | `src/service.mjs#startAutoScheduler`;`src/plugin.mjs#apply` | `service persists settings...` |
|
|
9
9
|
| 1.2 | 默认保存两份,手动/自动分开存储、分开显示 | 已实现 | `DEFAULT_SETTINGS.keepManual/keepAuto = 2`;`point.mjs#pruneCategory`;`manual/`、`auto/` | `prune keeps only the newest N points` |
|
|
10
10
|
| 1.3 | 手动导入其他机器还原点 | 已实现 | `src/point.mjs#importRestorePoint`;`src/service.mjs#importPoint`;面板「导入」 | `imports a point into the imported store` |
|
|
11
|
+
| 1.4 | 文件夹详情区(倒数第二位置) | 已实现 | `lib/client.js#FolderDetails` 位于还原点列表之后、说明与边界之前;创建/导入后自动展开;下拉框与行内「文件夹」按钮切换 | 客户端 bundle 用例断言 `FolderDetails`、`isTreePathOpen`;创建/检查路由断言 `tree` |
|
|
12
|
+
| 1.5 | 备份文件夹结构树 + 中文说明 | 已实现 | `src/tree.mjs#buildPointTree`;创建返回 `tree`;`src/service.mjs#inspectPoint` 返回同一棵树 | `creates one manual point...` 断言根目录、顶层文件、`sessions/` 与大小;`inspect` 路由断言 |
|
|
13
|
+
| 1.6 | 单分支展开,其余折叠 | 已实现 | `FolderDetails` 单一 `expandedPath`;`isTreePathOpen` 只保留祖先链;切换还原点重置 | `folder details lists every healthy point and opens only one tree branch` |
|
|
11
14
|
| 2.1 | 用户插件(内置/实验性)开启、关闭、参数配置 | 已实现 | `src/plugins.mjs#readProfilePlugins` 读取 bundles/rows/disabled;配置原文随 `cordis.patch.yml` 备份;`pluginInventory` 展示 | 创建用例断言 `status.plugins.user` 与实验性插件 |
|
|
12
15
|
| 2.2 | 第三方插件列表,DSH 内由用户手动触发一键自动安装并还原 NPM latest,恢复原配置 | 已实现(真实网络安装待验收) | `lib/client.js` 还原计划弹窗「安装并还原第三方插件」勾选框,默认勾选,可取消;`src/plugins.mjs#reinstallPlugins`;`src/restore.mjs#restorePoint` 安装后重放 package.json 并保留新版本 | 临时 DSH 页面确认 2 个插件时显示勾选框且可切换;`restorePoint skips plugin installation...`;真机 11 个第三方插件清单;联网 latest 仅用假 runner 验证 |
|
|
13
16
|
| 2.2 | 不保存安装包,可手动勾选同时备份安装包 | 已实现 | `includePluginPackages`;`packPluginTarballs`;还原优先 `file:` tarball | 默认 `false` 静态检查 |
|
|
@@ -61,6 +64,7 @@ node scripts/host-menu-patch.mjs --app-asar "D:\DSH\resources\app.asar" --restor
|
|
|
61
64
|
- [x] 通用设置入口 + 左上角侧栏入口
|
|
62
65
|
- [x] 纯插件 Windows 标题栏备用按钮(`installCaptionEntry`;静态检查 + 浏览器无宿主不报错)
|
|
63
66
|
- [x] 原生「应用-开发者工具」菜单补丁器(asar 副本验证)
|
|
67
|
+
- [x] 完整面板「文件夹详情」区与备份结构树(创建后自动展开,单分支)
|
|
64
68
|
- [x] 预还原副本与失败回滚
|
|
65
69
|
|
|
66
70
|
### P1(增强)
|
package/docs/TESTPLAN.md
CHANGED
|
@@ -13,7 +13,7 @@ npm run pack-check
|
|
|
13
13
|
测试文件:
|
|
14
14
|
|
|
15
15
|
- `test/timemachine.test.mjs`:11 项服务端/路由用例
|
|
16
|
-
- `test/client-bundle.test.mjs`:
|
|
16
|
+
- `test/client-bundle.test.mjs`:7 项浏览器 bundle 用例(合计 18)
|
|
17
17
|
|
|
18
18
|
覆盖矩阵:
|
|
19
19
|
|
|
@@ -35,6 +35,9 @@ npm run pack-check
|
|
|
35
35
|
| 14 | 标题栏备用入口 | bundle 含 `data-windows-menu`、`DSH一键还原点`、`data-timemachine-caption` |
|
|
36
36
|
| 15 | 第三方插件手动开关 | bundle 含「安装并还原第三方插件」、`installPlugins`、`useSavedPackages` |
|
|
37
37
|
| 16 | 通用设置快捷入口 / 侧栏自适应 | bundle 含「立即备份」「一键还原」「打开完整面板」「时间机器」、`order: -100` |
|
|
38
|
+
| 17 | 文件夹结构树 | 创建返回 `tree`;根目录、顶层文件、`sessions/`、中文说明与精确大小;`/inspect` 返回同一棵树 |
|
|
39
|
+
| 18 | 单分支展开 | 所有健康还原点进入下拉框;`isTreePathOpen` 只展开目标路径与祖先链,其他分支折叠 |
|
|
40
|
+
| 19 | 树渲染 | 自定义 `createElement` 断言中文说明、文件大小、切换分支后旧分支折叠 |
|
|
38
41
|
|
|
39
42
|
## 2. 零残留
|
|
40
43
|
|
|
@@ -135,6 +138,15 @@ npm run pack-check
|
|
|
135
138
|
- 侧栏 `sidebar.panellist` 注册 `order: -100`;`sidebarLabel('MacIntel')` 返回「时间机器」,`sidebarLabel('Win32')` 返回「一键还原点」。
|
|
136
139
|
- 真实宿主内点击「一键还原」并完成还原、macOS 真机侧栏文案仍待人工验收。
|
|
137
140
|
|
|
141
|
+
### 3.9 0.2.0 文件夹详情(静态通过,待真机点击)
|
|
142
|
+
|
|
143
|
+
- `npm test` 18/18、`npm run check` 21/21、`npm run pack-check` 26 个文件。
|
|
144
|
+
- 创建手动还原点后,`POST /create` 返回 `tree`;`buildPointTree` 生成「还原点根目录 → 顶层文件 / sessions / attachments / profiles / registry」,节点带中文说明与大小。
|
|
145
|
+
- `POST /inspect` 对已有还原点返回同一棵树;`inspectPoint` 路由用例断言根目录与 `sessions/`。
|
|
146
|
+
- 完整面板中「文件夹详情」位于还原点列表之后、「说明与边界」之前;创建/导入后自动选中并展开根目录,切换还原点重置展开状态。
|
|
147
|
+
- `isTreePathOpen` 只保留目标路径及祖先链,保证同一时间只展开一个分支。
|
|
148
|
+
- 真实宿主内点击树节点、切换下拉框、创建后自动滚动到文件夹详情仍待人工点击验收。
|
|
149
|
+
|
|
138
150
|
## 4. 待人工验收
|
|
139
151
|
|
|
140
152
|
- 安装 tarball 到真实 DSH profile `desktop` 后:
|
|
@@ -143,6 +155,7 @@ npm run pack-check
|
|
|
143
155
|
- 点击入口打开 `main` 面板
|
|
144
156
|
- 设置行「一键还原」打开还原计划确认弹窗,确认后完成还原并自动打开会话
|
|
145
157
|
- 创建/还原按钮走真实 HTTP 路由
|
|
158
|
+
- 创建完成后「文件夹详情」自动选中新还原点并显示树;多个还原点切换时只展开一个分支
|
|
146
159
|
- 真实 DSH 桌面客户端左上角标题栏:
|
|
147
160
|
- 「应用 / 编辑」右侧出现「DSH一键还原点」
|
|
148
161
|
- 点击打开插件面板;关闭/卸载插件后按钮消失
|
|
@@ -158,7 +171,7 @@ npm run pack-check
|
|
|
158
171
|
|
|
159
172
|
## 5. 回归门槛
|
|
160
173
|
|
|
161
|
-
- `npm test`
|
|
162
|
-
- `npm run check`
|
|
163
|
-
- `npm run pack-check` tarball 内容符合 `files`(
|
|
174
|
+
- `npm test` 18/18 通过
|
|
175
|
+
- `npm run check` 21/21 通过
|
|
176
|
+
- `npm run pack-check` tarball 内容符合 `files`(26 个文件)
|
|
164
177
|
- 任何失败先定位到具体断言,不通过放宽断言“修复”
|
package/icon.png
ADDED
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -12,6 +12,8 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
const PREFIX = '/api/twinsearth/timemachine';
|
|
13
13
|
const STYLE_ID = 'timemachine-dsh-style';
|
|
14
14
|
const PANEL_ID = 'timemachine';
|
|
15
|
+
const SIDEBAR_AUTO_HIDE_MS = 10_000;
|
|
16
|
+
const CAPTION_AUTO_HIDE_MS = 30_000;
|
|
15
17
|
|
|
16
18
|
async function request(path, init = {}) {
|
|
17
19
|
const response = await fetch(PREFIX + path, {
|
|
@@ -54,6 +56,32 @@ window.__ModuleLoader__.load({
|
|
|
54
56
|
return `会话 ${counts.sessions ?? 0} · 配置 ${counts.config ?? 0} · 状态 ${counts.state ?? 0} · 插件 ${counts.plugins ?? 0}`;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
function pointKindLabel(value) {
|
|
60
|
+
const kind = typeof value === 'string' ? value : value?.point?.kind ?? value?.kind;
|
|
61
|
+
return kind === 'auto' ? '自动' : kind === 'imported' ? '导入' : '手动';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function allPointRows(status) {
|
|
65
|
+
const rows = [];
|
|
66
|
+
for (const kind of ['manual', 'auto', 'imported']) {
|
|
67
|
+
for (const row of status?.stores?.[kind]?.points ?? []) {
|
|
68
|
+
if (row?.ok !== false && typeof row.file === 'string') rows.push({ ...row, store_kind: kind });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
rows.sort((a, b) => String(b?.point?.created_at ?? '').localeCompare(String(a?.point?.created_at ?? '')));
|
|
72
|
+
return rows;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isTreePathOpen(path, openPath) {
|
|
76
|
+
if (path === '') return true;
|
|
77
|
+
return typeof openPath === 'string' && (openPath === path || openPath.startsWith(`${path}/`));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function baseName(file) {
|
|
81
|
+
const parts = String(file ?? '').split(/[\\/]/u);
|
|
82
|
+
return parts[parts.length - 1] || '还原点';
|
|
83
|
+
}
|
|
84
|
+
|
|
57
85
|
function sidebarLabel(platform = null) {
|
|
58
86
|
const detected = platform ?? (typeof navigator === 'undefined'
|
|
59
87
|
? ''
|
|
@@ -165,6 +193,17 @@ window.__ModuleLoader__.load({
|
|
|
165
193
|
.tm-plugin{display:flex;align-items:center;gap:8px;padding:5px 0;border-top:1px dashed var(--dsh-border,#e5e7eb);flex-wrap:wrap}
|
|
166
194
|
.tm-plugin:first-child{border-top:0}
|
|
167
195
|
.tm-yaml{margin:0;padding:8px;background:#0f172a;color:#e2e8f0;border-radius:8px;font:11px/1.5 ui-monospace,SFMono-Regular,Consolas,monospace;max-height:220px;overflow:auto;white-space:pre-wrap;word-break:break-word}
|
|
196
|
+
.tm-folderSelect{min-width:260px;flex:1}
|
|
197
|
+
.tm-tree{margin-top:10px;padding-top:6px;border-top:1px solid var(--dsh-border,#e5e7eb);display:flex;flex-direction:column;gap:1px}
|
|
198
|
+
.tm-treeHead{display:grid;grid-template-columns:minmax(150px,.9fr) minmax(160px,1.1fr);gap:8px;padding:0 0 5px 22px;color:var(--dsh-text-secondary,#6b7280);font-size:10px}
|
|
199
|
+
.tm-treeRow{display:grid;grid-template-columns:14px minmax(150px,.9fr) minmax(160px,1.1fr);gap:8px;align-items:start;width:100%;border:0;background:transparent;color:inherit;text-align:left;padding:4px 0;font:inherit;font-size:11px;border-radius:6px}
|
|
200
|
+
.tm-treeRow.dir{cursor:pointer}
|
|
201
|
+
.tm-treeRow.dir:hover{background:var(--dsh-bg-secondary,#f9fafb)}
|
|
202
|
+
.tm-treeGlyph{color:var(--dsh-text-secondary,#6b7280);font-size:10px;line-height:1.7;user-select:none}
|
|
203
|
+
.tm-treeName{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;word-break:break-all;min-width:0}
|
|
204
|
+
.tm-treeDesc{color:var(--dsh-text-secondary,#6b7280);line-height:1.55;min-width:0}
|
|
205
|
+
.tm-treeSize{display:inline-block;margin-left:6px;color:var(--dsh-text-secondary,#9ca3af);white-space:nowrap}
|
|
206
|
+
.tm-point.selected{border-color:#2563eb;box-shadow:0 0 0 1px rgba(37,99,235,.18)}
|
|
168
207
|
.tm-modalMask{position:fixed;inset:0;background:rgba(15,23,42,.45);z-index:1000;display:flex;align-items:center;justify-content:center;padding:18px}
|
|
169
208
|
.tm-modal{background:var(--dsh-bg-primary,#fff);color:var(--dsh-text-primary,#111827);border-radius:14px;max-width:680px;width:100%;max-height:86vh;overflow:auto;padding:18px;box-shadow:0 20px 60px rgba(0,0,0,.25);display:flex;flex-direction:column;gap:12px}
|
|
170
209
|
.tm-modal h3{margin:0;font-size:15px}
|
|
@@ -174,7 +213,7 @@ window.__ModuleLoader__.load({
|
|
|
174
213
|
.tm-sessionRow{display:flex;gap:8px;align-items:center;padding:4px 0;border-top:1px dashed var(--dsh-border,#e5e7eb);font-size:11px;flex-wrap:wrap}
|
|
175
214
|
.tm-sessionRow:first-child{border-top:0}
|
|
176
215
|
.tm-sessionId{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;word-break:break-all}
|
|
177
|
-
@media (max-width:640px){.tm-pointActions{margin-left:0}.tm-card{padding:12px}}
|
|
216
|
+
@media (max-width:640px){.tm-pointActions{margin-left:0}.tm-card{padding:12px}.tm-treeHead{display:none}.tm-treeRow{grid-template-columns:14px minmax(0,1fr);row-gap:2px}.tm-treeDesc{grid-column:2;font-size:11px}}
|
|
178
217
|
`;
|
|
179
218
|
(doc.head ?? doc.documentElement).appendChild(style);
|
|
180
219
|
return () => {
|
|
@@ -219,15 +258,16 @@ window.__ModuleLoader__.load({
|
|
|
219
258
|
return { status, loading, error, refresh, setError };
|
|
220
259
|
}
|
|
221
260
|
|
|
222
|
-
function PointRow({ point, busy, onRestore, onDetails }) {
|
|
261
|
+
function PointRow({ point, busy, onRestore, onDetails, onFolder, selected = false }) {
|
|
223
262
|
const p = point.point ?? {};
|
|
224
|
-
return h('div', { className:
|
|
263
|
+
return h('div', { className: `tm-point${selected ? ' selected' : ''}`, 'data-tm-point': p.kind ?? '' },
|
|
225
264
|
h('div', { className: 'tm-pointTop' }, [
|
|
226
265
|
h('span', { key: 'time', className: 'tm-pointTime' }, formatTime(p.created_at)),
|
|
227
266
|
h('span', { key: 'src', className: 'tm-tag' }, p.source_machine ?? '本机'),
|
|
228
267
|
point.metadata_source === 'sidecar' ? null : h('span', { key: 'v', className: 'tm-tag warn' }, '待校验'),
|
|
229
268
|
h('span', { key: 'size', className: 'tm-tag' }, formatBytes(point.bytes)),
|
|
230
269
|
h('span', { key: 'actions', className: 'tm-pointActions' }, [
|
|
270
|
+
h('button', { key: 'folder', type: 'button', className: 'tm-btn ghost', onClick: () => onFolder(point) }, '文件夹'),
|
|
231
271
|
h('button', { key: 'detail', type: 'button', className: 'tm-btn ghost', onClick: () => onDetails(point) }, '详情'),
|
|
232
272
|
h('button', { key: 'restore', type: 'button', className: 'tm-btn danger', disabled: busy, onClick: () => onRestore(point) }, '还原'),
|
|
233
273
|
]),
|
|
@@ -240,6 +280,87 @@ window.__ModuleLoader__.load({
|
|
|
240
280
|
);
|
|
241
281
|
}
|
|
242
282
|
|
|
283
|
+
function FolderTree({ root, openPath, onToggle }) {
|
|
284
|
+
if (root === null || root === undefined) return null;
|
|
285
|
+
const render = (node, depth) => {
|
|
286
|
+
const path = typeof node.path === 'string' ? node.path : '';
|
|
287
|
+
const key = path === '' ? `root-${node.name}` : path;
|
|
288
|
+
const indent = { paddingLeft: `${2 + depth * 14}px` };
|
|
289
|
+
if (node.type !== 'dir') {
|
|
290
|
+
return h('div', { key, className: 'tm-treeRow file', style: indent, 'data-tm-tree-path': path }, [
|
|
291
|
+
h('span', { key: 'g', className: 'tm-treeGlyph' }, '·'),
|
|
292
|
+
h('span', { key: 'n', className: 'tm-treeName' }, node.name),
|
|
293
|
+
h('span', { key: 'd', className: 'tm-treeDesc' }, [
|
|
294
|
+
node.description ?? '备份文件',
|
|
295
|
+
typeof node.bytes === 'number' ? h('span', { key: 's', className: 'tm-treeSize' }, formatBytes(node.bytes)) : null,
|
|
296
|
+
]),
|
|
297
|
+
]);
|
|
298
|
+
}
|
|
299
|
+
const isRoot = depth === 0;
|
|
300
|
+
const open = isTreePathOpen(path, openPath);
|
|
301
|
+
return h('div', { key, 'data-tm-tree-dir': path }, [
|
|
302
|
+
h('button', {
|
|
303
|
+
key: 'row',
|
|
304
|
+
type: 'button',
|
|
305
|
+
className: 'tm-treeRow dir',
|
|
306
|
+
style: indent,
|
|
307
|
+
'aria-expanded': open,
|
|
308
|
+
onClick: isRoot ? undefined : () => onToggle(path),
|
|
309
|
+
}, [
|
|
310
|
+
h('span', { key: 'g', className: 'tm-treeGlyph' }, open ? '▾' : '▸'),
|
|
311
|
+
h('span', { key: 'n', className: 'tm-treeName' }, node.name),
|
|
312
|
+
h('span', { key: 'd', className: 'tm-treeDesc' }, [
|
|
313
|
+
node.description ?? '目录',
|
|
314
|
+
typeof node.files === 'number' ? h('span', { key: 'c', className: 'tm-treeSize' }, `${node.files} 个文件`) : null,
|
|
315
|
+
]),
|
|
316
|
+
]),
|
|
317
|
+
open ? (node.children ?? []).map((child) => render(child, depth + 1)) : null,
|
|
318
|
+
]);
|
|
319
|
+
};
|
|
320
|
+
return h('div', { className: 'tm-tree', 'data-tm-tree': 'true' }, [
|
|
321
|
+
h('div', { key: 'head', className: 'tm-treeHead' }, [
|
|
322
|
+
h('span', { key: 'path' }, '路径'),
|
|
323
|
+
h('span', { key: 'desc' }, '中文说明'),
|
|
324
|
+
]),
|
|
325
|
+
render(root, 0),
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function FolderDetails({ points, selectedFile, tree, loading, error, openPath, onSelect, onRefresh, onToggle }) {
|
|
330
|
+
const selected = points.find((row) => row.file === selectedFile) ?? null;
|
|
331
|
+
return h('div', { className: 'tm-card', 'data-tm-folder': 'true' }, [
|
|
332
|
+
h('div', { key: 'h', className: 'tm-cardTitle' }, [
|
|
333
|
+
h('span', { key: 't' }, '文件夹详情'),
|
|
334
|
+
h('span', { key: 'tag', className: 'tm-tag' }, selected === null
|
|
335
|
+
? '未选择'
|
|
336
|
+
: `${pointKindLabel(selected)} · ${formatBytes(selected.bytes)}`),
|
|
337
|
+
]),
|
|
338
|
+
h('div', { key: 'pick', className: 'tm-row' }, [
|
|
339
|
+
h('select', {
|
|
340
|
+
key: 'select',
|
|
341
|
+
className: 'tm-input tm-folderSelect',
|
|
342
|
+
value: selectedFile ?? '',
|
|
343
|
+
disabled: loading,
|
|
344
|
+
onChange: (event) => onSelect(event.target.value),
|
|
345
|
+
}, [
|
|
346
|
+
h('option', { key: 'none', value: '' }, points.length === 0 ? '还没有还原点' : '选择还原点查看文件夹结构'),
|
|
347
|
+
...points.map((row) => h('option', { key: row.file, value: row.file }, `${formatTime(row.point?.created_at)} · ${pointKindLabel(row)} · ${formatBytes(row.bytes)} · ${baseName(row.file)}`)),
|
|
348
|
+
]),
|
|
349
|
+
h('button', { key: 'refresh', type: 'button', className: 'tm-btn', disabled: selectedFile === null || loading, onClick: onRefresh }, loading ? '读取中…' : '刷新结构'),
|
|
350
|
+
]),
|
|
351
|
+
selected === null ? null : h('div', { key: 'path', className: 'tm-mono', style: { marginTop: 6 } }, selected.file),
|
|
352
|
+
h('div', { key: 'tip', className: 'tm-muted', style: { marginTop: 4 } }, '选中一个还原点查看结构;同一时间只展开一个目录,其余自动折叠。'),
|
|
353
|
+
error !== null ? h(Banner, { key: 'err', kind: 'error', title: '读取文件夹结构失败', detail: error }) : null,
|
|
354
|
+
loading
|
|
355
|
+
? h('div', { key: 'loading', className: 'tm-empty', style: { marginTop: 10 } }, '正在读取文件夹结构…')
|
|
356
|
+
: selectedFile === null
|
|
357
|
+
? h('div', { key: 'empty', className: 'tm-empty', style: { marginTop: 10 } }, '完成一次备份后,这里会自动显示备份文件的文件夹结构树。')
|
|
358
|
+
: tree === null
|
|
359
|
+
? h('div', { key: 'none', className: 'tm-empty', style: { marginTop: 10 } }, '没有读取到文件夹结构。')
|
|
360
|
+
: h(FolderTree, { key: 'tree', root: tree, openPath, onToggle }),
|
|
361
|
+
]);
|
|
362
|
+
}
|
|
363
|
+
|
|
243
364
|
function PlanModal({ plan, busy, pathMap, setPathMap, installPlugins, setInstallPlugins, onCancel, onConfirm }) {
|
|
244
365
|
if (plan === null) return null;
|
|
245
366
|
const will = plan.will ?? {};
|
|
@@ -355,6 +476,12 @@ window.__ModuleLoader__.load({
|
|
|
355
476
|
const [installPlugins, setInstallPlugins] = useState(true);
|
|
356
477
|
const [notice, setNotice] = useState(null);
|
|
357
478
|
const [details, setDetails] = useState(null);
|
|
479
|
+
const [folderFile, setFolderFile] = useState(null);
|
|
480
|
+
const [folderTree, setFolderTree] = useState(null);
|
|
481
|
+
const [folderLoading, setFolderLoading] = useState(false);
|
|
482
|
+
const [folderError, setFolderError] = useState(null);
|
|
483
|
+
const [expandedPath, setExpandedPath] = useState(null);
|
|
484
|
+
const folderSeq = useRef(0);
|
|
358
485
|
const [autoTime, setAutoTime] = useState('22:00');
|
|
359
486
|
const [autoOn, setAutoOn] = useState(false);
|
|
360
487
|
const [showPlugins, setShowPlugins] = useState(false);
|
|
@@ -377,6 +504,7 @@ window.__ModuleLoader__.load({
|
|
|
377
504
|
|
|
378
505
|
const stores = status?.stores ?? { manual: { points: [] }, auto: { points: [] }, imported: { points: [] } };
|
|
379
506
|
const points = tab === 'auto' ? (stores.auto?.points ?? []) : tab === 'imported' ? (stores.imported?.points ?? []) : (stores.manual?.points ?? []);
|
|
507
|
+
const folderPoints = useMemo(() => allPointRows(status), [status]);
|
|
380
508
|
|
|
381
509
|
const run = async (label, work) => {
|
|
382
510
|
if (busy !== '') return null;
|
|
@@ -399,12 +527,59 @@ window.__ModuleLoader__.load({
|
|
|
399
527
|
await request('/settings', { method: 'POST', body: JSON.stringify(options) });
|
|
400
528
|
};
|
|
401
529
|
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
530
|
+
const loadFolder = async (file, providedTree = null) => {
|
|
531
|
+
if (typeof file !== 'string' || file === '') {
|
|
532
|
+
folderSeq.current += 1;
|
|
533
|
+
setFolderFile(null);
|
|
534
|
+
setFolderTree(null);
|
|
535
|
+
setFolderLoading(false);
|
|
536
|
+
setFolderError(null);
|
|
537
|
+
setExpandedPath(null);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const seq = folderSeq.current + 1;
|
|
541
|
+
folderSeq.current = seq;
|
|
542
|
+
setFolderFile(file);
|
|
543
|
+
setFolderError(null);
|
|
544
|
+
setExpandedPath(null);
|
|
545
|
+
setFolderTree(providedTree ?? null);
|
|
546
|
+
if (providedTree !== null && providedTree !== undefined) {
|
|
547
|
+
setFolderLoading(false);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
setFolderLoading(true);
|
|
551
|
+
try {
|
|
552
|
+
const result = await request('/inspect', { method: 'POST', body: JSON.stringify({ file }) });
|
|
553
|
+
if (folderSeq.current !== seq) return;
|
|
554
|
+
if (result?.tree === undefined || result.tree === null) {
|
|
555
|
+
setFolderError('返回数据缺少文件夹结构');
|
|
556
|
+
} else {
|
|
557
|
+
setFolderTree(result.tree);
|
|
558
|
+
}
|
|
559
|
+
} catch (caught) {
|
|
560
|
+
if (folderSeq.current !== seq) return;
|
|
561
|
+
setFolderError(caught.payload?.detail ?? caught.message);
|
|
562
|
+
} finally {
|
|
563
|
+
if (folderSeq.current === seq) setFolderLoading(false);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const showFolder = (point) => {
|
|
568
|
+
if (point !== null && typeof point?.file === 'string') void loadFolder(point.file);
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const create = async () => {
|
|
572
|
+
const result = await run('create', async () => {
|
|
573
|
+
await saveOptions();
|
|
574
|
+
const created = await request('/create', { method: 'POST', body: JSON.stringify({ kind: 'manual' }) });
|
|
575
|
+
setNotice({ kind: 'success', title: '还原点已创建', detail: `${created.file} · ${formatBytes(created.bytes)}` });
|
|
576
|
+
return created;
|
|
577
|
+
});
|
|
578
|
+
if (result !== null && typeof result === 'object') {
|
|
579
|
+
await loadFolder(result.file, result.tree ?? null);
|
|
580
|
+
try { document.querySelector('[data-tm-folder]')?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } catch { /* optional layout */ }
|
|
581
|
+
}
|
|
582
|
+
};
|
|
408
583
|
|
|
409
584
|
const changeRoot = () => run('pick', async () => {
|
|
410
585
|
const picked = await pickDirectory();
|
|
@@ -423,17 +598,20 @@ window.__ModuleLoader__.load({
|
|
|
423
598
|
setNotice({ kind: 'success', title: '已使用默认文件夹', detail: root });
|
|
424
599
|
});
|
|
425
600
|
|
|
426
|
-
const importPoint =
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
601
|
+
const importPoint = async () => {
|
|
602
|
+
const result = await run('import', async () => {
|
|
603
|
+
const file = await pickFile();
|
|
604
|
+
if (file === null) {
|
|
605
|
+
setNotice({ kind: 'info', title: '没有选择还原点文件', detail: '也可以把 .tar.zst 文件拖到窗口后再试。' });
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
const imported = await request('/import', { method: 'POST', body: JSON.stringify({ file }) });
|
|
609
|
+
setNotice({ kind: 'success', title: '还原点已导入', detail: imported.file });
|
|
610
|
+
setTab('imported');
|
|
611
|
+
return imported;
|
|
612
|
+
});
|
|
613
|
+
if (result !== null && typeof result === 'object') await loadFolder(result.file);
|
|
614
|
+
};
|
|
437
615
|
|
|
438
616
|
const saveAuto = async (nextOn = autoOn, nextTime = autoTime) => {
|
|
439
617
|
setAutoOn(nextOn);
|
|
@@ -588,9 +766,30 @@ window.__ModuleLoader__.load({
|
|
|
588
766
|
]),
|
|
589
767
|
points.length === 0
|
|
590
768
|
? h('div', { key: 'empty', className: 'tm-empty', style: { marginTop: 10 } }, tab === 'manual' ? '还没有手动还原点。点上面的「一键设置还原点」即可创建第一份。' : tab === 'auto' ? '自动还原点默认关闭;打开上面的开关,或先手动生成一份。' : '还没有导入其他机器的还原点。')
|
|
591
|
-
: h('div', { key: 'list', className: 'tm-list', style: { marginTop: 10 } }, points.map((point) => h(PointRow, {
|
|
769
|
+
: h('div', { key: 'list', className: 'tm-list', style: { marginTop: 10 } }, points.map((point) => h(PointRow, {
|
|
770
|
+
key: point.file,
|
|
771
|
+
point,
|
|
772
|
+
busy: busy !== '',
|
|
773
|
+
selected: folderFile === point.file,
|
|
774
|
+
onRestore: startRestore,
|
|
775
|
+
onDetails: setDetails,
|
|
776
|
+
onFolder: showFolder,
|
|
777
|
+
}))),
|
|
592
778
|
]),
|
|
593
779
|
|
|
780
|
+
h(FolderDetails, {
|
|
781
|
+
key: 'folder',
|
|
782
|
+
points: folderPoints,
|
|
783
|
+
selectedFile: folderFile,
|
|
784
|
+
tree: folderTree,
|
|
785
|
+
loading: folderLoading,
|
|
786
|
+
error: folderError,
|
|
787
|
+
openPath: expandedPath,
|
|
788
|
+
onSelect: (file) => void loadFolder(file),
|
|
789
|
+
onRefresh: () => void loadFolder(folderFile),
|
|
790
|
+
onToggle: (path) => setExpandedPath((current) => (current === path ? null : path)),
|
|
791
|
+
}),
|
|
792
|
+
|
|
594
793
|
h('details', { key: 'adv', className: 'tm-details' }, [
|
|
595
794
|
h('summary', { key: 's' }, '说明与边界'),
|
|
596
795
|
h('div', { key: 'b', className: 'tm-detailsBody' }, [
|
|
@@ -754,6 +953,7 @@ window.__ModuleLoader__.load({
|
|
|
754
953
|
let button = null;
|
|
755
954
|
let observer = null;
|
|
756
955
|
let timer = null;
|
|
956
|
+
let hideTimer = null;
|
|
757
957
|
|
|
758
958
|
const stopWatching = () => {
|
|
759
959
|
if (observer !== null) {
|
|
@@ -766,7 +966,25 @@ window.__ModuleLoader__.load({
|
|
|
766
966
|
}
|
|
767
967
|
};
|
|
768
968
|
|
|
969
|
+
const hide = () => {
|
|
970
|
+
hideTimer = null;
|
|
971
|
+
if (button !== null) {
|
|
972
|
+
try { button.remove(); } catch { /* already gone */ }
|
|
973
|
+
button = null;
|
|
974
|
+
}
|
|
975
|
+
stopWatching();
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
const scheduleHide = () => {
|
|
979
|
+
if (typeof window.setTimeout !== 'function') return;
|
|
980
|
+
hideTimer = window.setTimeout(hide, CAPTION_AUTO_HIDE_MS);
|
|
981
|
+
};
|
|
982
|
+
|
|
769
983
|
const cleanup = () => {
|
|
984
|
+
if (hideTimer !== null) {
|
|
985
|
+
try { window.clearTimeout(hideTimer); } catch { /* already gone */ }
|
|
986
|
+
hideTimer = null;
|
|
987
|
+
}
|
|
770
988
|
stopWatching();
|
|
771
989
|
if (button !== null) {
|
|
772
990
|
try { button.remove(); } catch { /* already gone */ }
|
|
@@ -801,14 +1019,18 @@ window.__ModuleLoader__.load({
|
|
|
801
1019
|
return true;
|
|
802
1020
|
};
|
|
803
1021
|
|
|
804
|
-
if (mount())
|
|
1022
|
+
if (mount()) {
|
|
1023
|
+
scheduleHide();
|
|
1024
|
+
return cleanup;
|
|
1025
|
+
}
|
|
1026
|
+
scheduleHide();
|
|
805
1027
|
try {
|
|
806
1028
|
observer = new MutationObserver(() => {
|
|
807
1029
|
if (!mount()) return;
|
|
808
1030
|
stopWatching();
|
|
809
1031
|
});
|
|
810
1032
|
observer.observe(document.body ?? document.documentElement, { childList: true, subtree: true });
|
|
811
|
-
timer = window.setTimeout(stopWatching,
|
|
1033
|
+
timer = window.setTimeout(stopWatching, CAPTION_AUTO_HIDE_MS);
|
|
812
1034
|
} catch { /* no DOM observer in a test harness */ }
|
|
813
1035
|
return cleanup;
|
|
814
1036
|
}
|
|
@@ -825,16 +1047,32 @@ window.__ModuleLoader__.load({
|
|
|
825
1047
|
Object.defineProperty(slots, guard, { value: true, configurable: true, enumerable: false });
|
|
826
1048
|
} catch { /* frozen host */ }
|
|
827
1049
|
const disposers = [];
|
|
1050
|
+
const scheduleAutoHide = (dispose, delay) => {
|
|
1051
|
+
if (typeof dispose !== 'function' || typeof window === 'undefined' || typeof window.setTimeout !== 'function') return;
|
|
1052
|
+
const timer = window.setTimeout(() => {
|
|
1053
|
+
try { dispose(); } catch { /* already gone */ }
|
|
1054
|
+
}, delay);
|
|
1055
|
+
disposers.push(() => {
|
|
1056
|
+
try { window.clearTimeout(timer); } catch { /* already gone */ }
|
|
1057
|
+
});
|
|
1058
|
+
};
|
|
828
1059
|
const styleDisposer = injectStyle(typeof document === 'undefined' ? null : document);
|
|
829
1060
|
if (typeof styleDisposer === 'function') disposers.push(styleDisposer);
|
|
830
1061
|
const mountSlot = (seat, options, component, what) => {
|
|
831
1062
|
try {
|
|
832
1063
|
const dispose = slots.inject(seat, () => slots.register({ ...options, name: seat }, component));
|
|
833
|
-
if (typeof dispose
|
|
834
|
-
|
|
1064
|
+
if (typeof dispose !== 'function') return null;
|
|
1065
|
+
let active = true;
|
|
1066
|
+
const once = () => {
|
|
1067
|
+
if (!active) return;
|
|
1068
|
+
active = false;
|
|
1069
|
+
try { dispose(); } catch { /* already gone */ }
|
|
1070
|
+
};
|
|
1071
|
+
disposers.push(once);
|
|
1072
|
+
return once;
|
|
835
1073
|
} catch (error) {
|
|
836
1074
|
console.error(`@twinsearth/timemachine-dsh-plugin: ${what} was not mounted`, error);
|
|
837
|
-
return
|
|
1075
|
+
return null;
|
|
838
1076
|
}
|
|
839
1077
|
};
|
|
840
1078
|
const getService = (name) => (typeof ctx?.get === 'function' ? ctx.get(name) : undefined);
|
|
@@ -884,7 +1122,8 @@ window.__ModuleLoader__.load({
|
|
|
884
1122
|
}
|
|
885
1123
|
};
|
|
886
1124
|
mountSlot('settings.general.item', { id: 'timemachine-general', order: 80, label: () => 'DSH 一键还原点', inject: () => ({ open: openPanel, onRestoreDone: openRestored }) }, SettingsGeneralRow, 'the general-settings row');
|
|
887
|
-
mountSlot('sidebar.panellist', { id: PANEL_ID, order: -100, label: () => sidebarLabel() }, SidebarEntry, 'the sidebar entry');
|
|
1125
|
+
const sidebarDisposer = mountSlot('sidebar.panellist', { id: PANEL_ID, order: -100, label: () => sidebarLabel() }, SidebarEntry, 'the sidebar entry');
|
|
1126
|
+
scheduleAutoHide(sidebarDisposer, SIDEBAR_AUTO_HIDE_MS);
|
|
888
1127
|
mountSlot('main', { key: PANEL_ID, label: () => 'DSH 一键还原点', inject: () => ({ onRestoreDone: openRestored }) }, MainPage, 'the main panel');
|
|
889
1128
|
return () => {
|
|
890
1129
|
try {
|
|
@@ -903,7 +1142,13 @@ window.__ModuleLoader__.load({
|
|
|
903
1142
|
exports.SettingsGeneralRow = SettingsGeneralRow;
|
|
904
1143
|
exports.SidebarEntry = SidebarEntry;
|
|
905
1144
|
exports.sidebarLabel = sidebarLabel;
|
|
1145
|
+
exports.SIDEBAR_AUTO_HIDE_MS = SIDEBAR_AUTO_HIDE_MS;
|
|
1146
|
+
exports.CAPTION_AUTO_HIDE_MS = CAPTION_AUTO_HIDE_MS;
|
|
906
1147
|
exports.latestLocalPoint = latestLocalPoint;
|
|
1148
|
+
exports.allPointRows = allPointRows;
|
|
1149
|
+
exports.isTreePathOpen = isTreePathOpen;
|
|
1150
|
+
exports.FolderDetails = FolderDetails;
|
|
1151
|
+
exports.FolderTree = FolderTree;
|
|
907
1152
|
exports.injectStyle = injectStyle;
|
|
908
1153
|
exports.formatBytes = formatBytes;
|
|
909
1154
|
exports.formatTime = formatTime;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/timemachine-dsh-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "DSH 一键还原点:手动/自动双还原点、会话与工作区完整备份、第三方插件 latest 重装、配置迁移与一键还原。",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"icon": "./icon.png",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": "./lib/index.js",
|
|
8
9
|
"./client": "./lib/client.js",
|
|
@@ -14,6 +15,7 @@
|
|
|
14
15
|
"src",
|
|
15
16
|
"plugin.json",
|
|
16
17
|
"cordis.patch.yml",
|
|
18
|
+
"icon.png",
|
|
17
19
|
"README.md",
|
|
18
20
|
"CHANGELOG.md",
|
|
19
21
|
"docs",
|
package/plugin.json
CHANGED
package/src/point.mjs
CHANGED
|
@@ -27,6 +27,7 @@ import { readTar, writeTar } from './archive/tar.mjs';
|
|
|
27
27
|
import { inspectSessionBuffer } from './session-log.mjs';
|
|
28
28
|
import { scanExclusions, scanHome } from './scan.mjs';
|
|
29
29
|
import { packPluginTarballs, readProfilePlugins, SELF_PLUGIN } from './plugins.mjs';
|
|
30
|
+
import { buildPointTree } from './tree.mjs';
|
|
30
31
|
import { atomicWriteFile, ensureDir, formatBytes, isSafeArchiveName, readJson, sha256, stamp } from './util/fs.mjs';
|
|
31
32
|
import { encodeSegment, profileDir, projectKey, resolveDshHome } from './util/paths.mjs';
|
|
32
33
|
|
|
@@ -440,7 +441,7 @@ export async function createRestorePoint(input) {
|
|
|
440
441
|
writeSidecar(file, { point, counts, sha256: digest, bytes: zst.length });
|
|
441
442
|
const pruned = pruneCategory(folder, keep, file);
|
|
442
443
|
input.onProgress?.({ phase: 'created', file, bytes: zst.length });
|
|
443
|
-
return { ok: true, file, kind, bytes: zst.length, sha256: digest, point, counts, pruned };
|
|
444
|
+
return { ok: true, file, kind, bytes: zst.length, sha256: digest, point, counts, pruned, tree: buildPointTree(manifest, point, entries) };
|
|
444
445
|
} catch (error) {
|
|
445
446
|
if (error?.code === CODES.TOTAL_TOO_LARGE) return { ok: false, reason_code: error.code, detail: error.message };
|
|
446
447
|
return { ok: false, reason_code: CODES.WRITE_FAILED, detail: error instanceof Error ? error.message : String(error) };
|
|
@@ -575,6 +576,22 @@ export function readRestorePoint(file) {
|
|
|
575
576
|
};
|
|
576
577
|
}
|
|
577
578
|
|
|
579
|
+
/** Metadata plus the human-readable archive tree used by the full panel. */
|
|
580
|
+
export function inspectRestorePoint(file) {
|
|
581
|
+
const archive = readArchive(file);
|
|
582
|
+
if (!archive.ok) return archive;
|
|
583
|
+
return {
|
|
584
|
+
ok: true,
|
|
585
|
+
file: archive.file,
|
|
586
|
+
bytes: archive.bytes,
|
|
587
|
+
sha256: archive.sha256,
|
|
588
|
+
point: archive.point,
|
|
589
|
+
counts: archive.manifest.counts ?? archive.point.counts,
|
|
590
|
+
manifest: archive.manifest,
|
|
591
|
+
tree: buildPointTree(archive.manifest, archive.point, archive.entries),
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
578
595
|
/** List one store, newest first. Unreadable files become `ok:false` rows, not omissions. */
|
|
579
596
|
export function listCategory(root, kind) {
|
|
580
597
|
const folder = categoryDir(root, kind);
|
package/src/service.mjs
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
defaultRoot,
|
|
18
18
|
estimateRestorePoint,
|
|
19
19
|
importRestorePoint,
|
|
20
|
+
inspectRestorePoint,
|
|
20
21
|
listCategory,
|
|
21
|
-
readRestorePoint,
|
|
22
22
|
resolveRoot,
|
|
23
23
|
rootIsDefaultable,
|
|
24
24
|
selectSessions,
|
|
@@ -378,7 +378,7 @@ export function pickerUnavailable(what) {
|
|
|
378
378
|
export function inspectPoint(rawConfig, body, options = {}) {
|
|
379
379
|
const file = typeof body?.file === 'string' ? body.file.trim() : '';
|
|
380
380
|
if (file === '') return { ok: false, reason_code: 'TIMEMACHINE_FILE_REQUIRED', detail: 'body.file is required' };
|
|
381
|
-
const row =
|
|
381
|
+
const row = inspectRestorePoint(file);
|
|
382
382
|
if (!row.ok) return row;
|
|
383
383
|
const names = new Set((row.manifest.files ?? []).filter((item) => item.kind === 'session').map((item) => item.session_id));
|
|
384
384
|
return {
|
|
@@ -393,6 +393,7 @@ export function inspectPoint(rawConfig, body, options = {}) {
|
|
|
393
393
|
plugins: row.point.plugins ?? [],
|
|
394
394
|
user_plugins: row.point.all_plugins ?? [],
|
|
395
395
|
has_plugin_packages: Object.keys(row.point.plugin_package_files ?? {}).length > 0,
|
|
396
|
+
tree: row.tree,
|
|
396
397
|
};
|
|
397
398
|
}
|
|
398
399
|
|
package/src/tree.mjs
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable archive tree for the full panel.
|
|
3
|
+
*
|
|
4
|
+
* The manifest lists the content files but deliberately omits the three
|
|
5
|
+
* top-level files (it describes itself before they are packed). Keep the
|
|
6
|
+
* mapping here so the server and the UI use the same Chinese labels.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const TOP_LEVEL = [
|
|
10
|
+
['manifest.json', 'manifest', '清单文件:记录每个文件的路径、大小与 SHA-256'],
|
|
11
|
+
['README.txt', 'readme', '人读说明:创建时间、备份范围与排除项'],
|
|
12
|
+
['RESTORE-POINT.json', 'point', '还原点元数据:会话、插件、工作区与统计'],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const KIND_DESCRIPTIONS = {
|
|
16
|
+
manifest: '清单文件:记录每个文件的路径、大小与 SHA-256',
|
|
17
|
+
readme: '人读说明:创建时间、备份范围与排除项',
|
|
18
|
+
point: '还原点元数据:会话、插件、工作区与统计',
|
|
19
|
+
session: '会话原始日志(zstd 压缩)',
|
|
20
|
+
guide: '还原引导:会话来源、工作区与恢复步骤',
|
|
21
|
+
attachment: '会话附件对象',
|
|
22
|
+
config: 'DSH 配置文件(不含账户与凭据)',
|
|
23
|
+
state: 'DSH 界面或状态数据',
|
|
24
|
+
registry: '工作区与会话注册表快照',
|
|
25
|
+
plugin_package: '第三方插件离线安装包(.tgz)',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function describeDir(rel) {
|
|
29
|
+
if (rel === 'sessions') return '会话目录:按项目分组,每个会话一个 Session ID 子目录';
|
|
30
|
+
if (/^sessions\/[^/]+$/u.test(rel)) return '项目分组:由会话工作目录生成';
|
|
31
|
+
if (/^sessions\/[^/]+\/[^/]+$/u.test(rel)) return '单个会话目录:原始日志 + 两份还原引导';
|
|
32
|
+
if (rel === 'attachments') return '附件目录:会话引用的附件对象';
|
|
33
|
+
if (/^attachments\/[^/]+$/u.test(rel)) return '附件对象分片目录';
|
|
34
|
+
if (rel === 'profiles') return 'DSH profile 目录:配置、插件列表与界面状态';
|
|
35
|
+
if (/^profiles\/[^/]+$/u.test(rel)) return 'DSH profile:该配置档的配置与插件状态';
|
|
36
|
+
if (rel === 'storages' || /\/storages$/u.test(rel)) return 'DSH 状态存储:界面与会话状态';
|
|
37
|
+
if (rel === 'registry') return '工作区注册表目录';
|
|
38
|
+
if (rel === 'plugin-packages') return '第三方插件离线安装包目录';
|
|
39
|
+
return '目录';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function describeFile(row) {
|
|
43
|
+
const base = row.rel.split('/').pop() ?? row.rel;
|
|
44
|
+
if (row.kind === 'guide') {
|
|
45
|
+
return base.endsWith('.json')
|
|
46
|
+
? '机器可读还原引导:会话来源、工作区与恢复步骤'
|
|
47
|
+
: '人读还原引导:逐项说明如何恢复该会话';
|
|
48
|
+
}
|
|
49
|
+
if (KIND_DESCRIPTIONS[row.kind] !== undefined) return KIND_DESCRIPTIONS[row.kind];
|
|
50
|
+
if (base === 'package.json') return 'DSH profile 的插件声明与版本信息';
|
|
51
|
+
if (base === 'cordis.patch.yml') return 'DSH 插件启用/参数补丁';
|
|
52
|
+
return row.reason ? `备份文件:${row.reason}` : '备份文件';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function fileSize(row, sizeByRel) {
|
|
56
|
+
if (sizeByRel.has(row.rel)) return sizeByRel.get(row.rel);
|
|
57
|
+
return typeof row.size === 'number' ? row.size : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function finalize(node) {
|
|
61
|
+
if (node.type === 'file') return;
|
|
62
|
+
let bytes = 0;
|
|
63
|
+
let known = false;
|
|
64
|
+
for (const child of node.children.values()) {
|
|
65
|
+
finalize(child);
|
|
66
|
+
if (typeof child.bytes === 'number') {
|
|
67
|
+
bytes += child.bytes;
|
|
68
|
+
known = true;
|
|
69
|
+
}
|
|
70
|
+
node.files += child.files;
|
|
71
|
+
}
|
|
72
|
+
node.bytes = known ? bytes : null;
|
|
73
|
+
node.children = [...node.children.values()].sort((a, b) => {
|
|
74
|
+
if (a.type !== b.type) return a.type === 'dir' ? -1 : 1;
|
|
75
|
+
return a.name.localeCompare(b.name, 'zh-CN');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {{files?: Array<{rel: string, kind?: string, size?: number, reason?: string}>}} manifest
|
|
81
|
+
* @param {object} [point]
|
|
82
|
+
* @param {Array<{name: string, data: Buffer}>} [entries] exact sizes when available
|
|
83
|
+
* @returns {{name: string, path: string, type: string, description: string, bytes: number|null, files: number, children: Array}}
|
|
84
|
+
*/
|
|
85
|
+
export function buildPointTree(manifest, point = {}, entries = null) {
|
|
86
|
+
const sizeByRel = new Map();
|
|
87
|
+
for (const entry of entries ?? []) {
|
|
88
|
+
if (typeof entry?.name === 'string' && entry?.data !== undefined) {
|
|
89
|
+
sizeByRel.set(entry.name, entry.data.length);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const rows = [...(manifest?.files ?? [])];
|
|
94
|
+
const seen = new Set(rows.map((row) => row.rel));
|
|
95
|
+
for (const [rel, kind, description] of TOP_LEVEL) {
|
|
96
|
+
if (!seen.has(rel)) rows.push({ rel, kind, size: sizeByRel.get(rel) ?? null, description });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const root = {
|
|
100
|
+
name: '还原点根目录',
|
|
101
|
+
path: '',
|
|
102
|
+
type: 'dir',
|
|
103
|
+
description: `整个还原点压缩包${point?.kind ? `(${point.kind === 'auto' ? '自动' : point.kind === 'imported' ? '导入' : '手动'})` : ''}`,
|
|
104
|
+
bytes: null,
|
|
105
|
+
files: 0,
|
|
106
|
+
children: new Map(),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
for (const row of rows) {
|
|
110
|
+
if (typeof row?.rel !== 'string' || row.rel === '') continue;
|
|
111
|
+
const segments = row.rel.split('/').filter(Boolean);
|
|
112
|
+
let parent = root;
|
|
113
|
+
let current = '';
|
|
114
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
115
|
+
const segment = segments[index];
|
|
116
|
+
current = current === '' ? segment : `${current}/${segment}`;
|
|
117
|
+
const isFile = index === segments.length - 1;
|
|
118
|
+
let node = parent.children.get(segment);
|
|
119
|
+
if (node === undefined) {
|
|
120
|
+
node = {
|
|
121
|
+
name: segment,
|
|
122
|
+
path: current,
|
|
123
|
+
type: isFile ? 'file' : 'dir',
|
|
124
|
+
description: isFile ? describeFile(row) : describeDir(current),
|
|
125
|
+
bytes: isFile ? fileSize(row, sizeByRel) : null,
|
|
126
|
+
files: isFile ? 1 : 0,
|
|
127
|
+
...(isFile ? { kind: row.kind ?? 'file' } : { children: new Map() }),
|
|
128
|
+
};
|
|
129
|
+
parent.children.set(segment, node);
|
|
130
|
+
}
|
|
131
|
+
parent = node;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
finalize(root);
|
|
136
|
+
return root;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Flatten a built tree for a simple indented list. */
|
|
140
|
+
export function flattenTree(root) {
|
|
141
|
+
const rows = [];
|
|
142
|
+
const walk = (node, depth) => {
|
|
143
|
+
rows.push({ ...node, depth, children: undefined });
|
|
144
|
+
for (const child of node.children ?? []) walk(child, depth + 1);
|
|
145
|
+
};
|
|
146
|
+
walk(root, 0);
|
|
147
|
+
return rows;
|
|
148
|
+
}
|