Merge branch 'plugins-dev-experience' of github.com:Budibase/budibase into plugins-dev-experience
This commit is contained in:
commit
5a0e6aee25
|
@ -24,6 +24,7 @@ import { buildSelfEndpoints } from "./self"
|
||||||
import { buildViewEndpoints } from "./views"
|
import { buildViewEndpoints } from "./views"
|
||||||
import { buildLicensingEndpoints } from "./licensing"
|
import { buildLicensingEndpoints } from "./licensing"
|
||||||
import { buildGroupsEndpoints } from "./groups"
|
import { buildGroupsEndpoints } from "./groups"
|
||||||
|
import { buildPluginEndpoints } from "./plugins"
|
||||||
|
|
||||||
const defaultAPIClientConfig = {
|
const defaultAPIClientConfig = {
|
||||||
/**
|
/**
|
||||||
|
@ -243,5 +244,6 @@ export const createAPIClient = config => {
|
||||||
...buildSelfEndpoints(API),
|
...buildSelfEndpoints(API),
|
||||||
...buildLicensingEndpoints(API),
|
...buildLicensingEndpoints(API),
|
||||||
...buildGroupsEndpoints(API),
|
...buildGroupsEndpoints(API),
|
||||||
|
...buildPluginEndpoints(API),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
export const buildPluginEndpoints = API => ({
|
||||||
|
/**
|
||||||
|
* Uploads a plugin tarball bundle
|
||||||
|
* @param data the plugin tarball bundle to upload
|
||||||
|
*/
|
||||||
|
uploadPlugin: async data => {
|
||||||
|
return await API.post({
|
||||||
|
url: "/api/plugin/upload",
|
||||||
|
body: data,
|
||||||
|
json: false,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
|
@ -11,6 +11,7 @@ export async function upload(ctx: any) {
|
||||||
: [ctx.request.files.file]
|
: [ctx.request.files.file]
|
||||||
const db = getGlobalDB()
|
const db = getGlobalDB()
|
||||||
try {
|
try {
|
||||||
|
let docs = []
|
||||||
// can do single or multiple plugins
|
// can do single or multiple plugins
|
||||||
for (let plugin of plugins) {
|
for (let plugin of plugins) {
|
||||||
const { metadata, directory } = await extractPluginTarball(plugin)
|
const { metadata, directory } = await extractPluginTarball(plugin)
|
||||||
|
@ -42,15 +43,24 @@ export async function upload(ctx: any) {
|
||||||
`Plugin already exists: name: ${name}, version: ${version}`
|
`Plugin already exists: name: ${name}, version: ${version}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
await db.put({
|
const doc = {
|
||||||
_id: pluginId,
|
_id: pluginId,
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
description,
|
description,
|
||||||
...metadata,
|
...metadata,
|
||||||
jsUrl: `${bucketPath}${jsFileName}`,
|
jsUrl: `${bucketPath}${jsFileName}`,
|
||||||
|
}
|
||||||
|
const response = await db.put(doc)
|
||||||
|
docs.push({
|
||||||
|
...doc,
|
||||||
|
_rev: response.rev,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
ctx.body = {
|
||||||
|
message: "Plugin(s) uploaded successfully",
|
||||||
|
plugins: docs,
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const errMsg = err?.message ? err?.message : err
|
const errMsg = err?.message ? err?.message : err
|
||||||
ctx.throw(400, `Failed to import plugin: ${errMsg}`)
|
ctx.throw(400, `Failed to import plugin: ${errMsg}`)
|
||||||
|
|
Loading…
Reference in New Issue