perf(images): 缩略图入库预热 + 稳定 key + Blob/objectURL + 按需切原图(v3.25.73)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 25s

This commit is contained in:
qiqi committed 2026-11-21 06:53:32 +08:00
1 parent b37a1ffe78
commit 94680fd127
19 files changed
+278 -57

No files matched your search

+30 -1
View File
@@ -907,6 +907,35 @@
return bytesToDataUrl('image/jpeg', u8)
} catch (e) { return '' }
}
// v3.25.73:缩略图以 Blob + objectURL 交给显示层(避免 dataURL 常驻 JS 堆)
const thumbUrlCache = new Map() // hash → objectURL
async function readDisplayThumbUrl(hash) {
try {
if (!enabled() || !dir || !hash) return ''
const hit = thumbUrlCache.get(String(hash))
if (hit) return hit
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768.jpg')
if (!(await fs().exists(abs))) return ''
const u8 = await fs().readFile(abs)
if (!u8 || !u8.length) return ''
const url = URL.createObjectURL(new Blob([u8], { type: 'image/jpeg' }))
thumbUrlCache.set(String(hash), url)
if (thumbUrlCache.size > 400) { const k = thumbUrlCache.keys().next().value; try { URL.revokeObjectURL(thumbUrlCache.get(k)) } catch (e) {} ; thumbUrlCache.delete(k) }
return url
} catch (e) { return '' }
}
async function writeDisplayThumbBlob(hash, blob) {
try {
if (!enabled() || !dir || !hash || !blob) return false
const abs = await join(dir, IMG_DIR, 'thumbs', String(hash) + '_768.jpg')
if (await fs().exists(abs)) return true
await fs().mkdir(await join(dir, IMG_DIR, 'thumbs'), { recursive: true })
const buf = new Uint8Array(await blob.arrayBuffer())
await fs().writeFile(abs, buf)
return true
} catch (e) { return false }
}
async function writeDisplayThumb(hash, dataUrl) {
try {
if (!enabled() || !dir || !hash || !dataUrl) return false
@@ -1005,7 +1034,7 @@
}
global.IWBStorageFile = {
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, writeDisplayThumb,
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages, rotateTrash, galleryThumb, readDisplayThumb, readDisplayThumbUrl, writeDisplayThumb, writeDisplayThumbBlob,
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir },
pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList },
storage: () => storage,