feat(backup): v3.26.59 备份带上插件文件(提示词封面不再换机丢失)
P0(宿主): - 备份 ZIP 新增 plugin-files/<插件id>/<文件名> 通道,恢复时写回沙箱; 此前只备份 JSON ⇒ 换机后「提示词都在、封面全是灰块」,而状态行写着「已恢复」 - IWBStorageFile.pluginFiles 增 readBytes / listAll(不 mkdir、只读字节) - IWBPluginData 增 listFiles / readFile / restoreFiles:清单一次给出、字节逐条读写 (插件文件单插件上限 64MB,攒数组会 OOM) - 校验和口径统一:images / imagesData / pluginFiles / pluginFilesData 全部排除; JSON 兜底导出按自身内容重算 checksum,避免「换个打包形态就报校验不一致」 - 备份二次确认的体积/张数把插件文件计入;恢复摘要显示「含 N 个插件文件(封面等)」 - tests/plugin-data-test:新增插件文件清单/读字节/写回 三条行为断言 P1(插件 promptlib 1.11.0,随包同步): - 封面保存/上传即落成文件(JSON 只留文件名)、孤儿封面可回收 (启动后一次 + 删词条后一次 + 设置页手动入口;空集合/非插件数据来源一律不删) - 四处内联 djb2 哈希合并为 coverFileName,同图不再存两份 - 样式散值归零(4px→6px、margin 13px→12px),插件尺度棘轮基线保持 0
This commit is contained in:
1 parent
054db215cd
commit
e966b348b9
14 files changed
+387
-83
No files matched your search
@@ -230,12 +230,61 @@
|
||||
return { bytes: n, count: all.length }
|
||||
}
|
||||
|
||||
// ---- 插件文件(plugin-data/<id>/files/,v3.26.59)----
|
||||
// 为什么放在这层:备份/还原只认 IWBPluginData 一个入口。此前只备份 JSON,
|
||||
// 于是「提示词封面」这类图片文件换机后全丢(标题栏说"已恢复",打开却是灰块)。
|
||||
// 内存纪律:清单(id/name/size)一次性给出;字节**逐条读**(调用方写完即放手),
|
||||
// 不做"全部读进数组再写包"——插件文件单插件上限 64MB,攒起来会 OOM。
|
||||
function pluginFilesFacade () {
|
||||
const F = global.IWBStorageFile
|
||||
const pf = F && F.pluginFiles
|
||||
return (pf && typeof pf.listAll === 'function') ? pf : null
|
||||
}
|
||||
async function listFiles () {
|
||||
const pf = pluginFilesFacade()
|
||||
if (!pf) return []
|
||||
let groups = []
|
||||
try { groups = await pf.listAll() } catch (e) { groups = [] }
|
||||
const out = []
|
||||
for (const g of (Array.isArray(groups) ? groups : [])) {
|
||||
if (!g || !g.id) continue
|
||||
for (const f of (g.files || [])) {
|
||||
if (!f || !f.name) continue
|
||||
out.push({ id: String(g.id), name: String(f.name), size: Number(f.size) || 0 })
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
async function readFile (id, name) {
|
||||
const pf = pluginFilesFacade()
|
||||
if (!pf || typeof pf.readBytes !== 'function') return null
|
||||
try { return await pf.readBytes(String(id), String(name)) } catch (e) { return null }
|
||||
}
|
||||
// list = [{ id, name, data: dataURL }],单条失败不影响其它
|
||||
async function restoreFiles (list) {
|
||||
const F = global.IWBStorageFile
|
||||
const pf = F && F.pluginFiles
|
||||
if (!pf || typeof pf.put !== 'function') return 0
|
||||
let n = 0
|
||||
for (const it of (Array.isArray(list) ? list : [])) {
|
||||
if (!it || !it.id || !it.name || !it.data) continue
|
||||
try {
|
||||
const r = await pf.put(String(it.id), String(it.name), String(it.data))
|
||||
if (r && r.ok) n++
|
||||
} catch (e) { /* 单个失败不影响其它 */ }
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
global.IWBPluginData = {
|
||||
create: create,
|
||||
stripLegacy: stripLegacy,
|
||||
collectAll: collectAll,
|
||||
restoreAll: restoreAll,
|
||||
totalSize: totalSize,
|
||||
listFiles: listFiles,
|
||||
readFile: readFile,
|
||||
restoreFiles: restoreFiles,
|
||||
_bytesOf: bytesOf,
|
||||
}
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
Reference in new issue
Block a user