perf(image): 图库清单去 base64(367KB→1.6KB,按 thumbHash 读文件)+ 画布显示缩略图 768px 落盘
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m36s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m36s
This commit is contained in:
1 parent
e9a6402373
commit
3bbf1ea85d
3 files changed
+140
-5
No files matched your search
@@ -4,6 +4,8 @@
|
||||
function createHydrator(options) {
|
||||
const opt = options || {}
|
||||
const get = typeof opt.get === 'function' ? opt.get : (() => Promise.resolve(null))
|
||||
// 文件存储:清单只留 thumbHash,缩略图按需从 images/thumbs/ 读
|
||||
const thumb = typeof opt.thumb === 'function' ? opt.thumb : null
|
||||
let sequence = 0
|
||||
let disposed = false
|
||||
async function hydrate(items, requestId) {
|
||||
@@ -11,7 +13,12 @@
|
||||
if (id > sequence) sequence = id
|
||||
const list = Array.isArray(items) ? items : []
|
||||
const values = await Promise.all(list.map(async (item) => {
|
||||
if (!item || !item.idb) return item
|
||||
if (!item) return item
|
||||
if (item.data) return item
|
||||
if (thumb && item.thumbHash) {
|
||||
try { const v = await thumb(item.thumbHash); if (v) return Object.assign({}, item, { data: v }) } catch (e) { /* 读文件失败退回 idb */ }
|
||||
}
|
||||
if (!item.idb) return item
|
||||
try {
|
||||
const value = await get(item.idb)
|
||||
return value == null ? item : Object.assign({}, item, { data: value })
|
||||
|
||||
Reference in new issue
Block a user