fix(gallery): v3.26.135 原子写缩略图 + 合并同键生成 + 补 png 后缀(修一半卡片加载失败)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m33s

This commit is contained in:
qiqi committed 2026-11-30 20:06:50 +08:00
1 parent 7e9a99c6f2
commit fa3586b725
7 files changed
+54 -15

No files matched your search

+11
View File
@@ -16,6 +16,17 @@
> 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。
> 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。
## v3.26.135(2026-11-30)修「多次加载还是有没有显示的」:并发写坏缩略图 + png 后缀漏查
134 实测:预热 164/164 完成、失败 0,但宫格里仍有一半卡显示「缩略图加载失败」。两个原因:
- **并发写同一张 tier**:预热与宫格同时要同一 (hash,max),两边各跑一次 `img_thumbs`、直写同一文件,
另一方可能读到写了一半的 jpg ⇒ 截断图 ⇒ `<img>` onerror ⇒ 被缓存成坏 objectURL(刷新也还是坏的)。
→ `img_thumbs` 改为**先写 .tmp 再 rename**(原子);宿主侧同一 (hash,max) 的生成**合并成一个 Promise**;
读到 0 字节文件视为坏档,删掉重做。
- **png 后缀漏查**:原生 tier 对带透明的图输出 `.png`,而 `thumbFileOf` 只找 `.webp/.jpg` ⇒ 透明图永远「查不到」,
每次请求都重新生成(1515 次调用)。→ 补 `.png`。
## v3.26.134(2026-11-30)图库缩略图空闲预热
133 之后宫格不再读原图,但**第一次**打开仍要给每张图做一次 320 缩略图(实测 139 张 × 200~600ms)。
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "image-workbench-web",
"private": true,
"version": "3.26.134",
"version": "3.26.135",
"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.134"
version = "3.26.135"
dependencies = [
"arboard",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "image-workbench"
version = "3.26.134"
version = "3.26.135"
description = "无限画布 · 生图工作台桌面版"
authors = ["malongan"]
license = ""
+14 -6
View File
@@ -268,15 +268,23 @@ fn do_thumbs(src: &str, jobs: &[ThumbJob]) -> Result<serde_json::Value, String>
image::codecs::png::PngEncoder::new(&mut buf)
.write_image(rgba.as_raw(), nw, nh, image::ExtendedColorType::Rgba8)
.map_err(|e| format!("png: {e}"))?;
std::fs::write(&path, &buf).map_err(|e| format!("write: {e}"))?;
// v3.26.135:**原子写**。原来直写目标文件,预热心跳与宫格同时做同一张时,
// 另一边会读到写了一半的文件 ⇒ 截断图 ⇒ <img> onerror ⇒ 前端缓存成坏图(刷新也坏)。
let tmp = format!("{}.tmp{}", path, std::process::id());
std::fs::write(&tmp, &buf).map_err(|e| format!("write: {e}"))?;
std::fs::rename(&tmp, &path).map_err(|e| format!("rename: {e}"))?;
buf.len()
} else {
let rgb = resized.to_rgb8();
let f = std::fs::File::create(&path).map_err(|e| format!("create: {e}"))?;
let mut wr = std::io::BufWriter::new(f);
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut wr, 82)
.encode(rgb.as_raw(), nw, nh, image::ExtendedColorType::Rgb8)
.map_err(|e| format!("jpeg: {e}"))?;
let tmp = format!("{}.tmp{}", path, std::process::id());
{
let f = std::fs::File::create(&tmp).map_err(|e| format!("create: {e}"))?;
let mut wr = std::io::BufWriter::new(f);
image::codecs::jpeg::JpegEncoder::new_with_quality(&mut wr, 82)
.encode(rgb.as_raw(), nw, nh, image::ExtendedColorType::Rgb8)
.map_err(|e| format!("jpeg: {e}"))?;
}
std::fs::rename(&tmp, &path).map_err(|e| format!("rename: {e}"))?;
std::fs::metadata(&path).map(|m| m.len() as usize).unwrap_or(0)
};
out.push(serde_json::json!({ "path": path, "w": nw, "h": nh, "bytes": bytes }));
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "image-workbench",
"version": "3.26.134",
"version": "3.26.135",
"identifier": "com.malongan.imageworkbench",
"build": {
"frontendDist": "../dist",
+25 -5
View File
@@ -1156,8 +1156,10 @@
async function thumbFileOf (hash, max) {
const base = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_' + (Math.max(64, Number(max) || 768)))
for (const ext of ['.webp', '.jpg']) {
try { if (await fs().exists(base + ext)) return { path: base + ext, mime: ext === '.webp' ? 'image/webp' : 'image/jpeg' } } catch (e) { /* ignore */ }
// v3.26.135:补 .png —— 原生 tier 对**带透明**的图输出 png,原来只查 webp/jpg,
// 于是透明图的 tier 永远「查不到」⇒ 每次请求都重新生成(实测 1515 次调用就是这么来的)。
for (const ext of ['.webp', '.jpg', '.png']) {
try { if (await fs().exists(base + ext)) { const mime = ext === '.webp' ? 'image/webp' : (ext === '.png' ? 'image/png' : 'image/jpeg'); return { path: base + ext, mime: mime } } } catch (e) { /* ignore */ }
}
return null
}
@@ -1275,12 +1277,30 @@
function decodeStats () { return { active: dec.active, peak: dec.peak, total: dec.total, big: dec.big, queued: 0 } }
// 按**绝对路径**生成 tier(相册的 {__file} 引用走这条)
async function makeDisplayThumbFromPath (hash, absPath, max) {
// v3.26.135:同一 (hash,max) 的生成**去重**。预热与宫格会同时要同一张,
// 原来两边各跑一次 img_thumbs、同时写同一个文件 ⇒ 另一方可能读到写了一半的 jpg。
const thumbInflight = new Map()
function makeDisplayThumbFromPath (hash, absPath, max) {
const m = Math.max(64, Number(max) || 768)
const key = String(hash) + '_' + m
const hit = thumbInflight.get(key)
if (hit) return hit
const p = makeDisplayThumbFromPathInner(hash, absPath, m).finally(() => { thumbInflight.delete(key) })
thumbInflight.set(key, p)
return p
}
async function makeDisplayThumbFromPathInner (hash, absPath, max) {
try {
if (!enabled() || !dir || !hash || !absPath) return null
const m = Math.max(64, Number(max) || 768)
const m = max
const have = await thumbFileOf(hash, m)
if (have) return { url: await readDisplayThumbUrl(hash, m), path: have.path, cached: true }
if (have) {
// 0 字节 = 上次并发写坏的截断文件:删掉重做,别把坏图缓存成 objectURL
let size = 0
try { const st = await fs().stat(have.path); size = (st && st.size) || 0 } catch (e) { size = 0 }
if (size > 0) return { url: await readDisplayThumbUrl(hash, m), path: have.path, cached: true }
try { await fs().remove(have.path) } catch (e) { /* ignore */ }
}
const base = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_' + m)
try { await fs().mkdir(await join(dir, IMG_DIR, 'thumbs'), { recursive: true }) } catch (e) { /* ignore */ }
const T = (typeof window !== 'undefined') ? window.__TAURI__ : null