1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00

Add plugin upload to core API client, add response to plugin upload endpoint

This commit is contained in:
Andrew Kingston 2022-08-11 10:37:57 +01:00
parent b7116ccc18
commit f2ee01d58f
3 changed files with 26 additions and 1 deletions

View file

@ -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),
} }
} }

View file

@ -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,
})
},
})

View file

@ -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}`)