Allow delete attachments from builder data section

This commit is contained in:
Mel O'Hagan 2022-08-15 15:46:55 +01:00
parent df620fb9f7
commit 1f66cf9a83
5 changed files with 34 additions and 3 deletions

View File

@ -95,9 +95,11 @@
"change",
value.filter((x, idx) => idx !== selectedImageIdx)
)
if (deleteAttachments) {
await deleteAttachments(
value.filter((x, idx) => idx === selectedImageIdx).map(item => item.key)
)
}
selectedImageIdx = 0
}

View File

@ -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}

View File

@ -27,6 +27,14 @@
return []
}
}
async function deleteAttachments(fileList) {
try {
return await API.deleteBuilderAttachments(fileList)
} catch (error) {
return []
}
}
</script>
<Dropzone
@ -34,5 +42,6 @@
{label}
{...$$restProps}
{processFiles}
{deleteAttachments}
{handleFileTooLarge}
/>

View File

@ -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,
},
})
},
}
}

View File

@ -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",