|
| 1 | +<script lang="ts"> |
| 2 | + import { IO, getCloudProviderAliases, hasFolderPicker, isValidFileUpload, type IOProvider } from '$lib/duui/io.js' |
| 3 | + import { equals } from '$lib/duui/utils/text' |
| 4 | + import { isEmpty } from 'lodash' |
| 5 | +
|
| 6 | + import Checkbox from '$lib/svelte/components/Input/Checkbox.svelte' |
| 7 | + import Dropdown from '$lib/svelte/components/Input/Dropdown.svelte' |
| 8 | + import TextInput from '$lib/svelte/components/Input/TextInput.svelte' |
| 9 | +
|
| 10 | + import LocalDirectoryPanel from '$lib/process-io/LocalDirectoryPanel.svelte' |
| 11 | + import RemoteDirectoryPanel from '$lib/process-io/RemoteDirectoryPanel.svelte' |
| 12 | +
|
| 13 | + export let userOid: string |
| 14 | + export let connections: Record<string, Record<string, unknown>> |
| 15 | +
|
| 16 | + let fileStorage: { |
| 17 | + storeFiles: boolean |
| 18 | + provider: IOProvider |
| 19 | + provider_id: string |
| 20 | + path: string |
| 21 | + } = { storeFiles: false, provider: IO.LocalDrive, provider_id: '', path: '' } |
| 22 | +
|
| 23 | + const hasConnections = (providerLower: string) => Object.keys(connections?.[providerLower] ?? {}).length > 0 |
| 24 | +
|
| 25 | + $: isValidFileStorage = !fileStorage.storeFiles || isValidFileUpload(fileStorage as any) |
| 26 | + $: isFileUploadError = |
| 27 | + fileStorage.storeFiles && |
| 28 | + (!equals(fileStorage.provider, IO.LocalDrive) && !hasConnections(fileStorage.provider.toLowerCase())) && |
| 29 | + (equals(fileStorage.provider, IO.LocalDrive) && false) |
| 30 | +
|
| 31 | + $: isFileUploadRequirementsMet = |
| 32 | + (!equals(fileStorage.provider, IO.LocalDrive) && !isEmpty(fileStorage.provider_id)) || |
| 33 | + (equals(fileStorage.provider, IO.LocalDrive) && true) |
| 34 | +
|
| 35 | + export const getFileStorage = () => fileStorage |
| 36 | + export const getIsValidFileStorage = () => isValidFileStorage |
| 37 | +</script> |
| 38 | + |
| 39 | +<Checkbox label="Upload input files to cloud storage." bind:checked={fileStorage.storeFiles} /> |
| 40 | + |
| 41 | +{#if fileStorage.storeFiles} |
| 42 | + <div |
| 43 | + class="grid gap-4" |
| 44 | + class:grid-cols-1={!hasConnections(fileStorage.provider.toLowerCase())} |
| 45 | + class:grid-cols-2={hasConnections(fileStorage.provider.toLowerCase())} |
| 46 | + > |
| 47 | + <Dropdown |
| 48 | + label="Provider" |
| 49 | + options={[IO.LocalDrive, IO.Dropbox, IO.Minio, IO.NextCloud, IO.Google]} |
| 50 | + bind:value={fileStorage.provider} |
| 51 | + on:change={() => { |
| 52 | + fileStorage.provider_id = '' |
| 53 | + }} |
| 54 | + /> |
| 55 | + {#if !isFileUploadError && hasConnections(fileStorage.provider.toLowerCase())} |
| 56 | + <Dropdown |
| 57 | + label="Connection Alias" |
| 58 | + options={getCloudProviderAliases(connections?.[fileStorage.provider.toLowerCase()] ?? {})} |
| 59 | + initFirst={true} |
| 60 | + bind:value={fileStorage.provider_id} |
| 61 | + /> |
| 62 | + {/if} |
| 63 | + </div> |
| 64 | + |
| 65 | + {#if !isFileUploadError && isFileUploadRequirementsMet} |
| 66 | + {#if equals(fileStorage.provider, IO.Minio)} |
| 67 | + <TextInput |
| 68 | + label="Path (bucket/path/to/folder)" |
| 69 | + name="fileStoragePath" |
| 70 | + bind:value={fileStorage.path} |
| 71 | + /> |
| 72 | + {:else if equals(fileStorage.provider, IO.LocalDrive)} |
| 73 | + <LocalDirectoryPanel name="fileLFSUploadPaths" isMultiple={false} bind:value={fileStorage.path} /> |
| 74 | + {:else if hasFolderPicker(fileStorage.provider, true)} |
| 75 | + <RemoteDirectoryPanel |
| 76 | + provider={fileStorage.provider} |
| 77 | + providerId={fileStorage.provider_id} |
| 78 | + {userOid} |
| 79 | + {connections} |
| 80 | + name="fileUploadPaths" |
| 81 | + isMultiple={false} |
| 82 | + bind:selectedPaths={fileStorage.path} |
| 83 | + /> |
| 84 | + {:else} |
| 85 | + <TextInput label="Path" name="fileStoragePath" bind:value={fileStorage.path} /> |
| 86 | + {/if} |
| 87 | + {/if} |
| 88 | +{/if} |
0 commit comments