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 { ModalContent, Label, Input, Select, Dropzone } from "@budibase/bbui"
|
||||||
import { plugins } from "stores/portal"
|
import { plugins } from "stores/portal"
|
||||||
|
|
||||||
|
const Sources = {
|
||||||
|
NPM: "NPM",
|
||||||
|
GITHUB: "Github",
|
||||||
|
URL: "URL",
|
||||||
|
FILE: "File Upload",
|
||||||
|
}
|
||||||
|
|
||||||
let authOptions = {
|
let authOptions = {
|
||||||
URL: ["Headers", "URL"],
|
[Sources.NPM]: ["URL"],
|
||||||
NPM: ["URL"],
|
[Sources.GITHUB]: ["Github Token", "URL"],
|
||||||
Github: ["Github Token", "URL"],
|
[Sources.URL]: ["Headers", "URL"],
|
||||||
"File Upload": ["File Upload"],
|
[Sources.FILE]: ["File Upload"],
|
||||||
}
|
}
|
||||||
let file
|
let file
|
||||||
let sourceValue = "URL"
|
let source = Sources.URL
|
||||||
let typeValue = "Component"
|
let typeValue = "Component"
|
||||||
let dynamicValues = {}
|
let dynamicValues = {}
|
||||||
|
|
||||||
let validation
|
let validation
|
||||||
$: validation = sourceValue === "File Upload" ? file : dynamicValues["URL"]
|
$: validation = source === "File Upload" ? file : dynamicValues["URL"]
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
const source = sourceValue.toLocaleLowerCase()
|
if (source === Sources.FILE) {
|
||||||
|
await plugins.uploadPlugin(file)
|
||||||
|
} else {
|
||||||
const url = dynamicValues["URL"]
|
const url = dynamicValues["URL"]
|
||||||
|
let auth =
|
||||||
switch (source) {
|
source === Sources.GITHUB
|
||||||
case "file upload":
|
? dynamicValues["Github Token"]
|
||||||
if (file) {
|
: source === Sources.URL
|
||||||
await plugins.uploadPlugin(file, sourceValue)
|
? dynamicValues["Headers"]
|
||||||
}
|
: undefined
|
||||||
break
|
await plugins.createPlugin(typeValue, source, url, auth)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -68,12 +58,12 @@
|
||||||
<Label size="M">Source</Label>
|
<Label size="M">Source</Label>
|
||||||
<Select
|
<Select
|
||||||
placeholder={null}
|
placeholder={null}
|
||||||
bind:value={sourceValue}
|
bind:value={source}
|
||||||
options={["NPM", "Github", "URL", "File Upload"]}
|
options={Object.values(Sources)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#each authOptions[sourceValue] as option}
|
{#each authOptions[source] as option}
|
||||||
{#if option === "File Upload"}
|
{#if option === "File Upload"}
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<Label size="M">{option}</Label>
|
<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()
|
let data = new FormData()
|
||||||
data.append("file", file)
|
data.append("file", file)
|
||||||
data.append("source", source)
|
|
||||||
let resp = await API.uploadPlugin(data)
|
let resp = await API.uploadPlugin(data)
|
||||||
let newPlugin = resp.plugins[0]
|
let newPlugin = resp.plugins[0]
|
||||||
update(state => {
|
update(state => {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
uploadDirectory,
|
uploadDirectory,
|
||||||
deleteFolder,
|
deleteFolder,
|
||||||
} from "@budibase/backend-core/objectStore"
|
} from "@budibase/backend-core/objectStore"
|
||||||
import { PluginType, FileType } from "@budibase/types"
|
import { PluginType, FileType, PluginSource } from "@budibase/types"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
|
|
||||||
export async function getPlugins(type?: PluginType) {
|
export async function getPlugins(type?: PluginType) {
|
||||||
|
@ -40,7 +40,7 @@ export async function upload(ctx: any) {
|
||||||
let docs = []
|
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 doc = await processPlugin(plugin, ctx.request.body.source)
|
const doc = await processPlugin(plugin, PluginSource.FILE)
|
||||||
docs.push(doc)
|
docs.push(doc)
|
||||||
}
|
}
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
@ -68,19 +68,19 @@ export async function create(ctx: any) {
|
||||||
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
|
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
|
||||||
|
|
||||||
switch (source) {
|
switch (source) {
|
||||||
case "npm":
|
case PluginSource.NPM:
|
||||||
const { metadata: metadataNpm, directory: directoryNpm } =
|
const { metadata: metadataNpm, directory: directoryNpm } =
|
||||||
await uploadedNpmPlugin(url, name)
|
await uploadedNpmPlugin(url, name)
|
||||||
metadata = metadataNpm
|
metadata = metadataNpm
|
||||||
directory = directoryNpm
|
directory = directoryNpm
|
||||||
break
|
break
|
||||||
case "github":
|
case PluginSource.GITHUB:
|
||||||
const { metadata: metadataGithub, directory: directoryGithub } =
|
const { metadata: metadataGithub, directory: directoryGithub } =
|
||||||
await uploadedGithubPlugin(ctx, url, name, githubToken)
|
await uploadedGithubPlugin(ctx, url, name, githubToken)
|
||||||
metadata = metadataGithub
|
metadata = metadataGithub
|
||||||
directory = directoryGithub
|
directory = directoryGithub
|
||||||
break
|
break
|
||||||
case "url":
|
case PluginSource.URL:
|
||||||
const headersObj = JSON.parse(headers || null) || {}
|
const headersObj = JSON.parse(headers || null) || {}
|
||||||
const { metadata: metadataUrl, directory: directoryUrl } =
|
const { metadata: metadataUrl, directory: directoryUrl } =
|
||||||
await uploadedUrlPlugin(url, name, headersObj)
|
await uploadedUrlPlugin(url, name, headersObj)
|
||||||
|
|
|
@ -3,9 +3,15 @@ export enum PluginType {
|
||||||
COMPONENT = "component",
|
COMPONENT = "component",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum PluginSource {
|
||||||
|
NPM = "NPM",
|
||||||
|
GITHUB = "Github",
|
||||||
|
URL = "URL",
|
||||||
|
FILE = "File Upload",
|
||||||
|
}
|
||||||
export interface FileType {
|
export interface FileType {
|
||||||
path: string
|
path: string
|
||||||
name: 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