feat(images): 插件侧图片策略 v2 —— 全部改走宿主小图(album/promptlib/batch-export/annotate/vectorize/white-bg/cutout)
validate / validate (push) Canceled after 0s
validate / validate (push) Canceled after 0s
This commit is contained in:
1 parent
70613a4112
commit
9ceaa7d699
15 files changed
+53
-24
No files matched your search
+19
-7
@@ -607,13 +607,25 @@
|
||||
// dataURL → { img: 文件名 };失败原样返回(宁可留着内联 base64,也不丢封面)
|
||||
function ensureCoverFile (cover) {
|
||||
if (!FILEAPI || typeof cover !== 'string' || cover.indexOf('data:') !== 0) return Promise.resolve(cover)
|
||||
var name = coverFileName(cover)
|
||||
pendingCoverNames[name] = 1
|
||||
return Promise.resolve(FILEAPI.put(name, cover)).then(function (r) {
|
||||
if (r && r.ok) return { img: name }
|
||||
delete pendingCoverNames[name]
|
||||
return cover
|
||||
}).catch(function () { delete pendingCoverNames[name]; return cover })
|
||||
// v: 封面入库前先在**原生侧**缩到 512 —— 大封面会永久占 plugin-data,
|
||||
// 而且每次显示都要整幅解码(WebKit 上 4K 封面 = 21MB/次)。
|
||||
var prepped = Promise.resolve(cover)
|
||||
try {
|
||||
if (PLP_CTX && PLP_CTX.images && typeof PLP_CTX.images.preview === 'function') {
|
||||
prepped = Promise.resolve(PLP_CTX.images.preview(cover, { max: 512 }))
|
||||
.then(function (r) { return (r && r.ok && r.dataUrl) ? r.dataUrl : cover })
|
||||
.catch(function () { return cover })
|
||||
}
|
||||
} catch (e) { /* 退回未压缩 */ }
|
||||
return prepped.then(function (small) {
|
||||
var name = coverFileName(small)
|
||||
pendingCoverNames[name] = 1
|
||||
return Promise.resolve(FILEAPI.put(name, small)).then(function (r) {
|
||||
if (r && r.ok) return { img: name }
|
||||
delete pendingCoverNames[name]
|
||||
return small
|
||||
}).catch(function () { delete pendingCoverNames[name]; return small })
|
||||
})
|
||||
}
|
||||
// 回收未被任何词条引用的封面文件(判定在模块级 plpGcCoverFiles,设置页复用同一套)。
|
||||
// 返回 { removed, bytes, skipped }
|
||||
|
||||
Reference in new issue
Block a user