plugins: customApiCall will support calls with any number of parameters

Massimo Melina committed Sep 26, 2023 at 23:49 UTC b18befeb4be3fde0b11c04ddb8e2cce1fd12caf7
4 files changed +6 -6
admin/src/OnlinePlugins.ts
+1 -1
@@ -84,7 +84,7 @@ export default function OnlinePlugins() {
84 catch(e: any) {
85 if (e.code !== 424) throw e
86 const msg = h(Fragment, {}, "This plugin has some dependencies unmet:",
87 - e.data.map((x: any) => h('li', {}, x.repo + ': ' + x.error)) )
87 + e.data.map((x: any) => h('li', { key: x.repo }, x.repo + ': ' + x.error)) )
88 return alertDialog(msg, 'error')
89 }
90 }
dev-plugins.md
+2 -1
@@ -181,7 +181,7 @@ The `api` object you get as parameter of the `init` contains the following:
181 If you need something for your plugin that's not covered by `api`, you can test it with this method, but you should
182 then discuss it on the forum because an addition to `api` is your best option for making a future-proof plugin.
183
184 -- `customApiCall: (method: string, params?: object) => any[]` this will invoke other plugins if they define `method`
184 +- `customApiCall: (method: string, ...params) => any[]` this will invoke other plugins if they define `method`
185 exported inside `customApi: object`
186
187 ## Front-end specific
@@ -366,6 +366,7 @@ Where `h` is just `import { createElement as h } from 'react'`.
366 - 8.5 (v0.49.0)
367 - new event: entry
368 - exports.onDirEntry: entry.icon
369 + - customApiCall supports any number of parameters
370 - 8.4 (v0.48.2)
371 - HFS.fileShow
372 - api.Const (api.const is now deprecated)
src/api.plugins.ts
+1 -2
@@ -180,8 +180,7 @@ function serialize(p: Readonly<Plugin> | AvailablePlugin) {
180
181 async function checkDependencies(repo: Repo, branch?: string) {
182 const rec = await readOnlinePlugin(repo, branch)
183 - if (!rec) return
184 - const miss = rec.depend && rec.depend.map((dep: any) => {
183 + const miss = rec?.depend?.map((dep: any) => {
184 const res = findPluginByRepo(dep.repo)
185 const error = !res ? 'missing'
186 : (res.version || 0) < dep.version ? 'version'
src/plugins.ts
+2 -2
@@ -405,8 +405,8 @@ function watchPlugin(id: string, path: string) {
405 }
406 }
407
408 -function customApiCall(method: string, params?: any) {
409 - return mapPlugins(pl => pl.getData().customApi?.[method]?.(params))
408 +function customApiCall(method: string, ...params: any[]) {
409 + return mapPlugins(pl => pl.getData().customApi?.[method]?.(...params))
410 }
411
412 function getError(id: string) {