feat(vault): 库面板维护 — 重新定位/修复/全部检查(v3.26.265)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 46s

- 每行 ⋯:重命名/复制路径/重新定位…/移除(当前库禁用)
- 失效行内「修复」(重新定位)、权限不足「重新授权」
- relocate 只改登记;重复路径提示合并;当前库重定位同步指针并重载
- 顶部「N 个库需要处理」+「全部检查」;失效项排末尾
- 新增 registry.setPath;单测 +4(relocate×3、reauthorize)
This commit is contained in:
qiqi committed 2026-12-06 13:52:01 +08:00
1 parent ed7ce0051b
commit 4a84ebc615
9 files changed
+154 -11

No files matched your search

+8
View File
@@ -20,6 +20,14 @@
- 历史条目补录:该 tag 当时未在 CHANGELOG 记录(release-records 守卫要求 tag 与条目双向一致),内容按当时提交补一句占位说明。
## v3.26.265(2026-12-06)库面板维护:重新定位 / 修复 / 全部检查
- 每一行都有「⋯」菜单:重命名 / 复制路径 / 重新定位… / 从列表移除(当前库禁用移除)
- 失效库(路径缺失 / 不是数据库)行内直接显示「修复」;权限不足显示「重新授权」
- 重新定位只改登记路径;目标已被另一条登记占用时提示合并(只保留一条);当前库重定位后同步指针并重载
- 面板顶部提示「N 个库需要处理」+「全部检查」;失效项排在列表末尾(当前库仍置顶)
- 探测前补授权(沿用 264),避免可用库被误显示为「路径不可用」
## v3.26.264(2026-12-06)多库修复:启动误判 + 恢复页出口 + 库名显示
- 修复 263 的「数据库无法打开 / 文件夹不存在」误判:启动时**先授权再校验**;fs.exists 被权限拒绝时提示「权限不足」,不再当成路径不存在
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.26.264",
"version": "3.26.265",
"description": "Browser-based node canvas image workbench",
"scripts": {
"build": "node scripts/build.js && node scripts/copy-plugins.js",
+1 -1
View File
@@ -2014,7 +2014,7 @@ dependencies = [
[[package]]
name = "image-workbench"
version = "3.26.264"
version = "3.26.265"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.26.264"
version = "3.26.265"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.26.264",
"version": "3.26.265",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+24 -5
View File
@@ -88,12 +88,19 @@
}
const syncing = rows.some((r) => r.current && r.sync)
const isBad = (x) => !!(x.info && (!x.info.exists || !x.info.hasData || !x.info.dataOk))
const badCount = rows.filter(isBad).length
const sorted = rows.slice().sort((a, b) =>
(b.current ? 1 : 0) - (a.current ? 1 : 0) ||
(isBad(a) ? 1 : 0) - (isBad(b) ? 1 : 0) ||
(Number(b.lastUsedAt) || 0) - (Number(a.lastUsedAt) || 0)
)
const rowEl = (r) => {
const isEdit = editing && editing.id === r.id
const when = r.info && r.info.dataMtime ? new Date(r.info.dataMtime).toLocaleString('zh-CN', { hour12: false }) : ''
let meta
if (!r.info || !r.info.exists) meta = (r.info && r.info.denied) ? '权限不足(点「切换」重新授权)' : '路径缺失'
if (!r.info || !r.info.exists) meta = (r.info && r.info.denied) ? '权限不足(点「重新授权」)' : '路径缺失'
else if (!r.info.hasData) meta = '不是数据库(缺 data.json)'
else if (!r.info.dataOk) meta = 'data.json 无法解析'
else meta = (r.info.boards + ' 个画板') + (when ? ' · ' + when : '')
@@ -127,15 +134,21 @@
el('div', { style: pathSt, title: r.path }, r.path),
el('div', { style: { fontSize: '11px', color: '#8a8a8a', marginTop: '2px' } }, meta || '—'),
),
r.current
? el('button', { style: ghost, title: '更多操作', onClick: () => setMenuFor(menuFor === r.id ? '' : r.id) }, '⋯')
: el('button', { style: btn(false), disabled: !!busy, onClick: () => doAction('switch', () => ctl.switchTo(r.path)) }, busy === 'switch' ? '切换中…' : '切换'),
(() => {
if (r.current) return null
const info = r.info || {}
if (info.denied) return el('button', { style: btn(false), disabled: !!busy, onClick: () => doAction('auth', () => ctl.reauthorize(r.id)) }, busy === 'auth' ? '授权中…' : '重新授权')
if (!info.exists || !info.hasData || !info.dataOk) return el('button', { style: btn(false), disabled: !!busy, onClick: () => doAction('relocate', () => ctl.relocate(r.id)) }, busy === 'relocate' ? '定位中…' : '修复')
return el('button', { style: btn(false), disabled: !!busy, onClick: () => doAction('switch', () => ctl.switchTo(r.path)) }, busy === 'switch' ? '切换中…' : '切换')
})(),
el('button', { style: ghost, title: '更多操作', onClick: () => setMenuFor(menuFor === r.id ? '' : r.id) }, '⋯'),
menuFor === r.id ? el('div', {
style: { position: 'absolute', right: '18px', top: '44px', zIndex: 3, background: '#fff', border: '1px solid #c2c2c2', borderRadius: '8px', boxShadow: '0 10px 24px rgba(0,0,0,.14)', padding: '4px', minWidth: '132px' },
onPointerDown: (e) => e.stopPropagation(),
},
el('button', { style: Object.assign({}, ghost, { display: 'block', width: '100%', textAlign: 'left' }), onClick: () => { setMenuFor(''); setEditing({ id: r.id, value: r.name }) } }, '重命名'),
el('button', { style: Object.assign({}, ghost, { display: 'block', width: '100%', textAlign: 'left' }), onClick: () => { setMenuFor(''); try { global.navigator.clipboard.writeText(r.path) } catch (e) { /* ignore */ } setMsg('路径已复制') } }, '复制路径'),
el('button', { style: Object.assign({}, ghost, { display: 'block', width: '100%', textAlign: 'left' }), onClick: () => { setMenuFor(''); doAction('relocate', () => ctl.relocate(r.id)) } }, '重新定位…'),
!r.current ? el('button', { style: Object.assign({}, ghost, { display: 'block', width: '100%', textAlign: 'left', color: '#b91c1c' }), onClick: () => { setMenuFor(''); doAction('remove', () => ctl.remove(r.id)) } }, '从列表移除') : null,
) : null,
)
@@ -155,8 +168,14 @@
el('button', { style: ghost, 'aria-label': '关闭', onClick: () => onClose && onClose() }, '✕'),
),
syncing ? el('div', { style: { margin: '0 12px 8px', padding: '8px 10px', borderRadius: '8px', background: '#fdf6ec', border: '1px solid #f0d7b8', color: '#8a5a20', fontSize: '11px', lineHeight: 1.5 } }, '⚠ 当前库在同步目录里,建议只查看;在这里编辑可能会被同步回另一台电脑。') : null,
badCount ? el('div', {
style: { margin: '0 12px 8px', padding: '6px 10px', borderRadius: '8px', background: '#fff5f5', border: '1px solid #f3c9c9', color: '#9b2c2c', fontSize: '11px', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
},
el('span', null, badCount + ' 个库需要处理'),
el('button', { style: ghost, disabled: !!busy, onClick: () => doAction('check', async () => ({ ok: true })) }, busy === 'check' ? '检查中…' : '全部检查'),
) : null,
el('div', { style: { padding: '2px 8px 8px', maxHeight: '46vh', overflow: 'auto' } },
rows.length ? rows.map(rowEl) : el('div', { style: { fontSize: '12px', color: '#8a8a8a', padding: '12px 8px' } }, '还没有登记任何库'),
rows.length ? sorted.map(rowEl) : el('div', { style: { fontSize: '12px', color: '#8a8a8a', padding: '12px 8px' } }, '还没有登记任何库'),
msg ? el('div', { style: { fontSize: '11px', color: '#b91c1c', padding: '6px 8px' } }, msg) : null,
),
el('div', { style: foot },
+61 -1
View File
@@ -171,6 +171,66 @@
return { ok: true }
}
function isCurrentId(id) {
try {
const Rg = R()
const d = Rg.read()
const it = (d.items || []).find((x) => x.id === id)
return !!(it && Rg.pathKey(it.path) === Rg.pathKey(currentPath()))
} catch (e) { return false }
}
/** 重新定位:只改登记里的路径;若指向当前库则同步指针并重载 */
async function relocate(id) {
const Rg = R()
const d0 = Rg.read()
const it = (d0.items || []).find((x) => x.id === id)
if (!it) return { ok: false, code: 'missing' }
const dir = await SF().pickDir()
if (!dir) return { ok: false, code: 'cancel' }
const p = Rg.normalizePath(dir)
const nfo = await info(p)
if (!nfo.exists) return { ok: false, code: nfo.denied ? 'denied' : 'missing', path: p }
if (!nfo.hasData) return { ok: false, code: 'no-data', path: p }
if (!nfo.dataOk) return { ok: false, code: 'bad-data', path: p }
// 目标路径已被另一条登记占用 → 询问合并(保留当前这条,移除重复的那条)
const dup = (d0.items || []).find((x) => x.id !== id && Rg.pathKey(x.path) === Rg.pathKey(p))
let d = d0
if (dup) {
if (Rg.pathKey(p) === Rg.pathKey(currentPath())) {
const yes = await confirmAsk('目标路径就是当前库「' + dup.name + '」。要把这条失效记录直接移除吗?')
if (!yes) return { ok: false, code: 'cancel' }
const r = Rg.remove(d0, id)
Rg.write(r.doc)
return { ok: true, merged: 'removed' }
}
const yes = await confirmAsk('目标路径已经被「' + dup.name + '」登记。合并后只保留当前这条,继续?')
if (!yes) return { ok: false, code: 'cancel' }
d = Rg.remove(d0, dup.id).doc
}
const r2 = Rg.setPath(d, id, p)
if (!r2.ok) return { ok: false, code: 'invalid' }
Rg.write(r2.doc)
if (isCurrentId(id)) {
try { await SF().flush() } catch (e) { /* ignore */ }
try { global.localStorage.setItem(PTR, p) } catch (e) { /* ignore */ }
reload()
}
return { ok: true }
}
/** 权限不足时重新授权并复检 */
async function reauthorize(id) {
const Rg = R()
const d = Rg.read()
const it = (d.items || []).find((x) => x.id === id)
if (!it) return { ok: false, code: 'missing' }
try { if (SF().grantDir) await SF().grantDir(it.path) } catch (e) { /* ignore */ }
const nfo = await info(it.path)
if (nfo.exists && nfo.hasData && nfo.dataOk) return { ok: true }
return { ok: false, code: nfo.denied ? 'denied' : (nfo.exists ? (nfo.hasData ? 'bad-data' : 'no-data') : 'missing') }
}
async function rowsWithInfo() {
const rows = list()
const out = await Promise.all(rows.map(async (x) => ({ ...x, info: await info(x.path) })))
@@ -195,7 +255,7 @@
} catch (e) { return { ok: false, code: 'bad-format' } }
}
return { list, rowsWithInfo, currentName, currentPath, switchTo, createNew, openExisting, rename, remove, info, exportDoc, importDoc }
return { list, rowsWithInfo, currentName, currentPath, switchTo, createNew, openExisting, rename, remove, relocate, reauthorize, isCurrentId, info, exportDoc, importDoc }
}
const api = { create }
+13 -1
View File
@@ -129,6 +129,18 @@
return { doc, ok: true }
}
/** 只改登记里的路径(重新定位用);同路径冲突由调用方先处理 */
function setPath(doc, id, path) {
const it = (doc.items || []).find((x) => x.id === id)
if (!it) return { doc, ok: false }
const p = normalizePath(path)
if (!p) return { doc, ok: false }
it.path = p
it.lastUsedAt = now()
if (pathKey(doc.current) === pathKey(it.path)) doc.current = p
return { doc, ok: true }
}
function setCurrent(doc, path) {
const p = normalizePath(path)
doc.current = p
@@ -137,7 +149,7 @@
return doc
}
return { KEY, normalizePath, pathKey, baseName, isSyncPath, uniqueName, read, write, add, remove, rename, setCurrent, findByPath, empty }
return { KEY, normalizePath, pathKey, baseName, isSyncPath, uniqueName, read, write, add, remove, rename, setPath, setCurrent, findByPath, empty }
}
const api = { create, normalizePath, pathKey, baseName, isSyncPath, uniqueName }
+44
View File
@@ -28,6 +28,7 @@ function makeEnv(opts) {
flush: async () => true,
dirtyCount: () => o.dirty || 0,
pickDir: async () => o.pickDir || '',
grantDir: async () => true,
createVaultAt: async (p) => { files[p] = { data: true }; return { ok: true } },
vaultProbe: async (p) => {
if (files[p] === undefined) return { exists: false }
@@ -125,3 +126,46 @@ test('rename:重名自动加序号', async () => {
assert.notEqual(names[0], names[1])
})
test('relocate:重新定位只改登记路径', async () => {
const e = makeEnv({ pointer: '/Users/x/A', files: { '/Users/x/A': 'ok', '/Users/x/New': 'ok' }, pickDir: '/Users/x/New' })
const R = e.R.create({ storage: e.g.localStorage })
let d = R.add(R.read(), '/Users/x/Old', '旧位置')
R.write(d.doc)
const oldRow = e.ctl.list().find((x) => x.path === '/Users/x/Old')
const r = await e.ctl.relocate(oldRow.id)
assert.equal(r.ok, true)
const rows = e.ctl.list()
assert.equal(rows.some((x) => x.path === '/Users/x/Old'), false)
assert.equal(rows.some((x) => x.path === '/Users/x/New'), true)
})
test('relocate:目标不是库 → 不修改登记', async () => {
const e = makeEnv({ pointer: '/Users/x/A', files: { '/Users/x/A': 'ok', '/Users/x/Empty': 'nodata' }, pickDir: '/Users/x/Empty' })
const R = e.R.create({ storage: e.g.localStorage })
const d = R.add(R.read(), '/Users/x/Old', '旧位置'); R.write(d.doc)
const row = e.ctl.list().find((x) => x.path === '/Users/x/Old')
const r = await e.ctl.relocate(row.id)
assert.equal(r.ok, false)
assert.equal(r.code, 'no-data')
assert.equal(e.ctl.list().some((x) => x.path === '/Users/x/Old'), true)
})
test('relocate:目标已被另一条登记 → 合并后只留一条', async () => {
const e = makeEnv({ pointer: '/Users/x/A', files: { '/Users/x/A': 'ok', '/Users/x/B': 'ok' }, pickDir: '/Users/x/B' })
const R = e.R.create({ storage: e.g.localStorage })
let d = R.add(R.read(), '/Users/x/A', 'A'); R.write(d.doc)
d = R.add(R.read(), '/Users/x/Old', '旧位置'); R.write(d.doc)
const row = e.ctl.list().find((x) => x.path === '/Users/x/Old')
const r = await e.ctl.relocate(row.id)
assert.equal(r.ok, true)
const rows = e.ctl.list()
assert.equal(rows.filter((x) => x.path === '/Users/x/B').length, 1)
})
test('reauthorize:授权后探测通过返回 ok', async () => {
const e = makeEnv({ pointer: '/Users/x/A', files: { '/Users/x/A': 'ok' } })
const rows = e.ctl.list()
const r = await e.ctl.reauthorize(rows[0].id)
assert.equal(r.ok, true)
})