1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Change the download to be a post

This commit is contained in:
Adria Navarro 2023-06-14 10:47:46 +01:00
parent 2ba8adc4e8
commit bfd444dbaa
2 changed files with 50 additions and 4 deletions

View file

@ -1,5 +1,11 @@
<script>
import { ModalContent, Toggle, Body, InlineAlert } from "@budibase/bbui"
import {
ModalContent,
Toggle,
Body,
InlineAlert,
notifications,
} from "@budibase/bbui"
export let app
export let published
@ -8,10 +14,50 @@
$: title = published ? "Export published app" : "Export latest app"
$: confirmText = published ? "Export published" : "Export latest"
const exportApp = () => {
const exportApp = async () => {
const id = published ? app.prodId : app.devId
const appName = encodeURIComponent(app.name)
window.location = `/api/backups/export?appId=${id}&appname=${appName}&excludeRows=${excludeRows}`
const url = `/api/backups/export?appId=${id}&appname=${appName}&excludeRows=${excludeRows}`
await downloadFile(url)
}
export async function downloadFile(url, body) {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
})
if (response.ok) {
const contentDisposition = response.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const filename = matches[1].replace(/['"]/g, "")
const url = URL.createObjectURL(await response.blob())
const link = document.createElement("a")
link.href = url
link.download = filename
link.click()
URL.revokeObjectURL(url)
} else {
notifications.error("Error exporting the app.")
}
} catch (error) {
let message = "Error downloading the exported app"
if (error.message) {
message += `: ${error.message}`
}
notifications.error("Error downloading the exported app", message)
}
}
</script>

View file

@ -5,7 +5,7 @@ import { permissions } from "@budibase/backend-core"
const router: Router = new Router()
router.get(
router.post(
"/api/backups/export",
authorized(permissions.BUILDER),
controller.exportAppDump