Refactoring some plugin adding work - changing how source is specified to remove lower casing.
This commit is contained in:
parent
3d739d3b26
commit
f6e5524b07
|
@ -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()
|
||||
if (source === Sources.FILE) {
|
||||
await plugins.uploadPlugin(file)
|
||||
} else {
|
||||
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
|
||||
let auth =
|
||||
source === Sources.GITHUB
|
||||
? dynamicValues["Github Token"]
|
||||
: source === Sources.URL
|
||||
? dynamicValues["Headers"]
|
||||
: undefined
|
||||
await plugins.createPlugin(typeValue, source, url, auth)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -68,12 +58,12 @@
|
|||
<Label size="M">Source</Label>
|
||||
<Select
|
||||
placeholder={null}
|
||||
bind:value={sourceValue}
|
||||
options={["NPM", "Github", "URL", "File Upload"]}
|
||||
bind:value={source}
|
||||
options={Object.values(Sources)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#each authOptions[sourceValue] as option}
|
||||
{#each authOptions[source] as option}
|
||||
{#if option === "File Upload"}
|
||||
<div class="form-row">
|
||||
<Label size="M">{option}</Label>
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue