diff --git a/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte b/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte
index 3520c18991..ade5f14c9f 100644
--- a/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte
+++ b/packages/builder/src/pages/builder/portal/manage/plugins/_components/AddPluginModal.svelte
@@ -2,49 +2,39 @@
import { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui"
import { plugins } from "stores/portal"
+ const Sources = {
+ NPM: "NPM",
+ GITHUB: "Github",
+ URL: "URL",
+ FILE: "File Upload",
+ }
+
let authOptions = {
- URL: ["Headers", "URL"],
- NPM: ["URL"],
- Github: ["Github Token", "URL"],
- "File Upload": ["File Upload"],
+ [Sources.NPM]: ["URL"],
+ [Sources.GITHUB]: ["Github Token", "URL"],
+ [Sources.URL]: ["Headers", "URL"],
+ [Sources.FILE]: ["File Upload"],
}
let file
- let sourceValue = "URL"
+ let source = Sources.URL
let typeValue = "Component"
let dynamicValues = {}
let validation
- $: validation = sourceValue === "File Upload" ? file : dynamicValues["URL"]
+ $: validation = source === "File Upload" ? file : dynamicValues["URL"]
async function save() {
- const source = sourceValue.toLocaleLowerCase()
- const url = dynamicValues["URL"]
-
- switch (source) {
- case "file upload":
- if (file) {
- await plugins.uploadPlugin(file, sourceValue)
- }
- break
- case "github":
- await plugins.createPlugin(
- typeValue,
- source,
- url,
- dynamicValues["Github Token"]
- )
- break
- case "url":
- await plugins.createPlugin(
- typeValue,
- source,
- url,
- dynamicValues["Headers"]
- )
- break
- case "npm":
- await plugins.createPlugin(typeValue, source, url)
- break
+ if (source === Sources.FILE) {
+ await plugins.uploadPlugin(file)
+ } else {
+ const url = dynamicValues["URL"]
+ let auth =
+ source === Sources.GITHUB
+ ? dynamicValues["Github Token"]
+ : source === Sources.URL
+ ? dynamicValues["Headers"]
+ : undefined
+ await plugins.createPlugin(typeValue, source, url, auth)
}
}
@@ -68,12 +58,12 @@
- {#each authOptions[sourceValue] as option}
+ {#each authOptions[source] as option}
{#if option === "File Upload"}
diff --git a/packages/builder/src/stores/portal/plugins.js b/packages/builder/src/stores/portal/plugins.js
index 28f9bfc42d..981daeb715 100644
--- a/packages/builder/src/stores/portal/plugins.js
+++ b/packages/builder/src/stores/portal/plugins.js
@@ -50,10 +50,12 @@ export function createPluginsStore() {
})
}
- async function uploadPlugin(file, source) {
+ async function uploadPlugin(file) {
+ if (!file) {
+ return
+ }
let data = new FormData()
data.append("file", file)
- data.append("source", source)
let resp = await API.uploadPlugin(data)
let newPlugin = resp.plugins[0]
update(state => {
diff --git a/packages/server/src/api/controllers/plugin/index.ts b/packages/server/src/api/controllers/plugin/index.ts
index de4aa2a50a..5c0cd6c197 100644
--- a/packages/server/src/api/controllers/plugin/index.ts
+++ b/packages/server/src/api/controllers/plugin/index.ts
@@ -13,7 +13,7 @@ import {
uploadDirectory,
deleteFolder,
} from "@budibase/backend-core/objectStore"
-import { PluginType, FileType } from "@budibase/types"
+import { PluginType, FileType, PluginSource } from "@budibase/types"
import env from "../../../environment"
export async function getPlugins(type?: PluginType) {
@@ -40,7 +40,7 @@ export async function upload(ctx: any) {
let docs = []
// can do single or multiple plugins
for (let plugin of plugins) {
- const doc = await processPlugin(plugin, ctx.request.body.source)
+ const doc = await processPlugin(plugin, PluginSource.FILE)
docs.push(doc)
}
ctx.body = {
@@ -68,19 +68,19 @@ export async function create(ctx: any) {
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
switch (source) {
- case "npm":
+ case PluginSource.NPM:
const { metadata: metadataNpm, directory: directoryNpm } =
await uploadedNpmPlugin(url, name)
metadata = metadataNpm
directory = directoryNpm
break
- case "github":
+ case PluginSource.GITHUB:
const { metadata: metadataGithub, directory: directoryGithub } =
await uploadedGithubPlugin(ctx, url, name, githubToken)
metadata = metadataGithub
directory = directoryGithub
break
- case "url":
+ case PluginSource.URL:
const headersObj = JSON.parse(headers || null) || {}
const { metadata: metadataUrl, directory: directoryUrl } =
await uploadedUrlPlugin(url, name, headersObj)
diff --git a/packages/types/src/documents/plugin/index.ts b/packages/types/src/documents/plugin/index.ts
index f696d7a2aa..7fbfececd6 100644
--- a/packages/types/src/documents/plugin/index.ts
+++ b/packages/types/src/documents/plugin/index.ts
@@ -3,9 +3,15 @@ export enum PluginType {
COMPONENT = "component",
}
+export enum PluginSource {
+ NPM = "NPM",
+ GITHUB = "Github",
+ URL = "URL",
+ FILE = "File Upload",
+}
export interface FileType {
path: string
name: string
}
-export const PLUGIN_TYPE_ARR = Object.values(exports.PluginType)
+export const PLUGIN_TYPE_ARR = Object.values(PluginType)