smoother downloads, lint
This commit is contained in:
parent
91ee1b313e
commit
d0f389a5cb
|
@ -74,6 +74,7 @@
|
||||||
"codemirror": "^5.59.0",
|
"codemirror": "^5.59.0",
|
||||||
"d3-selection": "^1.4.1",
|
"d3-selection": "^1.4.1",
|
||||||
"deepmerge": "^4.2.2",
|
"deepmerge": "^4.2.2",
|
||||||
|
"downloadjs": "^1.4.7",
|
||||||
"fast-sort": "^2.2.0",
|
"fast-sort": "^2.2.0",
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
"posthog-js": "1.4.5",
|
"posthog-js": "1.4.5",
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import Spinner from "components/common/Spinner.svelte"
|
import Spinner from "components/common/Spinner.svelte"
|
||||||
|
import download from "downloadjs"
|
||||||
|
|
||||||
export let name, _id
|
export let name, _id
|
||||||
|
|
||||||
|
@ -13,10 +14,8 @@
|
||||||
async function exportApp() {
|
async function exportApp() {
|
||||||
appExportLoading = true
|
appExportLoading = true
|
||||||
try {
|
try {
|
||||||
const response = await api.post(`/api/backups/export`, { appId: _id })
|
download(`/api/backups/export?appId=${_id}`)
|
||||||
const { url } = await response.json()
|
|
||||||
notifier.success("App Export Complete.")
|
notifier.success("App Export Complete.")
|
||||||
window.location = url
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifier.danger("App Export Failed.")
|
notifier.danger("App Export Failed.")
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -30,13 +29,13 @@
|
||||||
<Spacer medium />
|
<Spacer medium />
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<TextButton text medium blue href="/_builder/{_id}">
|
<TextButton text medium blue href="/_builder/{_id}">
|
||||||
Open {name} →
|
Open
|
||||||
|
{name}
|
||||||
|
→
|
||||||
</TextButton>
|
</TextButton>
|
||||||
{#if appExportLoading}
|
{#if appExportLoading}
|
||||||
<Spinner size="10" />
|
<Spinner size="10" />
|
||||||
{:else}
|
{:else}<i class="ri-folder-download-line" on:click={exportApp} />{/if}
|
||||||
<i class="ri-folder-download-line" on:click={exportApp} />
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,7 @@ const os = require("os")
|
||||||
const fs = require("fs-extra")
|
const fs = require("fs-extra")
|
||||||
|
|
||||||
exports.exportAppDump = async function(ctx) {
|
exports.exportAppDump = async function(ctx) {
|
||||||
const { appId } = ctx.request.body
|
const { appId } = ctx.query
|
||||||
|
|
||||||
const backupsDir = path.join(os.homedir(), ".budibase", "backups")
|
const backupsDir = path.join(os.homedir(), ".budibase", "backups")
|
||||||
fs.ensureDirSync(backupsDir)
|
fs.ensureDirSync(backupsDir)
|
||||||
|
@ -18,19 +18,24 @@ exports.exportAppDump = async function(ctx) {
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = {
|
|
||||||
url: `/api/backups/download/${backupIdentifier}`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.downloadAppDump = async function(ctx) {
|
const backupFile = path.join(backupsDir, backupIdentifier)
|
||||||
const fileName = ctx.params.fileName
|
|
||||||
|
|
||||||
const backupsDir = path.join(os.homedir(), ".budibase", "backups")
|
ctx.attachment(backupIdentifier)
|
||||||
fs.ensureDirSync(backupsDir)
|
|
||||||
|
|
||||||
const backupFile = path.join(backupsDir, fileName)
|
|
||||||
|
|
||||||
ctx.attachment(fileName)
|
|
||||||
ctx.body = fs.createReadStream(backupFile)
|
ctx.body = fs.createReadStream(backupFile)
|
||||||
|
// ctx.body = {
|
||||||
|
// url: `/api/backups/download/${backupIdentifier}`,
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exports.downloadAppDump = async function(ctx) {
|
||||||
|
// const fileName = ctx.params.fileName
|
||||||
|
|
||||||
|
// const backupsDir = path.join(os.homedir(), ".budibase", "backups")
|
||||||
|
// fs.ensureDirSync(backupsDir)
|
||||||
|
|
||||||
|
// const backupFile = path.join(backupsDir, fileName)
|
||||||
|
|
||||||
|
// ctx.attachment(fileName)
|
||||||
|
// ctx.body = fs.createReadStream(backupFile)
|
||||||
|
// }
|
||||||
|
|
|
@ -83,7 +83,7 @@ const controller = {
|
||||||
ctx.message = `View ${ctx.params.viewName} saved successfully.`
|
ctx.message = `View ${ctx.params.viewName} saved successfully.`
|
||||||
},
|
},
|
||||||
exportView: async ctx => {
|
exportView: async ctx => {
|
||||||
const view = ctx.request.body
|
const view = ctx.query.view
|
||||||
const format = ctx.query.format
|
const format = ctx.query.format
|
||||||
|
|
||||||
// Fetch view rows
|
// Fetch view rows
|
||||||
|
@ -102,14 +102,6 @@ const controller = {
|
||||||
const filename = `${view.name}.${format}`
|
const filename = `${view.name}.${format}`
|
||||||
fs.writeFileSync(join(os.tmpdir(), filename), exportedFile)
|
fs.writeFileSync(join(os.tmpdir(), filename), exportedFile)
|
||||||
|
|
||||||
ctx.body = {
|
|
||||||
url: `/api/views/export/download/${filename}`,
|
|
||||||
name: view.name,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
downloadExport: async ctx => {
|
|
||||||
const filename = ctx.params.fileName
|
|
||||||
|
|
||||||
ctx.attachment(filename)
|
ctx.attachment(filename)
|
||||||
ctx.body = fs.createReadStream(join(os.tmpdir(), filename))
|
ctx.body = fs.createReadStream(join(os.tmpdir(), filename))
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,12 +5,11 @@ const { BUILDER } = require("../../utilities/security/permissions")
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router.get("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
|
||||||
.post("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
|
// .get(
|
||||||
.get(
|
// "/api/backups/download/:fileName",
|
||||||
"/api/backups/download/:fileName",
|
// authorized(BUILDER),
|
||||||
authorized(BUILDER),
|
// controller.downloadAppDump
|
||||||
controller.downloadAppDump
|
// )
|
||||||
)
|
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -26,10 +26,5 @@ router
|
||||||
)
|
)
|
||||||
.post("/api/views", authorized(BUILDER), usage, viewController.save)
|
.post("/api/views", authorized(BUILDER), usage, viewController.save)
|
||||||
.post("/api/views/export", authorized(BUILDER), viewController.exportView)
|
.post("/api/views/export", authorized(BUILDER), viewController.exportView)
|
||||||
.get(
|
|
||||||
"/api/views/export/download/:fileName",
|
|
||||||
authorized(BUILDER),
|
|
||||||
viewController.downloadExport
|
|
||||||
)
|
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
|
@ -10,7 +10,6 @@ const streamPipeline = promisify(stream.pipeline)
|
||||||
const { budibaseAppsDir } = require("./budibaseDir")
|
const { budibaseAppsDir } = require("./budibaseDir")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
const CouchDB = require("../db")
|
const CouchDB = require("../db")
|
||||||
const { DocumentTypes } = require("../db/utils")
|
|
||||||
|
|
||||||
const DEFAULT_TEMPLATES_BUCKET =
|
const DEFAULT_TEMPLATES_BUCKET =
|
||||||
"prod-budi-templates.s3-eu-west-1.amazonaws.com"
|
"prod-budi-templates.s3-eu-west-1.amazonaws.com"
|
||||||
|
|
Loading…
Reference in New Issue