release: v3.26.102 相册外部路径重启复授权

This commit is contained in:
qiqi committed 2026-11-26 08:41:55 +08:00
1 parent bac3c32e1c
commit d604bb39b8
13 files changed
+91 -9

No files matched your search

+23 -1
View File
@@ -130,6 +130,28 @@
return { ok: true, path: p, name: nameOf(p), size: st.size, mtime: st.mtime }
}
const API = Object.freeze({ is, available, mimeOf, nameOf, isImagePath, listImages, readBytes, readDataUrl, readBlob, stat, grant, pick, reference })
// 启动时把画布里已有的 {__file} 路径重新授权一次(并让 Rust 持久化)。
// 旧版只 grant 不持久化 ⇒ 重启后文件读取被 fs scope 拒绝:相册缩略图有缓存还能显示,
// 组合/参考图要读原图就只剩感叹号。只授权 .isImagePath() 的路径,不扩大面。
async function grantKnown (workspaces) {
if (!available()) return 0
const paths = new Set()
const walk = (v, d) => {
if (v == null || d > 6) return
if (Array.isArray(v)) { for (const x of v) walk(x, d + 1); return }
if (typeof v !== 'object') return
if (is(v)) { paths.add(String(v.__file)); return }
for (const k of Object.keys(v)) { if (k === 'result') continue; walk(v[k], d + 1) }
}
for (const w of (Array.isArray(workspaces) ? workspaces : [])) {
for (const n of ((w && w.nodes) || [])) walk(n && n.data, 0)
}
const list = Array.from(paths).filter(isImagePath).slice(0, 1000)
if (!list.length) return 0
await grant(list)
return list.length
}
const API = Object.freeze({ is, available, mimeOf, nameOf, isImagePath, listImages, readBytes, readDataUrl, readBlob, stat, grant, grantKnown, pick, reference })
global.IWBImageFileRef = API
})(typeof window !== 'undefined' ? window : globalThis)