feat(plugins): P1 插件外置(<资料目录>/plugins 覆盖内置、sha256 校验、blob 注入、来源标签);CSP 放行 blob:
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m11s

This commit is contained in:
qiqi committed 2026-11-17 11:29:47 +08:00
1 parent 2626c663c3
commit 5da4f255d8
5 files changed
+106 -10

No files matched your search

+26
View File
@@ -395,6 +395,31 @@
} catch (e) { return 0 }
}
// ---- 插件外置(P1):<资料目录>/plugins/ 覆盖随包的内置插件 ----
const PLUG_DIR = 'plugins'
async function pluginManifest() {
try {
const txt = await fs().readTextFile(await join(dir, PLUG_DIR, 'index.json'))
const j = JSON.parse(txt)
return Array.isArray(j) ? j : (Array.isArray(j && j.plugins) ? j.plugins : [])
} catch (e) { return [] }
}
async function pluginRead(file) {
const safe = String(file || '')
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
return fs().readTextFile(await join(dir, PLUG_DIR, safe))
}
async function pluginRemove(file) {
const safe = String(file || '')
if (!/^[A-Za-z0-9._-]+$/.test(safe)) throw new Error('非法插件文件名')
try { await fs().remove(await join(dir, PLUG_DIR, safe)); return true } catch (e) { return false }
}
async function pluginDir() {
const p = await join(dir, PLUG_DIR)
try { await fs().mkdir(p, { recursive: true }) } catch (e) { /* 已存在 */ }
return p
}
async function loadInto() {
// data.json 不存在 ⇒ 把当前 WebView 里的数据迁过去(只做一次)
const target = await join(dir, DATA_FILE)
@@ -653,6 +678,7 @@
global.IWBStorageFile = {
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages,
plugins: { manifest: pluginManifest, read: pluginRead, remove: pluginRemove, dir: pluginDir },
storage: () => storage,
kv: () => kv,
dir: () => dir,
+11 -1
View File
@@ -25,12 +25,22 @@
if (!pluginItems.length && !remoteIdle.length && !remoteFailed.length) return el('div', { className: 'iwb-hint' }, '暂无已注册插件。插件随应用一起发布,启用后其面板 / 命令 / 节点类型才会出现。')
return el('div', { className: 'iwb-set-page' },
el('div', { className: 'iwb-set-page-title' }, '插件管理'),
isDesk() && (() => {
const F = (typeof window !== 'undefined') ? window.IWBStorageFile : null
const extCount = (wRuntimePlugins || []).filter((r) => r && r.source === 'external').length
const dirHint = (F && F.dir && F.dir()) ? (F.dir() + '/plugins/') : '资料目录/plugins/'
return el('div', { className: 'iwb-hint' },
'外部插件:' + dirHint + '(放 index.json + 插件 js 即可覆盖内置;' + (extCount ? '当前 ' + extCount + ' 个来自外部' : '当前全部来自内置') + ')。',
)
})(),
el('div', { className: 'iwb-hint' }, (isDesk()
? '插件随应用一起发布(离线可用),升级插件需要更新应用版本。停用只隐藏其入口:既有的插件节点仍照常渲染、运行与保存。'
? '插件随应用发布(离线可用);外部插件放在资料目录 plugins/ 下可独立维护,不动本体。停用只隐藏其入口:既有的插件节点仍照常渲染、运行与保存。'
: '内置插件随应用发布;带「远程」标签的插件来自同源 /plugins/index.json(KV 提供),更新只需上传到 KV、刷新即生效。停用只隐藏其入口:既有的插件节点仍照常渲染、运行与保存。')),
pluginItems.map((p) => {
return el('div', { key: p.id, className: 'iwb-plugin-row' },
el('label', { className: 'iwb-label iwb-grow' },
el('span', { className: 'iwb-hint', style: { marginRight: 6 } },
((wRuntimePlugins || []).find((r) => r && r.id === p.id && r.source === 'external') ? '外部' : '内置')),
el('input', {
type: 'checkbox', checked: p.enabled, disabled: !p.compatible,
onChange: (e) => { const r = PluginHost.setEnabled(p.id, e.target.checked); setPluginsRev((v) => v + 1); if (!r.ok) setMsg({ type: 'err', text: p.name + ':' + r.error }) },