cleaning minio folder when deleting plugin

This commit is contained in:
NEOLPAR 2022-09-05 10:13:55 +01:00
parent 0314f65977
commit 79d2ea0c60
1 changed files with 19 additions and 3 deletions

View File

@ -4,11 +4,14 @@ import {
createNpmPlugin, createNpmPlugin,
createUrlPlugin, createUrlPlugin,
createGithubPlugin, createGithubPlugin,
loadJSFile loadJSFile,
} from "../../utilities/fileSystem" } from "../../utilities/fileSystem"
import { getGlobalDB } from "@budibase/backend-core/tenancy" import { getGlobalDB } from "@budibase/backend-core/tenancy"
import { generatePluginID, getPluginParams } from "../../db/utils" import { generatePluginID, getPluginParams } from "../../db/utils"
import { uploadDirectory } from "@budibase/backend-core/objectStore" import {
uploadDirectory,
deleteFolder,
} from "@budibase/backend-core/objectStore"
import { PluginType, FileType } from "@budibase/types" import { PluginType, FileType } from "@budibase/types"
import env from "../../environment" import env from "../../environment"
@ -98,7 +101,20 @@ export async function fetch(ctx: any) {
export async function destroy(ctx: any) { export async function destroy(ctx: any) {
const db = getGlobalDB() const db = getGlobalDB()
await db.remove(ctx.params.pluginId, ctx.params.pluginRev) const { pluginId, pluginRev } = ctx.params
try {
const plugin = await db.get(pluginId)
const bucketPath = `${plugin.name}/`
await deleteFolder(ObjectStoreBuckets.PLUGINS, bucketPath)
await db.remove(pluginId, pluginRev)
} catch (err: any) {
const errMsg = err?.message ? err?.message : err
ctx.throw(400, `Failed to delete plugin: ${errMsg}`)
}
ctx.message = `Plugin ${ctx.params.pluginId} deleted.` ctx.message = `Plugin ${ctx.params.pluginId} deleted.`
ctx.status = 200 ctx.status = 200
} }