Allow downloading attachment
This commit is contained in:
parent
12f9b47954
commit
7e7f31b967
|
@ -3,7 +3,6 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
import { FieldType } from "@budibase/types"
|
import { FieldType } from "@budibase/types"
|
||||||
import { processStringSync } from "@budibase/string-templates"
|
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
export let bindings = []
|
export let bindings = []
|
||||||
|
@ -12,8 +11,6 @@
|
||||||
b => b.fieldSchema?.type === FieldType.ATTACHMENT
|
b => b.fieldSchema?.type === FieldType.ATTACHMENT
|
||||||
)
|
)
|
||||||
|
|
||||||
let selectedAttachment
|
|
||||||
|
|
||||||
const fileOptions = [
|
const fileOptions = [
|
||||||
{
|
{
|
||||||
label: "Attachment",
|
label: "Attachment",
|
||||||
|
@ -25,14 +22,6 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const onAttachmentSelect = e => {
|
|
||||||
const fileData = processStringSync(e.detail, bindings)
|
|
||||||
parameters.value ??= {}
|
|
||||||
parameters.value.file_name = e.detail.name
|
|
||||||
parameters.value.url = e.detail.url
|
|
||||||
console.log({ parameters, bindings, fileData })
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!parameters.type) {
|
if (!parameters.type) {
|
||||||
parameters.type = "attachment"
|
parameters.type = "attachment"
|
||||||
|
@ -46,9 +35,6 @@
|
||||||
placeholder={null}
|
placeholder={null}
|
||||||
bind:value={parameters.type}
|
bind:value={parameters.type}
|
||||||
options={fileOptions}
|
options={fileOptions}
|
||||||
on:change={() => {
|
|
||||||
delete parameters.value
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
{#if parameters.type === "attachment"}
|
{#if parameters.type === "attachment"}
|
||||||
<Label small>Attachment</Label>
|
<Label small>Attachment</Label>
|
||||||
|
@ -56,25 +42,23 @@
|
||||||
title="Attachment"
|
title="Attachment"
|
||||||
bindings={fileBindings}
|
bindings={fileBindings}
|
||||||
allowHelpers={false}
|
allowHelpers={false}
|
||||||
bind:value={selectedAttachment}
|
value={parameters.attachment}
|
||||||
on:change={onAttachmentSelect}
|
on:change={value => (parameters.attachment = value.detail)}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<Label small>URL</Label>
|
<Label small>URL</Label>
|
||||||
<DrawerBindableInput
|
<DrawerBindableInput
|
||||||
title="URL"
|
title="URL"
|
||||||
{bindings}
|
{bindings}
|
||||||
value={parameters.value?.url}
|
value={parameters.url}
|
||||||
on:change={e =>
|
on:change={value => (parameters.url = value.detail)}
|
||||||
(parameters.value = { ...parameters.value, url: e.detail })}
|
|
||||||
/>
|
/>
|
||||||
<Label small>File name</Label>
|
<Label small>File name</Label>
|
||||||
<DrawerBindableInput
|
<DrawerBindableInput
|
||||||
title="File name"
|
title="File name"
|
||||||
{bindings}
|
{bindings}
|
||||||
value={parameters.value?.file_name}
|
value={parameters.file_name}
|
||||||
on:change={e =>
|
on:change={value => (parameters.file_name = value.detail)}
|
||||||
(parameters.value = { ...parameters.value, file_name: e.detail })}
|
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -401,7 +401,12 @@ const closeSidePanelHandler = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadFileHandler = async (action, context) => {
|
const downloadFileHandler = async (action, context) => {
|
||||||
const { url, file_name } = action.parameters.value
|
let { url, file_name, type, attachment } = action.parameters
|
||||||
|
if (type === "attachment") {
|
||||||
|
const attachmentObject = JSON.parse(attachment)
|
||||||
|
url = attachmentObject.url
|
||||||
|
file_name = attachmentObject.name
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue