2022-05-25 20:26:10 +12:00
< script >
2023-06-13 22:21:54 +12:00
import {
ModalContent,
Toggle,
Body,
InlineAlert,
Input,
} from "@budibase/bbui"
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
2022-09-10 07:06:29 +12:00
export let published
2023-06-13 21:00:01 +12:00
let includeInternalTablesRows = true
let encypt = true
2023-06-13 22:57:56 +12:00
2023-06-13 23:42:30 +12:00
let password = null
2023-06-13 22:57:56 +12:00
const validation = createValidationStore()
2023-06-14 01:28:31 +12:00
validation.addValidatorType("password", "password", true)
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: encypt ? "Continue" : exportButtonText,
onConfirm: () => {
if (!encypt) {
exportApp()
} else {
currentStep = Step.SET_PASSWORD
return false
}
},
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) {
2023-06-13 22:21:54 +12:00
return false
}
2023-06-13 23:45:57 +12:00
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
},
}
2022-09-10 07:06:29 +12:00
2023-06-13 23:45:57 +12:00
const exportApp = password => {
2022-09-10 07:06:29 +12:00
const id = published ? app.prodId : app.devId
2022-05-25 20:26:10 +12:00
const appName = encodeURIComponent(app.name)
2023-06-13 23:45:57 +12:00
let url = `/api/backups/export?appId=${ id } & appname=${ appName } & excludeRows=${ ! includeInternalTablesRows } `
if (password) {
url += `& encryptPassword=${ password } `
}
window.location = url
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 = { encypt } / >
< / Body >
{ #if ! encypt }
< InlineAlert
header="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 }
{ #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"
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 >