2022-10-07 07:10:45 +13:00
|
|
|
import sdk from "../../sdk"
|
|
|
|
import { events, context } from "@budibase/backend-core"
|
|
|
|
import { DocumentType } from "../../db/utils"
|
|
|
|
import { isQsTrue } from "../../utilities"
|
2021-01-28 02:55:46 +13:00
|
|
|
|
2022-10-07 07:10:45 +13:00
|
|
|
export async function exportAppDump(ctx: any) {
|
2022-06-07 02:17:14 +12:00
|
|
|
let { appId, excludeRows } = ctx.query
|
2021-10-19 00:08:12 +13:00
|
|
|
const appName = decodeURI(ctx.query.appname)
|
2022-09-10 07:06:29 +12:00
|
|
|
excludeRows = isQsTrue(excludeRows)
|
2021-10-19 00:08:12 +13:00
|
|
|
const backupIdentifier = `${appName}-export-${new Date().getTime()}.txt`
|
2021-01-30 10:52:45 +13:00
|
|
|
ctx.attachment(backupIdentifier)
|
2022-10-07 07:10:45 +13:00
|
|
|
ctx.body = await sdk.apps.exports.streamBackup(appId, excludeRows)
|
2022-05-26 21:13:26 +12:00
|
|
|
|
|
|
|
await context.doInAppContext(appId, async () => {
|
|
|
|
const appDb = context.getAppDB()
|
2022-08-12 00:50:05 +12:00
|
|
|
const app = await appDb.get(DocumentType.APP_METADATA)
|
2022-05-26 21:13:26 +12:00
|
|
|
await events.app.exported(app)
|
|
|
|
})
|
2021-01-28 02:55:46 +13:00
|
|
|
}
|