From 1f66cf9a83453643ac38bab9e2c9bd82b7e42613 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Mon, 15 Aug 2022 15:46:55 +0100 Subject: [PATCH] Allow delete attachments from builder data section --- packages/bbui/src/Form/Core/Dropzone.svelte | 8 +++++--- packages/bbui/src/Form/Dropzone.svelte | 2 ++ .../builder/src/components/common/Dropzone.svelte | 9 +++++++++ packages/frontend-core/src/api/attachments.js | 13 +++++++++++++ packages/server/src/api/routes/static.ts | 5 +++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/bbui/src/Form/Core/Dropzone.svelte b/packages/bbui/src/Form/Core/Dropzone.svelte index 68882fe810..ffdac08402 100644 --- a/packages/bbui/src/Form/Core/Dropzone.svelte +++ b/packages/bbui/src/Form/Core/Dropzone.svelte @@ -95,9 +95,11 @@ "change", value.filter((x, idx) => idx !== selectedImageIdx) ) - await deleteAttachments( - value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key) - ) + if (deleteAttachments) { + await deleteAttachments( + value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key) + ) + } selectedImageIdx = 0 } diff --git a/packages/bbui/src/Form/Dropzone.svelte b/packages/bbui/src/Form/Dropzone.svelte index f1b548f7f1..5b82c0ebea 100644 --- a/packages/bbui/src/Form/Dropzone.svelte +++ b/packages/bbui/src/Form/Dropzone.svelte @@ -10,6 +10,7 @@ export let error = null export let fileSizeLimit = undefined export let processFiles = undefined + export let deleteAttachments = undefined export let handleFileTooLarge = undefined export let handleTooManyFiles = undefined export let gallery = true @@ -30,6 +31,7 @@ {value} {fileSizeLimit} {processFiles} + {deleteAttachments} {handleFileTooLarge} {handleTooManyFiles} {gallery} diff --git a/packages/builder/src/components/common/Dropzone.svelte b/packages/builder/src/components/common/Dropzone.svelte index 9a86554b49..fd2359fd91 100644 --- a/packages/builder/src/components/common/Dropzone.svelte +++ b/packages/builder/src/components/common/Dropzone.svelte @@ -27,6 +27,14 @@ return [] } } + + async function deleteAttachments(fileList) { + try { + return await API.deleteBuilderAttachments(fileList) + } catch (error) { + return [] + } + } diff --git a/packages/frontend-core/src/api/attachments.js b/packages/frontend-core/src/api/attachments.js index 1a24785a89..f79b461574 100644 --- a/packages/frontend-core/src/api/attachments.js +++ b/packages/frontend-core/src/api/attachments.js @@ -75,5 +75,18 @@ export const buildAttachmentEndpoints = API => { }, }) }, + + /** + * Deletes attachments from the builder bucket. + * @param keys the attachments to delete + */ + deleteBuilderAttachments: async keys => { + return await API.post({ + url: `/api/attachments/delete`, + body: { + keys, + }, + }) + }, } } diff --git a/packages/server/src/api/routes/static.ts b/packages/server/src/api/routes/static.ts index 7cf3f5e145..c94ff54708 100644 --- a/packages/server/src/api/routes/static.ts +++ b/packages/server/src/api/routes/static.ts @@ -38,6 +38,11 @@ router // TODO: for now this builder endpoint is not authorized/secured, will need to be .get("/builder/:file*", controller.serveBuilder) .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile) + .post( + "/api/attachments/delete", + authorized(BUILDER), + controller.deleteObjects + ) .post("/api/beta/:feature", controller.toggleBetaUiFeature) .post( "/api/attachments/:tableId/upload",