1
0
Fork 0
mirror of synced 2024-06-14 08:24:48 +12:00
budibase/packages/builder/src/components/start/ExportAppModal.svelte

105 lines
2.9 KiB
Svelte
Raw Normal View History

2022-05-25 20:26:10 +12:00
<script>
2023-06-14 21:47:46 +12:00
import {
ModalContent,
keepOpen,
2023-06-14 21:47:46 +12:00
Toggle,
Body,
InlineAlert,
2023-06-13 22:21:54 +12:00
Input,
2023-06-14 21:47:46 +12:00
notifications,
} from "@budibase/bbui"
2024-03-22 23:34:05 +13:00
import { downloadFile } from "@budibase/frontend-core"
2023-06-13 22:57:56 +12:00
import { createValidationStore } from "helpers/validation/yup"
2022-05-25 20:26:10 +12:00
export let app
export let published
2023-06-13 21:00:01 +12:00
let includeInternalTablesRows = true
let encrypt = true
2022-05-25 20:26:10 +12:00
2023-06-13 23:42:30 +12:00
let password = null
2023-06-13 22:57:56 +12:00
const validation = createValidationStore()
validation.addValidatorType("password", "password", true, { minLength: 8 })
2023-06-13 23:42:30 +12:00
$: validation.observe("password", password)
2022-05-25 20:26:10 +12:00
2023-06-13 22:15:32 +12:00
const Step = { CONFIG: "config", SET_PASSWORD: "set_password" }
2023-06-13 23:45:57 +12:00
let currentStep = Step.CONFIG
2023-06-13 22:15:32 +12:00
$: exportButtonText = published ? "Export published" : "Export latest"
$: stepConfig = {
[Step.CONFIG]: {
title: published ? "Export published app" : "Export latest app",
confirmText: encrypt ? "Continue" : exportButtonText,
2023-06-13 22:15:32 +12:00
onConfirm: () => {
if (!encrypt) {
2023-06-13 22:15:32 +12:00
exportApp()
} else {
currentStep = Step.SET_PASSWORD
return keepOpen
2023-06-13 22:15:32 +12:00
}
},
2023-06-13 23:42:30 +12:00
isValid: true,
2023-06-13 22:15:32 +12:00
},
[Step.SET_PASSWORD]: {
title: "Add password to encrypt your export",
confirmText: exportButtonText,
2023-06-13 22:57:56 +12:00
onConfirm: async () => {
2023-06-13 23:42:30 +12:00
await validation.check({ password })
2023-06-13 22:57:56 +12:00
if (!$validation.valid) {
return keepOpen
2023-06-13 22:21:54 +12:00
}
2023-12-06 05:10:01 +13:00
await exportApp(password)
2023-06-13 22:15:32 +12:00
},
2023-06-13 23:42:30 +12:00
isValid: $validation.valid,
2023-06-13 22:15:32 +12:00
},
}
2023-06-14 21:47:46 +12:00
const exportApp = async () => {
const id = published ? app.prodId : app.devId
const url = `/api/backups/export?appId=${id}`
2023-06-14 21:47:46 +12:00
try {
const downloaded = await downloadFile(url, {
2024-03-22 23:34:05 +13:00
excludeRows: !includeInternalTablesRows,
encryptPassword: password,
2023-06-14 21:47:46 +12:00
})
if (!downloaded) {
notifications.error("Error exporting the app.")
}
2023-06-14 21:47:46 +12:00
} catch (error) {
2023-06-15 00:48:37 +12:00
notifications.error(error.message || "Error downloading the exported app")
2023-06-14 21:47:46 +12:00
}
2022-05-25 20:26:10 +12:00
}
</script>
2023-06-13 22:15:32 +12:00
<ModalContent
title={stepConfig[currentStep].title}
confirmText={stepConfig[currentStep].confirmText}
onConfirm={stepConfig[currentStep].onConfirm}
2023-06-13 23:42:30 +12:00
disabled={!stepConfig[currentStep].isValid}
2023-06-13 22:15:32 +12:00
>
2023-06-13 22:21:54 +12:00
{#if currentStep === Step.CONFIG}
2023-06-13 22:57:56 +12:00
<Body>
<Toggle
text="Export rows from internal tables"
bind:value={includeInternalTablesRows}
/>
<Toggle text="Encrypt my export" bind:value={encrypt} />
2023-06-13 22:57:56 +12:00
</Body>
<InlineAlert
header={encrypt
2023-12-07 05:41:44 +13:00
? "Please note Budibase does not encrypt attachments during the export process to ensure efficient export of large attachments."
: "Do not share your Budibase application exports publicly as they may contain sensitive information such as database credentials or secret keys."}
/>
2023-06-13 22:21:54 +12:00
{/if}
{#if currentStep === Step.SET_PASSWORD}
<Input
2023-06-13 22:57:56 +12:00
type="password"
2023-06-13 22:21:54 +12:00
label="Password"
autocomplete="new-password"
2023-06-13 22:21:54 +12:00
placeholder="Type here..."
bind:value={password}
2023-06-13 22:57:56 +12:00
error={$validation.errors.password}
2023-06-13 21:00:01 +12:00
/>
{/if}
2022-05-25 20:26:10 +12:00
</ModalContent>