feat(plugins): P3 开发者模式(plugins/local/<id>/plugin.js 免签名加载)+ SDK 文档与示例插件
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m22s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m22s
This commit is contained in:
1 parent
1008370733
commit
49b8cb3abd
7 files changed
+225
-7
No files matched your search
+18
-1
@@ -421,6 +421,23 @@
|
||||
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 }
|
||||
}
|
||||
// 开发者模式:<资料目录>/plugins/local/<id>/plugin.js(未签名,只在开关打开时加载)
|
||||
async function pluginListLocal() {
|
||||
try {
|
||||
const ldir = await join(dir, PLUG_DIR, 'local')
|
||||
const entries = await fs().readDir(ldir)
|
||||
const out = []
|
||||
for (const e of entries) {
|
||||
if (!e || !e.isDirectory) continue
|
||||
try {
|
||||
const code = await fs().readTextFile(await join(ldir, e.name, 'plugin.js'))
|
||||
out.push({ id: e.name, file: 'local/' + e.name + '/plugin.js', code: code })
|
||||
} catch (err) { /* 该目录没有 plugin.js,跳过 */ }
|
||||
}
|
||||
return out
|
||||
} catch (e) { return [] }
|
||||
}
|
||||
|
||||
async function pluginDir() {
|
||||
const p = await join(dir, PLUG_DIR)
|
||||
try { await fs().mkdir(p, { recursive: true }) } catch (e) { /* 已存在 */ }
|
||||
@@ -685,7 +702,7 @@
|
||||
|
||||
global.IWBStorageFile = {
|
||||
enabled, ready: init, flush, runtime, pickDir, switchTo, migrateTo, gcImages,
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir },
|
||||
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal },
|
||||
storage: () => storage,
|
||||
kv: () => kv,
|
||||
dir: () => dir,
|
||||
|
||||
Reference in new issue
Block a user