Add validation to plugins uploaded using file upload and allow component uploads via non-file sources in cloud

This commit is contained in:
Andrew Kingston 2022-09-14 11:58:59 +01:00
parent a866874b4b
commit 64ee1677e6
1 changed files with 8 additions and 4 deletions

View File

@ -53,10 +53,6 @@ export async function upload(ctx: any) {
export async function create(ctx: any) {
const { source, url, headers, githubToken } = ctx.request.body
if (!env.SELF_HOSTED) {
ctx.throw(400, "Plugins not supported outside of self-host.")
}
try {
let metadata
let directory
@ -87,6 +83,13 @@ export async function create(ctx: any) {
validate(metadata?.schema)
// Only allow components in cloud
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {
throw new Error(
"Only component plugins are supported outside of self-host"
)
}
const doc = await storePlugin(metadata, directory, source)
ctx.body = {
@ -198,6 +201,7 @@ export async function storePlugin(
export async function processPlugin(plugin: FileType, source?: string) {
const { metadata, directory } = await fileUpload(plugin)
validate(metadata?.schema)
// Only allow components in cloud
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {