fix(gallery): 收紧插入取源顺序与归档通知时序(自查发现)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m35s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m35s
- localCopySrcOf 取源改为「原图文件 → 远程原图(8s 上限)→ 缩略图」:上一版把 320 缩略图 排在远程之前,会出现「有远程原图却插进一张小图」,标注完导出才发现糊了。顺序与宿主既有 口径(wResolveOutputSrc 默认 url 优先于 localData)一致;超时保护避免慢图床拖着插入不放。 - refreshOutputs 改为返回 Promise:逐张归档要在 emit 之前确认 React outputs 已换成新列表 (插件的 list/thumb 读的就是这份 state),否则通知到了却还是旧列表。 - 新增一条测试守住「别拿缩略图顶替远程原图」;BACKLOG 记 1.2(标注插件「转存」文案无对应 入口 / 一次失败不再重试)。
This commit is contained in:
1 parent
e94012db84
commit
bf7ed841ae
4 files changed
+51
-13
No files matched your search
+16
@@ -138,6 +138,22 @@
|
||||
|
||||
---
|
||||
|
||||
### 1.2 标注插件「远程图片不支持标注」的收尾(2026-11-24 · 中等收益)
|
||||
|
||||
> 证据:`image-annotate/src/index.js:9218` 只在 `getNodeImage` 返回 `dataUrl` 时才开编辑器,否则报
|
||||
> 「该节点是远程图片,暂不支持标注(请先转存为本地位图)」。
|
||||
|
||||
v3.26.61 已把三个成因收敛掉(`getNodeImage` 补 `data.localRef` 候选 / 只有远程时按需抓字节并写回
|
||||
`localRef` / 图库插入改本地副本),但两条尾巴还在:
|
||||
|
||||
1. **文案里的「转存」没有对应入口** —— 抓取失败(离线、图床拦跨域且不在 Tauri http 白名单)时,
|
||||
用户看到「请先转存为本地位图」却找不到按钮。二选一:① 画布 ref 节点右键加「转存为本地图片」
|
||||
(`wImgRefWrite` → `localRef`);② 把文案改成可执行引导(「下载到本地后拖进画布」)。
|
||||
2. **一次失败不再重试** —— `image-remote-cache` 的 `tried` 集合记住节点 id 后永不重试;网络恢复后
|
||||
只能靠用户手动再点。可加「右键重试取图」。
|
||||
|
||||
---
|
||||
|
||||
## 2. P1 — 有明确证据支撑,价值高
|
||||
|
||||
### 2.0 ✅ 图库索引(`OUT_KEY`)跨标签页「读-改-写」—— **已修(2026-11-16,v3.24.85)**
|
||||
|
||||
+22
-12
@@ -46,15 +46,35 @@
|
||||
return job
|
||||
}
|
||||
|
||||
// 图库条目 → 本地字节。顺序:原图文件 → 清单里已 hydrate 的 data → 缩略图 →
|
||||
// 按需抓一次远程(桌面端走 Rust 侧请求,不受 CORS)→ ''(交给调用方退回原链接)
|
||||
// 图库条目 → **本地字节**(dataURL)。取源顺序沿用宿主既有口径「画质最优优先」:
|
||||
// ① 原图文件(桌面端 images/gallery,浏览器 IndexedDB)
|
||||
// ② 远程原图抓一次字节(桌面端走 Rust 请求不受 CORS;8s 超时,慢图床不拖着插入不放)
|
||||
// ③ 清单里已 hydrate 的 data / 320 缩略图(能标注,但画质将就)
|
||||
// ④ '' —— 交给调用方保留原链接,绝不阻断插入、绝不丢图
|
||||
// 注意 ②③ 的顺序:缩略图排远程之后。反过来的话「有远程原图却插进一张 320 小图」,
|
||||
// 用户标注完导出才发现糊了。
|
||||
async function localCopySrcOf (item) {
|
||||
if (!item) return ''
|
||||
const fetchRemote = async (url) => {
|
||||
if (!/^https?:/i.test(url)) return ''
|
||||
if (typeof d.isDesktop === 'function' && d.isDesktop() && typeof d.desktopFetch === 'function') {
|
||||
try { const r = await d.desktopFetch(url); if (r && r.ok) { const b = await r.blob(); const du = b && typeof d.blobToDataUrl === 'function' ? await d.blobToDataUrl(b) : ''; if (du) return du } } catch (e) { /* 白名单外/网络失败 → 落到 WebView fetch */ }
|
||||
}
|
||||
if (typeof d.blobFromSrc !== 'function') return ''
|
||||
const blob = await d.blobFromSrc(url).catch(() => null)
|
||||
return (blob && typeof d.blobToDataUrl === 'function') ? await d.blobToDataUrl(blob) : ''
|
||||
}
|
||||
try {
|
||||
if (item.origIdb && typeof d.get === 'function') {
|
||||
const v = await d.get(item.origIdb).catch(() => null)
|
||||
if (v) return v
|
||||
}
|
||||
const url = String(item.url || '')
|
||||
if (/^https?:/i.test(url)) {
|
||||
// 8s 上限:抓不到就走缩略图,别让插入卡在图床超时上
|
||||
const remote = await Promise.race([fetchRemote(url), new Promise((r) => setTimeout(() => r(''), 8000))])
|
||||
if (remote) return remote
|
||||
}
|
||||
const data = (item.data && typeof item.data === 'object' && typeof d.refDataUrl === 'function')
|
||||
? await d.refDataUrl(item.data) : item.data
|
||||
if (typeof data === 'string' && data) return data
|
||||
@@ -62,16 +82,6 @@
|
||||
const v = await d.get(item.idb).catch(() => null)
|
||||
if (v) return v
|
||||
}
|
||||
const url = String(item.url || '')
|
||||
if (/^https?:/i.test(url)) {
|
||||
let blob = null
|
||||
if (typeof d.isDesktop === 'function' && d.isDesktop() && typeof d.desktopFetch === 'function') {
|
||||
try { const r = await d.desktopFetch(url); if (r && r.ok) blob = await r.blob() } catch (e) { /* 落到 WebView fetch */ }
|
||||
}
|
||||
if (!blob && typeof d.blobFromSrc === 'function') blob = await d.blobFromSrc(url).catch(() => null)
|
||||
const du = (blob && typeof d.blobToDataUrl === 'function') ? await d.blobToDataUrl(blob) : ''
|
||||
if (du) return du
|
||||
}
|
||||
if (url.indexOf('data:') === 0) return url
|
||||
} catch (e) { /* 取不到就交给调用方兜底 */ }
|
||||
return ''
|
||||
|
||||
@@ -2100,7 +2100,9 @@
|
||||
}
|
||||
const refreshOutputs = (limit) => {
|
||||
const requestId = ++outputRequestSeq.current
|
||||
api('outputs', limit ? { limit } : undefined).then((r) => { if (requestId === outputRequestSeq.current && r && Array.isArray(r.files)) { setOutputs(r.files); setOutputsInfo(r) } }).catch(() => {})
|
||||
// v3.26.61:**返回 Promise** —— 逐张归档要在「图库插件收到通知」之前确认 React outputs 已经换成新列表
|
||||
// (插件的 list/thumb 走 impl,读的就是这份 state;不 await 就可能通知到了却还是旧列表)
|
||||
return api('outputs', limit ? { limit } : undefined).then((r) => { if (requestId === outputRequestSeq.current && r && Array.isArray(r.files)) { setOutputs(r.files); setOutputsInfo(r) } }).catch(() => {})
|
||||
}
|
||||
const deleteOutputs = (names) => {
|
||||
const list = Array.isArray(names) ? names : []
|
||||
|
||||
@@ -85,6 +85,16 @@ ok('localCopySrcOf:只剩远程时抓一次,抓到即返回 dataURL', async
|
||||
assert.strictEqual(fetched, 1)
|
||||
})
|
||||
|
||||
ok('localCopySrcOf:有远程原图时不拿 320 缩略图顶替(画质优先)', async () => {
|
||||
const s = Sync.create({
|
||||
get: async () => null,
|
||||
blobFromSrc: async () => ({ size: 9 }),
|
||||
blobToDataUrl: async () => 'data:image/png;base64,FULL',
|
||||
})
|
||||
const got = await s.localCopySrcOf({ name: 'q.png', data: 'data:image/jpeg;base64,THUMB320', url: 'https://x/q.png' })
|
||||
assert.strictEqual(got, 'data:image/png;base64,FULL', '应取远程原图,实际 ' + String(got).slice(0, 30))
|
||||
})
|
||||
|
||||
ok('localCopySrcOf:全抓不到返回空串(调用方退回原链接,不丢图)', async () => {
|
||||
const s = Sync.create({ get: async () => null, blobFromSrc: async () => null })
|
||||
assert.strictEqual(await s.localCopySrcOf({ name: 'z.png', url: 'https://blocked/y.png' }), '')
|
||||
|
||||
Reference in new issue
Block a user