dsh-workspace-migrate 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +117 -2
- package/client.js +926 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +18 -0
- package/index.js +1238 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +52 -4
package/client.js
ADDED
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-workspace-migrate',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const { useState, useEffect, useRef, useCallback } = React
|
|
7
|
+
|
|
8
|
+
const NS = 'dsh-migrate'
|
|
9
|
+
const API = '/api/dsh-migrate'
|
|
10
|
+
|
|
11
|
+
const ZH = {
|
|
12
|
+
title: '迁移到另一台电脑',
|
|
13
|
+
subtitle: '把工作区、项目成果和对话内容打包带走,在新电脑上还原。导出在旧电脑做,导入在新电脑做。',
|
|
14
|
+
tabExport: '导出(旧电脑)',
|
|
15
|
+
tabImport: '导入(新电脑)',
|
|
16
|
+
projects: '工作区',
|
|
17
|
+
projectsHint: '选中的工作区会连同归属的会话一起打包;子会话会自动带上。',
|
|
18
|
+
selectAll: '全选',
|
|
19
|
+
selectNone: '清空',
|
|
20
|
+
sessionCount: '个会话',
|
|
21
|
+
files: '同时打包项目文件',
|
|
22
|
+
filesHint: '排除 node_modules、.git 等可重建目录。',
|
|
23
|
+
attachments: '同时打包图片附件',
|
|
24
|
+
outDir: '导出位置',
|
|
25
|
+
outDirHint: '留空则用 ~/.dsh/migrations。',
|
|
26
|
+
startExport: '开始导出',
|
|
27
|
+
exportRunning: '正在导出…',
|
|
28
|
+
exportDone: '导出完成',
|
|
29
|
+
exportFailed: '导出失败',
|
|
30
|
+
bundlePath: '迁移包路径',
|
|
31
|
+
loadPreview: '读取迁移包',
|
|
32
|
+
recent: '最近导出',
|
|
33
|
+
preview: '迁移包内容',
|
|
34
|
+
source: '来源',
|
|
35
|
+
createdAt: '创建时间',
|
|
36
|
+
formatVersion: '日志格式',
|
|
37
|
+
sessions: '会话',
|
|
38
|
+
remap: '路径映射',
|
|
39
|
+
remapHint: '新电脑没有同样的盘符或目录时,填新的目标路径;目录不存在会自动创建。',
|
|
40
|
+
from: '原路径',
|
|
41
|
+
to: '新路径',
|
|
42
|
+
importFiles: '导入项目文件',
|
|
43
|
+
overwrite: '目标目录非空时仍覆盖',
|
|
44
|
+
startImport: '开始导入',
|
|
45
|
+
importRunning: '正在导入…',
|
|
46
|
+
importDone: '导入完成',
|
|
47
|
+
importFailed: '导入失败',
|
|
48
|
+
report: '结果',
|
|
49
|
+
imported: '已导入会话',
|
|
50
|
+
skipped: '跳过',
|
|
51
|
+
flattened: '展开的 fork 会话',
|
|
52
|
+
warnings: '提醒',
|
|
53
|
+
undo: '撤销这次导入',
|
|
54
|
+
undoConfirm: '将删除本次导入创建的项目登记和会话文件,确定吗?',
|
|
55
|
+
undone: '已撤销本次导入',
|
|
56
|
+
refused: '拒绝',
|
|
57
|
+
update: '增量更新已有迁移包',
|
|
58
|
+
updateHint: '只复制新增或修改过的文件,未变化的文件与会话直接复用。适合同一个包反复同步。',
|
|
59
|
+
updateNow: '开始增量更新',
|
|
60
|
+
reused: '复用会话',
|
|
61
|
+
copied: '复制文件',
|
|
62
|
+
unchanged: '未变',
|
|
63
|
+
removed: '已删除',
|
|
64
|
+
importRoot: '导入到(新根目录)',
|
|
65
|
+
importRootHint: '每个项目会自动建一个以项目名命名的子文件夹;下面每一行仍可单独改。',
|
|
66
|
+
rewritePaths: '重写对话里提到的旧路径',
|
|
67
|
+
rewritePathsHint: '工具调用与结果中的旧绝对路径会换成新路径,续聊时模型才找得到文件。',
|
|
68
|
+
rewrittenPaths: '重写路径',
|
|
69
|
+
ungrouped: '未归属项目的会话',
|
|
70
|
+
cleaned: '已清理失效项目',
|
|
71
|
+
cleanup: '清理失效项目',
|
|
72
|
+
checkup: '导入前体检',
|
|
73
|
+
checkupRunning: '正在检查…',
|
|
74
|
+
refs: '附件引用',
|
|
75
|
+
missingRefs: '缺失',
|
|
76
|
+
attachmentAdvice: '建议',
|
|
77
|
+
missingAttachments: '缺失附件的会话',
|
|
78
|
+
noBundles: '还没有迁移包。先在旧电脑上导出。',
|
|
79
|
+
loading: '加载中…',
|
|
80
|
+
empty: '没有数据',
|
|
81
|
+
bytes: '大小',
|
|
82
|
+
close: '关闭',
|
|
83
|
+
}
|
|
84
|
+
const EN = {
|
|
85
|
+
title: 'Migrate to another computer',
|
|
86
|
+
subtitle: 'Package workspaces, project files, and conversations, then restore them on the new machine. Export on the old computer, import on the new one.',
|
|
87
|
+
tabExport: 'Export (old computer)',
|
|
88
|
+
tabImport: 'Import (new computer)',
|
|
89
|
+
projects: 'Workspaces',
|
|
90
|
+
projectsHint: 'Selected workspaces carry their sessions; sub-sessions are included automatically.',
|
|
91
|
+
selectAll: 'All',
|
|
92
|
+
selectNone: 'None',
|
|
93
|
+
sessionCount: 'sessions',
|
|
94
|
+
files: 'Include project files',
|
|
95
|
+
filesHint: 'Skips rebuildable directories such as node_modules and .git.',
|
|
96
|
+
attachments: 'Include image attachments',
|
|
97
|
+
outDir: 'Export location',
|
|
98
|
+
outDirHint: 'Empty uses ~/.dsh/migrations.',
|
|
99
|
+
startExport: 'Start export',
|
|
100
|
+
exportRunning: 'Exporting…',
|
|
101
|
+
exportDone: 'Export finished',
|
|
102
|
+
exportFailed: 'Export failed',
|
|
103
|
+
bundlePath: 'Bundle path',
|
|
104
|
+
loadPreview: 'Read bundle',
|
|
105
|
+
recent: 'Recent exports',
|
|
106
|
+
preview: 'Bundle contents',
|
|
107
|
+
source: 'Source',
|
|
108
|
+
createdAt: 'Created',
|
|
109
|
+
formatVersion: 'Log format',
|
|
110
|
+
sessions: 'Sessions',
|
|
111
|
+
remap: 'Path mapping',
|
|
112
|
+
remapHint: 'When the new machine lacks the same drive or folder, enter the target path; missing folders are created.',
|
|
113
|
+
from: 'From',
|
|
114
|
+
to: 'To',
|
|
115
|
+
importFiles: 'Import project files',
|
|
116
|
+
overwrite: 'Overwrite when the target folder is not empty',
|
|
117
|
+
startImport: 'Start import',
|
|
118
|
+
importRunning: 'Importing…',
|
|
119
|
+
importDone: 'Import finished',
|
|
120
|
+
importFailed: 'Import failed',
|
|
121
|
+
report: 'Result',
|
|
122
|
+
imported: 'Sessions imported',
|
|
123
|
+
skipped: 'Skipped',
|
|
124
|
+
flattened: 'Flattened forks',
|
|
125
|
+
warnings: 'Notes',
|
|
126
|
+
undo: 'Undo this import',
|
|
127
|
+
undoConfirm: 'This deletes the workspace registrations and session files created by this import. Continue?',
|
|
128
|
+
undone: 'Import undone',
|
|
129
|
+
refused: 'refused',
|
|
130
|
+
update: 'Update an existing bundle',
|
|
131
|
+
updateHint: 'Copies only added or changed files and reuses unchanged sessions, so repeated syncs stay cheap.',
|
|
132
|
+
updateNow: 'Start incremental update',
|
|
133
|
+
reused: 'sessions reused',
|
|
134
|
+
copied: 'files copied',
|
|
135
|
+
unchanged: 'unchanged',
|
|
136
|
+
removed: 'removed',
|
|
137
|
+
importRoot: 'Import into (new root)',
|
|
138
|
+
importRootHint: 'Each project gets a subfolder named after it; every row below can still be edited.',
|
|
139
|
+
rewritePaths: 'Rewrite old paths mentioned in conversations',
|
|
140
|
+
rewritePathsHint: 'Absolute paths inside tool calls and results are replaced with the new ones, so a resumed conversation finds its files.',
|
|
141
|
+
rewrittenPaths: 'paths rewritten',
|
|
142
|
+
ungrouped: 'sessions not attached to a project',
|
|
143
|
+
cleaned: 'stale projects removed',
|
|
144
|
+
cleanup: 'Clean up stale projects',
|
|
145
|
+
checkup: 'Pre-flight check',
|
|
146
|
+
checkupRunning: 'Checking…',
|
|
147
|
+
refs: 'attachment refs',
|
|
148
|
+
missingRefs: 'missing',
|
|
149
|
+
attachmentAdvice: 'Advice',
|
|
150
|
+
missingAttachments: 'sessions with missing attachments',
|
|
151
|
+
noBundles: 'No bundle yet. Export on the old computer first.',
|
|
152
|
+
loading: 'Loading…',
|
|
153
|
+
empty: 'Nothing here',
|
|
154
|
+
bytes: 'Size',
|
|
155
|
+
close: 'Close',
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const C = {
|
|
159
|
+
page: { padding: '26px 30px 48px', maxWidth: 860, display: 'flex', flexDirection: 'column', gap: 18 },
|
|
160
|
+
h1: { margin: 0, fontSize: 19, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' },
|
|
161
|
+
sub: { margin: '6px 0 0', fontSize: 13, lineHeight: 1.6, color: 'var(--dsw-alias-label-secondary)' },
|
|
162
|
+
tabs: { display: 'flex', gap: 6, borderBottom: '1px solid var(--dsw-alias-border-l1)' },
|
|
163
|
+
tab: {
|
|
164
|
+
appearance: 'none', border: 'none', background: 'transparent', cursor: 'pointer',
|
|
165
|
+
padding: '9px 12px', fontSize: 13, fontWeight: 500, color: 'var(--dsw-alias-label-secondary)',
|
|
166
|
+
borderBottom: '2px solid transparent', marginBottom: -1,
|
|
167
|
+
},
|
|
168
|
+
tabActive: { color: 'var(--dsw-alias-label-primary)', borderBottomColor: 'var(--dsw-alias-brand-primary)' },
|
|
169
|
+
card: {
|
|
170
|
+
border: '1px solid var(--dsw-alias-border-l1)', background: 'var(--dsw-alias-bg-layer-1)',
|
|
171
|
+
borderRadius: 10, padding: '14px 16px', display: 'flex', flexDirection: 'column', gap: 12,
|
|
172
|
+
},
|
|
173
|
+
cardHead: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 },
|
|
174
|
+
cardTitle: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' },
|
|
175
|
+
hint: { fontSize: 12, lineHeight: 1.55, color: 'var(--dsw-alias-label-secondary)' },
|
|
176
|
+
row: {
|
|
177
|
+
display: 'flex', alignItems: 'flex-start', gap: 10, padding: '8px 0',
|
|
178
|
+
borderTop: '1px solid var(--dsw-alias-border-l1)',
|
|
179
|
+
},
|
|
180
|
+
rowText: { display: 'flex', flexDirection: 'column', gap: 3, minWidth: 0, flex: 1 },
|
|
181
|
+
rowTitle: { fontSize: 13, color: 'var(--dsw-alias-label-primary)', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
182
|
+
mono: {
|
|
183
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
|
|
184
|
+
fontSize: 11.5, color: 'var(--dsw-alias-label-secondary)',
|
|
185
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
186
|
+
},
|
|
187
|
+
badge: {
|
|
188
|
+
fontSize: 11, padding: '1px 7px', borderRadius: 999,
|
|
189
|
+
border: '1px solid var(--dsw-alias-border-l1)', color: 'var(--dsw-alias-label-secondary)',
|
|
190
|
+
whiteSpace: 'nowrap',
|
|
191
|
+
},
|
|
192
|
+
input: {
|
|
193
|
+
width: '100%', boxSizing: 'border-box', padding: '7px 9px', fontSize: 12.5,
|
|
194
|
+
color: 'var(--dsw-alias-label-primary)', background: 'var(--dsw-alias-bg-base)',
|
|
195
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 8, outline: 'none',
|
|
196
|
+
},
|
|
197
|
+
button: {
|
|
198
|
+
appearance: 'none', border: '1px solid var(--dsw-alias-border-l1)', borderRadius: 8,
|
|
199
|
+
background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)',
|
|
200
|
+
padding: '7px 13px', fontSize: 12.5, cursor: 'pointer',
|
|
201
|
+
},
|
|
202
|
+
primary: {
|
|
203
|
+
appearance: 'none',
|
|
204
|
+
border: '1px solid var(--dsw-alias-brand-primary)',
|
|
205
|
+
borderRadius: 8,
|
|
206
|
+
background: 'color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, var(--dsw-alias-bg-base))',
|
|
207
|
+
color: 'var(--dsw-alias-brand-primary)',
|
|
208
|
+
padding: '8px 16px', fontSize: 12.5, fontWeight: 600, cursor: 'pointer',
|
|
209
|
+
},
|
|
210
|
+
primaryOff: { opacity: 0.5, cursor: 'default' },
|
|
211
|
+
label: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12.5, color: 'var(--dsw-alias-label-primary)', cursor: 'pointer' },
|
|
212
|
+
bar: { height: 4, borderRadius: 999, background: 'var(--dsw-alias-bg-layer-2)', overflow: 'hidden' },
|
|
213
|
+
barFill: { height: '100%', background: 'var(--dsw-alias-brand-primary)', transition: 'width .25s ease' },
|
|
214
|
+
warn: { fontSize: 12, lineHeight: 1.55, color: 'var(--dsw-alias-state-warn-primary)' },
|
|
215
|
+
error: { fontSize: 12, lineHeight: 1.55, color: 'var(--dsw-alias-state-error-primary)' },
|
|
216
|
+
ok: { fontSize: 12, lineHeight: 1.55, color: 'var(--dsw-alias-state-success-primary)' },
|
|
217
|
+
kv: { display: 'flex', gap: 8, fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
218
|
+
kvKey: { minWidth: 72, color: 'var(--dsw-alias-label-secondary)' },
|
|
219
|
+
kvVal: { color: 'var(--dsw-alias-label-primary)', wordBreak: 'break-all' },
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function fmtBytes(n) {
|
|
223
|
+
if (!n || n < 0) return '0 B'
|
|
224
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
225
|
+
let value = n
|
|
226
|
+
let unit = 0
|
|
227
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
228
|
+
value /= 1024
|
|
229
|
+
unit += 1
|
|
230
|
+
}
|
|
231
|
+
return `${value >= 100 || unit === 0 ? Math.round(value) : value.toFixed(1)} ${units[unit]}`
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function fmtTime(value) {
|
|
235
|
+
if (!value) return '—'
|
|
236
|
+
const date = new Date(value)
|
|
237
|
+
if (Number.isNaN(date.getTime())) return String(value)
|
|
238
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
239
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function request(path, options) {
|
|
243
|
+
const response = await fetch(API + path, options)
|
|
244
|
+
let payload = null
|
|
245
|
+
try {
|
|
246
|
+
payload = await response.json()
|
|
247
|
+
} catch {
|
|
248
|
+
payload = null
|
|
249
|
+
}
|
|
250
|
+
if (!response.ok) throw new Error((payload && payload.error) || `HTTP ${response.status}`)
|
|
251
|
+
return payload
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const api = {
|
|
255
|
+
get: (path) => request(path, { headers: { accept: 'application/json' } }),
|
|
256
|
+
post: (path, body) =>
|
|
257
|
+
request(path, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: { 'content-type': 'application/json' },
|
|
260
|
+
body: JSON.stringify(body || {}),
|
|
261
|
+
}),
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function Checkbox(props) {
|
|
265
|
+
return h('input', {
|
|
266
|
+
type: 'checkbox',
|
|
267
|
+
checked: Boolean(props.checked),
|
|
268
|
+
disabled: Boolean(props.disabled),
|
|
269
|
+
onChange: (event) => props.onChange(event.target.checked),
|
|
270
|
+
style: { marginTop: 2, accentColor: 'var(--dsw-alias-brand-primary)' },
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function Kv(props) {
|
|
275
|
+
return h(
|
|
276
|
+
'div',
|
|
277
|
+
{ style: C.kv },
|
|
278
|
+
h('span', { style: C.kvKey }, props.label),
|
|
279
|
+
h('span', { style: C.kvVal }, props.value),
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function Progress(props) {
|
|
284
|
+
const task = props.task
|
|
285
|
+
if (!task) return null
|
|
286
|
+
const total = Number(task.total) || 0
|
|
287
|
+
const done = Number(task.done) || 0
|
|
288
|
+
const percent = total > 0 ? Math.min(100, Math.round((done / total) * 100)) : task.phase === 'done' ? 100 : 8
|
|
289
|
+
return h(
|
|
290
|
+
'div',
|
|
291
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 7 } },
|
|
292
|
+
h('div', { style: C.bar }, h('div', { style: { ...C.barFill, width: `${percent}%` } })),
|
|
293
|
+
h(
|
|
294
|
+
'div',
|
|
295
|
+
{ style: task.phase === 'failed' ? C.error : C.hint },
|
|
296
|
+
task.phase === 'failed' ? task.error || task.message : task.message || '',
|
|
297
|
+
),
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function TaskResult(props) {
|
|
302
|
+
const { t, task, kind } = props
|
|
303
|
+
if (!task || task.phase !== 'done' || !task.result) return null
|
|
304
|
+
const result = task.result
|
|
305
|
+
if (kind === 'export') {
|
|
306
|
+
return h(
|
|
307
|
+
'div',
|
|
308
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 5 } },
|
|
309
|
+
h('div', { style: C.ok }, `${t('exportDone')} · ${result.sessions} ${t('sessions')} · ${fmtBytes(result.bytes)}`),
|
|
310
|
+
result.mode === 'update'
|
|
311
|
+
? h(
|
|
312
|
+
'div',
|
|
313
|
+
{ style: C.hint },
|
|
314
|
+
`${t('reused')} ${result.sessionsReused} · ${t('copied')} ${result.filesCopied} (${fmtBytes(result.bytesCopied)}) · ${t('unchanged')} ${result.filesUnchanged} · ${t('removed')} ${result.filesRemoved}`,
|
|
315
|
+
)
|
|
316
|
+
: null,
|
|
317
|
+
h('div', { style: C.mono }, result.path),
|
|
318
|
+
(result.warnings || []).length > 0
|
|
319
|
+
? h(
|
|
320
|
+
'div',
|
|
321
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
322
|
+
...result.warnings.map((text, index) => h('div', { key: index, style: C.warn }, `• ${text}`)),
|
|
323
|
+
)
|
|
324
|
+
: null,
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
return h(
|
|
328
|
+
'div',
|
|
329
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
330
|
+
h('div', { style: C.ok }, `${t('importDone')} · ${t('imported')} ${result.sessionsImported} · ${t('skipped')} ${result.sessionsSkipped.length}`),
|
|
331
|
+
result.flattened > 0 ? h('div', { style: C.hint }, `${t('flattened')}: ${result.flattened}`) : null,
|
|
332
|
+
result.rewritten > 0 ? h('div', { style: C.hint }, `${t('rewrittenPaths')}: ${result.rewritten}`) : null,
|
|
333
|
+
result.missingAttachments > 0
|
|
334
|
+
? h('div', { style: C.warn }, `${t('missingAttachments')}: ${result.missingAttachments}`)
|
|
335
|
+
: null,
|
|
336
|
+
result.ungrouped > 0 ? h('div', { style: C.warn }, `${t('ungrouped')}: ${result.ungrouped}`) : null,
|
|
337
|
+
result.warnings.length > 0
|
|
338
|
+
? h(
|
|
339
|
+
'div',
|
|
340
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
341
|
+
...result.warnings.map((text, index) => h('div', { key: index, style: C.warn }, `• ${text}`)),
|
|
342
|
+
)
|
|
343
|
+
: null,
|
|
344
|
+
result.sessionsSkipped.length > 0
|
|
345
|
+
? h(
|
|
346
|
+
'div',
|
|
347
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3, maxHeight: 180, overflowY: 'auto' } },
|
|
348
|
+
...result.sessionsSkipped.map((item, index) =>
|
|
349
|
+
h('div', { key: index, style: C.hint }, `• ${item.id} — ${item.reason}`),
|
|
350
|
+
),
|
|
351
|
+
)
|
|
352
|
+
: null,
|
|
353
|
+
)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function usePolling(t) {
|
|
357
|
+
const [taskId, setTaskId] = useState(null)
|
|
358
|
+
const [task, setTask] = useState(null)
|
|
359
|
+
const [error, setError] = useState(null)
|
|
360
|
+
|
|
361
|
+
useEffect(() => {
|
|
362
|
+
if (!taskId) return undefined
|
|
363
|
+
let stopped = false
|
|
364
|
+
let timer = null
|
|
365
|
+
const tick = async () => {
|
|
366
|
+
try {
|
|
367
|
+
const value = await api.get(`/task?id=${encodeURIComponent(taskId)}`)
|
|
368
|
+
if (stopped) return
|
|
369
|
+
if (value && value.error) {
|
|
370
|
+
setError(value.error)
|
|
371
|
+
setTask({ phase: 'failed', error: value.error, message: value.error, done: 0, total: 0 })
|
|
372
|
+
return
|
|
373
|
+
}
|
|
374
|
+
setTask(value)
|
|
375
|
+
if (value.phase === 'running') timer = setTimeout(tick, 450)
|
|
376
|
+
} catch (cause) {
|
|
377
|
+
if (!stopped) {
|
|
378
|
+
const message = cause instanceof Error ? cause.message : String(cause)
|
|
379
|
+
setError(message)
|
|
380
|
+
setTask({ phase: 'failed', error: message, message, done: 0, total: 0 })
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
timer = setTimeout(tick, 250)
|
|
385
|
+
return () => {
|
|
386
|
+
stopped = true
|
|
387
|
+
if (timer) clearTimeout(timer)
|
|
388
|
+
}
|
|
389
|
+
}, [taskId])
|
|
390
|
+
|
|
391
|
+
const run = useCallback(async (kind, body) => {
|
|
392
|
+
setError(null)
|
|
393
|
+
setTask({ phase: 'running', message: t(kind === 'export' ? 'exportRunning' : 'importRunning'), done: 0, total: 0 })
|
|
394
|
+
try {
|
|
395
|
+
const started = await api.post(`/${kind}`, body)
|
|
396
|
+
setTaskId(started.taskId)
|
|
397
|
+
} catch (cause) {
|
|
398
|
+
const message = cause instanceof Error ? cause.message : String(cause)
|
|
399
|
+
setError(message)
|
|
400
|
+
setTask({ phase: 'failed', error: message, message, done: 0, total: 0 })
|
|
401
|
+
}
|
|
402
|
+
}, [t])
|
|
403
|
+
|
|
404
|
+
return { task, error, run }
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function ExportPane(props) {
|
|
408
|
+
const { t, inventory, reload } = props
|
|
409
|
+
const [selected, setSelected] = useState(null)
|
|
410
|
+
const [includeFiles, setIncludeFiles] = useState(true)
|
|
411
|
+
const [includeAttachments, setIncludeAttachments] = useState(true)
|
|
412
|
+
const [outDir, setOutDir] = useState('')
|
|
413
|
+
const [updateTarget, setUpdateTarget] = useState('')
|
|
414
|
+
const [cleanupNote, setCleanupNote] = useState(null)
|
|
415
|
+
const { task, run } = usePolling(t)
|
|
416
|
+
|
|
417
|
+
const workspaces = inventory ? inventory.workspaces : []
|
|
418
|
+
const bundles = inventory && inventory.bundles ? inventory.bundles : []
|
|
419
|
+
const active = selected === null ? new Set(workspaces.map((workspace) => workspace.id)) : selected
|
|
420
|
+
|
|
421
|
+
useEffect(() => {
|
|
422
|
+
if (!updateTarget && bundles.length > 0) setUpdateTarget(bundles[0].path)
|
|
423
|
+
}, [bundles, updateTarget])
|
|
424
|
+
|
|
425
|
+
const toggle = (id) => {
|
|
426
|
+
const next = new Set(active)
|
|
427
|
+
if (next.has(id)) next.delete(id)
|
|
428
|
+
else next.add(id)
|
|
429
|
+
setSelected(next)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const cleanup = async () => {
|
|
433
|
+
try {
|
|
434
|
+
const result = await api.post('/cleanup', {})
|
|
435
|
+
const removed = (result.removed || []).filter((entry) => entry.removed).length
|
|
436
|
+
setCleanupNote(`${t('cleaned')} ${removed}`)
|
|
437
|
+
reload()
|
|
438
|
+
} catch (error) {
|
|
439
|
+
setCleanupNote(error instanceof Error ? error.message : String(error))
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const running = task && task.phase === 'running'
|
|
444
|
+
|
|
445
|
+
return h(
|
|
446
|
+
'div',
|
|
447
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 14 } },
|
|
448
|
+
h(
|
|
449
|
+
'div',
|
|
450
|
+
{ style: C.card },
|
|
451
|
+
h(
|
|
452
|
+
'div',
|
|
453
|
+
{ style: C.cardHead },
|
|
454
|
+
h('div', { style: C.cardTitle }, t('projects')),
|
|
455
|
+
h(
|
|
456
|
+
'div',
|
|
457
|
+
{ style: { display: 'flex', gap: 6 } },
|
|
458
|
+
h('button', { style: C.button, onClick: () => setSelected(new Set(workspaces.map((w) => w.id))) }, t('selectAll')),
|
|
459
|
+
h('button', { style: C.button, onClick: () => setSelected(new Set()) }, t('selectNone')),
|
|
460
|
+
h('button', { style: C.button, onClick: cleanup }, t('cleanup')),
|
|
461
|
+
),
|
|
462
|
+
),
|
|
463
|
+
h('div', { style: C.hint }, t('projectsHint')),
|
|
464
|
+
cleanupNote ? h('div', { style: C.hint }, cleanupNote) : null,
|
|
465
|
+
workspaces.length === 0
|
|
466
|
+
? h('div', { style: C.hint }, t('empty'))
|
|
467
|
+
: h(
|
|
468
|
+
'div',
|
|
469
|
+
{ style: { display: 'flex', flexDirection: 'column' } },
|
|
470
|
+
...workspaces.map((workspace) =>
|
|
471
|
+
h(
|
|
472
|
+
'div',
|
|
473
|
+
{ key: workspace.id, style: C.row },
|
|
474
|
+
h(Checkbox, { checked: active.has(workspace.id), onChange: () => toggle(workspace.id) }),
|
|
475
|
+
h(
|
|
476
|
+
'div',
|
|
477
|
+
{ style: C.rowText },
|
|
478
|
+
h('div', { style: C.rowTitle }, workspace.title),
|
|
479
|
+
h('div', { style: C.mono, title: workspace.path }, workspace.path),
|
|
480
|
+
),
|
|
481
|
+
h('span', { style: C.badge }, `${workspace.sessionIds.length} ${t('sessionCount')}`),
|
|
482
|
+
),
|
|
483
|
+
),
|
|
484
|
+
),
|
|
485
|
+
),
|
|
486
|
+
h(
|
|
487
|
+
'div',
|
|
488
|
+
{ style: C.card },
|
|
489
|
+
h('label', { style: C.label }, h(Checkbox, { checked: includeFiles, onChange: setIncludeFiles }), t('files')),
|
|
490
|
+
h('div', { style: C.hint }, t('filesHint')),
|
|
491
|
+
h('label', { style: C.label }, h(Checkbox, { checked: includeAttachments, onChange: setIncludeAttachments }), t('attachments')),
|
|
492
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 5 } },
|
|
493
|
+
h('div', { style: C.hint }, t('outDir')),
|
|
494
|
+
h('input', {
|
|
495
|
+
style: C.input,
|
|
496
|
+
value: outDir,
|
|
497
|
+
placeholder: inventory ? inventory.migrationsDir : '',
|
|
498
|
+
onChange: (event) => setOutDir(event.target.value),
|
|
499
|
+
spellCheck: false,
|
|
500
|
+
}),
|
|
501
|
+
h('div', { style: C.hint }, t('outDirHint')),
|
|
502
|
+
),
|
|
503
|
+
h(
|
|
504
|
+
'div',
|
|
505
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 10 } },
|
|
506
|
+
h(
|
|
507
|
+
'button',
|
|
508
|
+
{
|
|
509
|
+
style: running || active.size === 0 ? { ...C.primary, ...C.primaryOff } : C.primary,
|
|
510
|
+
disabled: running || active.size === 0,
|
|
511
|
+
onClick: () =>
|
|
512
|
+
run('export', {
|
|
513
|
+
workspaceIds: [...active],
|
|
514
|
+
includeFiles,
|
|
515
|
+
includeAttachments,
|
|
516
|
+
outDir: outDir.trim() || null,
|
|
517
|
+
}),
|
|
518
|
+
},
|
|
519
|
+
running ? t('exportRunning') : t('startExport'),
|
|
520
|
+
),
|
|
521
|
+
),
|
|
522
|
+
bundles.length > 0
|
|
523
|
+
? h(
|
|
524
|
+
'div',
|
|
525
|
+
{
|
|
526
|
+
style: {
|
|
527
|
+
display: 'flex',
|
|
528
|
+
flexDirection: 'column',
|
|
529
|
+
gap: 7,
|
|
530
|
+
borderTop: '1px solid var(--dsw-alias-border-l1)',
|
|
531
|
+
paddingTop: 11,
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
h('div', { style: C.cardTitle }, t('update')),
|
|
535
|
+
h('div', { style: C.hint }, t('updateHint')),
|
|
536
|
+
h(
|
|
537
|
+
'div',
|
|
538
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
539
|
+
bundles.length > 0
|
|
540
|
+
? h(
|
|
541
|
+
'select',
|
|
542
|
+
{
|
|
543
|
+
style: { ...C.input, flex: 1 },
|
|
544
|
+
value: updateTarget,
|
|
545
|
+
onChange: (event) => setUpdateTarget(event.target.value),
|
|
546
|
+
},
|
|
547
|
+
...bundles.map((bundle) =>
|
|
548
|
+
h(
|
|
549
|
+
'option',
|
|
550
|
+
{ key: bundle.path, value: bundle.path },
|
|
551
|
+
`${bundle.name} · ${bundle.sessions} ${t('sessions')}`,
|
|
552
|
+
),
|
|
553
|
+
),
|
|
554
|
+
)
|
|
555
|
+
: null,
|
|
556
|
+
h(
|
|
557
|
+
'button',
|
|
558
|
+
{
|
|
559
|
+
style: running ? { ...C.button, ...C.primaryOff } : C.button,
|
|
560
|
+
disabled: running || !updateTarget,
|
|
561
|
+
onClick: () =>
|
|
562
|
+
run('export', {
|
|
563
|
+
mode: 'update',
|
|
564
|
+
bundlePath: updateTarget,
|
|
565
|
+
includeFiles,
|
|
566
|
+
includeAttachments,
|
|
567
|
+
}),
|
|
568
|
+
},
|
|
569
|
+
t('updateNow'),
|
|
570
|
+
),
|
|
571
|
+
),
|
|
572
|
+
h('input', {
|
|
573
|
+
style: C.input,
|
|
574
|
+
value: updateTarget,
|
|
575
|
+
placeholder: 'D:\\path\\to\\dsh-migration-…',
|
|
576
|
+
onChange: (event) => setUpdateTarget(event.target.value),
|
|
577
|
+
spellCheck: false,
|
|
578
|
+
}),
|
|
579
|
+
)
|
|
580
|
+
: null,
|
|
581
|
+
h(Progress, { task }),
|
|
582
|
+
h(TaskResult, { t, task, kind: 'export' }),
|
|
583
|
+
),
|
|
584
|
+
task && task.phase === 'done' && task.result
|
|
585
|
+
? h('button', { style: C.button, onClick: reload }, '刷新列表')
|
|
586
|
+
: null,
|
|
587
|
+
)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function ImportPane(props) {
|
|
591
|
+
const { t, inventory, reload } = props
|
|
592
|
+
const bundles = inventory ? inventory.bundles : []
|
|
593
|
+
const [bundlePath, setBundlePath] = useState('')
|
|
594
|
+
const [preview, setPreview] = useState(null)
|
|
595
|
+
const [remap, setRemap] = useState({})
|
|
596
|
+
const [includeFiles, setIncludeFiles] = useState(true)
|
|
597
|
+
const [includeAttachments, setIncludeAttachments] = useState(true)
|
|
598
|
+
const [overwriteFiles, setOverwriteFiles] = useState(false)
|
|
599
|
+
const [rootDir, setRootDir] = useState('')
|
|
600
|
+
const [rewritePaths, setRewritePaths] = useState(true)
|
|
601
|
+
const [check, setCheck] = useState(null)
|
|
602
|
+
const [checking, setChecking] = useState(false)
|
|
603
|
+
const [loadError, setLoadError] = useState(null)
|
|
604
|
+
const [undoNote, setUndoNote] = useState(null)
|
|
605
|
+
const { task, run } = usePolling(t)
|
|
606
|
+
const running = task && task.phase === 'running'
|
|
607
|
+
|
|
608
|
+
const undo = async (result) => {
|
|
609
|
+
if (!window.confirm(t('undoConfirm'))) return
|
|
610
|
+
try {
|
|
611
|
+
const report = await api.post('/rollback', {
|
|
612
|
+
workspaceIds: (result.workspaces || []).map((workspace) => workspace.id),
|
|
613
|
+
sessionIds: result.importedSessions || [],
|
|
614
|
+
})
|
|
615
|
+
const entries = [...(report.workspaces || []), ...(report.sessions || [])]
|
|
616
|
+
const removed = entries.filter((entry) => entry.removed).length
|
|
617
|
+
const refused = entries.filter((entry) => entry.refused).length
|
|
618
|
+
setUndoNote(`${t('undone')} ${removed}${refused > 0 ? ` · ${t('refused')} ${refused}` : ''}`)
|
|
619
|
+
reload()
|
|
620
|
+
} catch (error) {
|
|
621
|
+
setLoadError(error instanceof Error ? error.message : String(error))
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
useEffect(() => {
|
|
626
|
+
if (!bundlePath && bundles.length > 0) setBundlePath(bundles[0].path)
|
|
627
|
+
}, [bundles, bundlePath])
|
|
628
|
+
|
|
629
|
+
const posixTarget = Boolean(
|
|
630
|
+
preview && (preview.workspaces || []).some((workspace) => String(workspace.path || '').startsWith('/')),
|
|
631
|
+
)
|
|
632
|
+
const targetSeparator = posixTarget ? '/' : '\\'
|
|
633
|
+
|
|
634
|
+
const applyRoot = (value) => {
|
|
635
|
+
setRootDir(value)
|
|
636
|
+
if (!preview) return
|
|
637
|
+
const trimmed = value.trim()
|
|
638
|
+
// Follow the separator style of what was typed, then of the bundle:
|
|
639
|
+
// a POSIX bundle imported on Linux must never grow backslashes.
|
|
640
|
+
const separator =
|
|
641
|
+
trimmed.startsWith('/') || (trimmed.includes('/') && !trimmed.includes('\\')) ? '/' : targetSeparator
|
|
642
|
+
const base = trimmed.replace(/[\\/]+$/, '')
|
|
643
|
+
const next = { ...remap }
|
|
644
|
+
for (const workspace of preview.workspaces || []) {
|
|
645
|
+
const name = String(workspace.title || workspace.path)
|
|
646
|
+
.replace(/[\\/:*?"<>|]/g, ' ')
|
|
647
|
+
.trim()
|
|
648
|
+
next[workspace.path] = base ? `${base}${separator}${name}` : workspace.path
|
|
649
|
+
}
|
|
650
|
+
setRemap(next)
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const runCheck = async () => {
|
|
654
|
+
if (!bundlePath) return
|
|
655
|
+
setChecking(true)
|
|
656
|
+
setCheck(null)
|
|
657
|
+
try {
|
|
658
|
+
setCheck(await api.get(`/check?path=${encodeURIComponent(bundlePath)}`))
|
|
659
|
+
} catch (error) {
|
|
660
|
+
setLoadError(error instanceof Error ? error.message : String(error))
|
|
661
|
+
} finally {
|
|
662
|
+
setChecking(false)
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const load = async (path) => {
|
|
667
|
+
setCheck(null)
|
|
668
|
+
setLoadError(null)
|
|
669
|
+
setPreview(null)
|
|
670
|
+
try {
|
|
671
|
+
const value = await api.get(`/preview?path=${encodeURIComponent(path)}`)
|
|
672
|
+
setPreview(value)
|
|
673
|
+
const next = {}
|
|
674
|
+
for (const workspace of value.workspaces || []) next[workspace.path] = workspace.path
|
|
675
|
+
setRemap(next)
|
|
676
|
+
} catch (error) {
|
|
677
|
+
setLoadError(error instanceof Error ? error.message : String(error))
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return h(
|
|
682
|
+
'div',
|
|
683
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 14 } },
|
|
684
|
+
h(
|
|
685
|
+
'div',
|
|
686
|
+
{ style: C.card },
|
|
687
|
+
h('div', { style: C.cardTitle }, t('bundlePath')),
|
|
688
|
+
bundles.length > 0
|
|
689
|
+
? h(
|
|
690
|
+
'div',
|
|
691
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
692
|
+
h(
|
|
693
|
+
'select',
|
|
694
|
+
{
|
|
695
|
+
style: { ...C.input, flex: 1 },
|
|
696
|
+
value: bundlePath,
|
|
697
|
+
onChange: (event) => setBundlePath(event.target.value),
|
|
698
|
+
},
|
|
699
|
+
...bundles.map((bundle) =>
|
|
700
|
+
h('option', { key: bundle.path, value: bundle.path },
|
|
701
|
+
`${bundle.name} · ${bundle.sessions} ${t('sessions')} · ${fmtBytes(bundle.bytes || 0)}`),
|
|
702
|
+
),
|
|
703
|
+
),
|
|
704
|
+
h('button', { style: C.button, onClick: () => load(bundlePath) }, t('loadPreview')),
|
|
705
|
+
)
|
|
706
|
+
: h('div', { style: C.hint }, t('noBundles')),
|
|
707
|
+
h('div', { style: { display: 'flex', gap: 8 } },
|
|
708
|
+
h('input', {
|
|
709
|
+
style: C.input,
|
|
710
|
+
value: bundlePath,
|
|
711
|
+
placeholder: 'D:\\path\\to\\dsh-migration-…',
|
|
712
|
+
onChange: (event) => setBundlePath(event.target.value),
|
|
713
|
+
spellCheck: false,
|
|
714
|
+
}),
|
|
715
|
+
h('button', { style: C.button, onClick: () => bundlePath && load(bundlePath) }, t('loadPreview')),
|
|
716
|
+
),
|
|
717
|
+
h(
|
|
718
|
+
'div',
|
|
719
|
+
{ style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
720
|
+
h(
|
|
721
|
+
'button',
|
|
722
|
+
{
|
|
723
|
+
style: checking ? { ...C.button, ...C.primaryOff } : C.button,
|
|
724
|
+
disabled: checking || !bundlePath,
|
|
725
|
+
onClick: runCheck,
|
|
726
|
+
},
|
|
727
|
+
checking ? t('checkupRunning') : t('checkup'),
|
|
728
|
+
),
|
|
729
|
+
check
|
|
730
|
+
? h(
|
|
731
|
+
'span',
|
|
732
|
+
{ style: check.totalMissing === 0 ? C.ok : C.warn },
|
|
733
|
+
`${check.sessions} ${t('sessions')} · ${check.totalRefs} ${t('refs')} · ${check.totalMissing} ${t('missingRefs')}`,
|
|
734
|
+
)
|
|
735
|
+
: null,
|
|
736
|
+
),
|
|
737
|
+
check && check.advice ? h('div', { style: C.warn }, `${t('attachmentAdvice')}: ${check.advice}`) : null,
|
|
738
|
+
check && check.problems.length > 0
|
|
739
|
+
? h(
|
|
740
|
+
'div',
|
|
741
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 3, maxHeight: 150, overflowY: 'auto' } },
|
|
742
|
+
...check.problems.map((problem) =>
|
|
743
|
+
h('div', { key: problem.id, style: C.hint }, `• ${problem.id} — ${problem.missing}/${problem.refs}`),
|
|
744
|
+
),
|
|
745
|
+
)
|
|
746
|
+
: null,
|
|
747
|
+
loadError ? h('div', { style: C.error }, loadError) : null,
|
|
748
|
+
),
|
|
749
|
+
preview
|
|
750
|
+
? h(
|
|
751
|
+
'div',
|
|
752
|
+
{ style: C.card },
|
|
753
|
+
h('div', { style: C.cardTitle }, t('preview')),
|
|
754
|
+
h(Kv, { label: t('createdAt'), value: fmtTime(preview.createdAt) }),
|
|
755
|
+
h(Kv, { label: t('source'), value: `${preview.source.host || '—'} · ${preview.source.platform || '—'}` }),
|
|
756
|
+
h(Kv, { label: t('formatVersion'), value: preview.formatVersion ? `v${preview.formatVersion}` : '—' }),
|
|
757
|
+
h(Kv, { label: t('sessions'), value: String(preview.sessions) }),
|
|
758
|
+
h(Kv, { label: t('bytes'), value: fmtBytes(preview.bytes || 0) }),
|
|
759
|
+
)
|
|
760
|
+
: null,
|
|
761
|
+
preview && (preview.workspaces || []).length > 0
|
|
762
|
+
? h(
|
|
763
|
+
'div',
|
|
764
|
+
{ style: C.card },
|
|
765
|
+
h('div', { style: C.cardTitle }, t('remap')),
|
|
766
|
+
h('div', { style: C.hint }, t('remapHint')),
|
|
767
|
+
h(
|
|
768
|
+
'div',
|
|
769
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: 5, padding: '4px 0 10px' } },
|
|
770
|
+
h('div', { style: C.cardTitle }, t('importRoot')),
|
|
771
|
+
h('input', {
|
|
772
|
+
style: C.input,
|
|
773
|
+
value: rootDir,
|
|
774
|
+
placeholder: posixTarget ? '/home/<user>/dsh' : 'E:\\DSH',
|
|
775
|
+
onChange: (event) => applyRoot(event.target.value),
|
|
776
|
+
spellCheck: false,
|
|
777
|
+
}),
|
|
778
|
+
h('div', { style: C.hint }, t('importRootHint')),
|
|
779
|
+
),
|
|
780
|
+
...(preview.workspaces || []).map((workspace) =>
|
|
781
|
+
h(
|
|
782
|
+
'div',
|
|
783
|
+
{ key: workspace.id, style: { display: 'flex', flexDirection: 'column', gap: 5 } },
|
|
784
|
+
h(
|
|
785
|
+
'div',
|
|
786
|
+
{ style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
|
787
|
+
h('span', { style: C.rowTitle }, workspace.title),
|
|
788
|
+
h('span', { style: C.badge }, `${workspace.sessions} ${t('sessionCount')} · ${fmtBytes(workspace.bytes || 0)}`),
|
|
789
|
+
),
|
|
790
|
+
h('div', { style: C.mono }, `${t('from')}: ${workspace.path}`),
|
|
791
|
+
h('input', {
|
|
792
|
+
style: C.input,
|
|
793
|
+
value: remap[workspace.path] ?? workspace.path,
|
|
794
|
+
onChange: (event) => setRemap({ ...remap, [workspace.path]: event.target.value }),
|
|
795
|
+
spellCheck: false,
|
|
796
|
+
}),
|
|
797
|
+
),
|
|
798
|
+
),
|
|
799
|
+
)
|
|
800
|
+
: null,
|
|
801
|
+
preview
|
|
802
|
+
? h(
|
|
803
|
+
'div',
|
|
804
|
+
{ style: C.card },
|
|
805
|
+
h('label', { style: C.label }, h(Checkbox, { checked: includeFiles, onChange: setIncludeFiles }), t('importFiles')),
|
|
806
|
+
preview.attachments
|
|
807
|
+
? h('label', { style: C.label }, h(Checkbox, { checked: includeAttachments, onChange: setIncludeAttachments }), t('attachments'))
|
|
808
|
+
: null,
|
|
809
|
+
h('label', { style: C.label }, h(Checkbox, { checked: overwriteFiles, onChange: setOverwriteFiles }), t('overwrite')),
|
|
810
|
+
h('label', { style: C.label }, h(Checkbox, { checked: rewritePaths, onChange: setRewritePaths }), t('rewritePaths')),
|
|
811
|
+
h('div', { style: C.hint }, t('rewritePathsHint')),
|
|
812
|
+
h(
|
|
813
|
+
'button',
|
|
814
|
+
{
|
|
815
|
+
style: running ? { ...C.primary, ...C.primaryOff } : C.primary,
|
|
816
|
+
disabled: running,
|
|
817
|
+
onClick: () => run('import', {
|
|
818
|
+
bundlePath,
|
|
819
|
+
remap,
|
|
820
|
+
rootDir: rootDir.trim() || null,
|
|
821
|
+
rewritePaths,
|
|
822
|
+
includeFiles,
|
|
823
|
+
includeAttachments,
|
|
824
|
+
overwriteFiles,
|
|
825
|
+
}),
|
|
826
|
+
},
|
|
827
|
+
running ? t('importRunning') : t('startImport'),
|
|
828
|
+
),
|
|
829
|
+
h(Progress, { task }),
|
|
830
|
+
h(TaskResult, { t, task, kind: 'import' }),
|
|
831
|
+
task && task.phase === 'done'
|
|
832
|
+
? h(
|
|
833
|
+
'div',
|
|
834
|
+
{ style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
835
|
+
h('button', { style: C.button, onClick: reload }, '刷新列表'),
|
|
836
|
+
(task.result.workspaces || []).length > 0
|
|
837
|
+
? h('button', { style: C.button, onClick: () => undo(task.result) }, t('undo'))
|
|
838
|
+
: null,
|
|
839
|
+
undoNote ? h('span', { style: C.ok }, undoNote) : null,
|
|
840
|
+
)
|
|
841
|
+
: null,
|
|
842
|
+
)
|
|
843
|
+
: null,
|
|
844
|
+
)
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function MigrateSection(props) {
|
|
848
|
+
const t = props.t
|
|
849
|
+
const [tab, setTab] = useState('export')
|
|
850
|
+
const [inventory, setInventory] = useState(null)
|
|
851
|
+
const [loadError, setLoadError] = useState(null)
|
|
852
|
+
|
|
853
|
+
const load = useCallback(async () => {
|
|
854
|
+
try {
|
|
855
|
+
const value = await api.get('/inventory')
|
|
856
|
+
setInventory(value)
|
|
857
|
+
setLoadError(null)
|
|
858
|
+
} catch (error) {
|
|
859
|
+
setLoadError(error instanceof Error ? error.message : String(error))
|
|
860
|
+
}
|
|
861
|
+
}, [])
|
|
862
|
+
|
|
863
|
+
useEffect(() => {
|
|
864
|
+
load()
|
|
865
|
+
}, [load])
|
|
866
|
+
|
|
867
|
+
return h(
|
|
868
|
+
'div',
|
|
869
|
+
{ style: C.page },
|
|
870
|
+
h('div', null, h('h1', { style: C.h1 }, t('title')), h('p', { style: C.sub }, t('subtitle'))),
|
|
871
|
+
loadError ? h('div', { style: C.error }, loadError) : null,
|
|
872
|
+
!inventory && !loadError ? h('div', { style: C.hint }, t('loading')) : null,
|
|
873
|
+
h(
|
|
874
|
+
'div',
|
|
875
|
+
{ style: C.tabs },
|
|
876
|
+
h('button', { style: { ...C.tab, ...(tab === 'export' ? C.tabActive : {}) }, onClick: () => setTab('export') }, t('tabExport')),
|
|
877
|
+
h('button', { style: { ...C.tab, ...(tab === 'import' ? C.tabActive : {}) }, onClick: () => setTab('import') }, t('tabImport')),
|
|
878
|
+
),
|
|
879
|
+
tab === 'export'
|
|
880
|
+
? h(ExportPane, { t, inventory, reload: load })
|
|
881
|
+
: h(ImportPane, { t, inventory, reload: load }),
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
return {
|
|
886
|
+
inject: ['slots', 'locale'],
|
|
887
|
+
apply(ctx) {
|
|
888
|
+
const dicts = { zh: ZH, en: EN }
|
|
889
|
+
const locale = ctx.get('locale')
|
|
890
|
+
ctx.effect(() => ctx.locale.register(NS, 'zh', dicts.zh))
|
|
891
|
+
ctx.effect(() => ctx.locale.register(NS, 'en', dicts.en))
|
|
892
|
+
const translate = ctx.locale.bind(NS)
|
|
893
|
+
const t = (key) => {
|
|
894
|
+
try {
|
|
895
|
+
return translate(key) || key
|
|
896
|
+
} catch {
|
|
897
|
+
return key
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function Section() {
|
|
902
|
+
if (locale && locale.subscribe) {
|
|
903
|
+
React.useSyncExternalStore(
|
|
904
|
+
(callback) => ctx.locale.subscribe(callback),
|
|
905
|
+
() => ctx.locale.getSnapshot(),
|
|
906
|
+
() => ctx.locale.getSnapshot(),
|
|
907
|
+
)
|
|
908
|
+
}
|
|
909
|
+
return h(MigrateSection, { t })
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
ctx.slots.inject('settings.section', () =>
|
|
913
|
+
ctx.slots.register(
|
|
914
|
+
{
|
|
915
|
+
name: 'settings.section',
|
|
916
|
+
id: 'migration',
|
|
917
|
+
order: 30,
|
|
918
|
+
label: () => t('title'),
|
|
919
|
+
},
|
|
920
|
+
Section,
|
|
921
|
+
),
|
|
922
|
+
)
|
|
923
|
+
},
|
|
924
|
+
}
|
|
925
|
+
},
|
|
926
|
+
})
|