fix(plugins): gallery 1.6.9 缩略图缓存共享(重排不重复取图)+ 顶栏更浅
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 43s

This commit is contained in:
qiqi committed 2026-11-21 23:48:14 +08:00
1 parent 2082ced720
commit 96e8cc2d7d
11 files changed
+36 -14

No files matched your search

+17 -3
View File
@@ -80,6 +80,8 @@
var cfg = Object.assign({}, DEF)
var items = []
var thumbCache = {}
var thumbPending = {} // 进行中的缩略图请求(v1.6.9)
var total = 0
var limit = 100
var picked = {}
@@ -348,7 +350,20 @@
holder.style.cursor = ''
holder.onclick = null
holder.textContent = '加载中…'
Promise.resolve(ctx.gallery.thumb(it.name)).then(function (url) {
// v1.6.9:缩略图地址按名字缓存,且进行中的请求共享同一 Promise ——
// 重排/重测会重建 DOM,不共享就会对同一张图重复取 N 次。
var key = it.name
if (thumbCache[key]) { var u0 = thumbCache[key]; setTimeout(function () { paint(u0) }, 0); return }
if (!thumbPending[key]) {
thumbPending[key] = Promise.resolve(ctx.gallery.thumb(key)).then(function (url) {
if (url && typeof url === 'string') thumbCache[key] = url
delete thumbPending[key]
return url
}, function (e) { delete thumbPending[key]; throw e })
}
thumbPending[key].then(paint).catch(function () { fail('缩略图加载失败(点击重试)') })
}
function paint (url) {
if (!url || typeof url !== 'string') { fail('图片已丢失'); return }
if (!box.isConnected) return
var img = el('img', { src: url, alt: '', loading: 'lazy', draggable: 'true' })
@@ -385,7 +400,6 @@
// 加载成功后再替换占位(避免破图标 + 长 title 占满格子)
if (img.complete && img.naturalWidth > 0) { img.style.display = ''; if (holder.parentNode === box) box.replaceChild(img, holder) }
else if (img.complete && !img.naturalWidth) { /* 立即失败(坏图)*/ tries++; if (tries <= 2) setTimeout(boot, 400 * tries); else { if (img.parentNode === box) box.replaceChild(holder, img); fail('缩略图加载失败(点击重试)') } }
}).catch(function () { fail('缩略图加载失败(点击重试)') })
}
boot()
box.addEventListener('contextmenu', function (e) { openMenu(e, it) })
@@ -513,7 +527,7 @@
global.IWBPluginHost.register({
id: 'gallery',
name: '图库',
version: '1.6.7',
version: '1.6.9',
apiVersion: 1,
capabilities: ['panels', 'gallery'],
data: { schemaVersion: 1, maxBytes: 65536 },
+2 -2
View File
@@ -1,7 +1,7 @@
{
"id": "gallery",
"name": "图库",
"version": "1.6.7",
"version": "1.6.9",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"图库"
],
"files": {
"main.js": "691fb701ef8f8055bc6a7c3bc40e9606c7948f0350c995ee1aa07745c5d48f5c",
"main.js": "fd3ca4d42dcc9c74d311d9177606ff25fc7e38c1d6b40de4a0435edd30a08a6f",
"styles.css": "9d5b4ab1343761e51ef0c479cab96a94d3d6eaa27f0fdb500bff789ec81d70e0"
}
}
+2 -2
View File
@@ -22,9 +22,9 @@
"dir": "gallery",
"main": "main.js",
"style": "styles.css",
"version": "1.6.7",
"version": "1.6.9",
"files": {
"main.js": "691fb701ef8f8055bc6a7c3bc40e9606c7948f0350c995ee1aa07745c5d48f5c",
"main.js": "fd3ca4d42dcc9c74d311d9177606ff25fc7e38c1d6b40de4a0435edd30a08a6f",
"styles.css": "9d5b4ab1343761e51ef0c479cab96a94d3d6eaa27f0fdb500bff789ec81d70e0"
}
},