commit
075f1d1e3d
|
@ -7,9 +7,10 @@ const apiCall = method => async (
|
||||||
headers = { "Content-Type": "application/json" }
|
headers = { "Content-Type": "application/json" }
|
||||||
) => {
|
) => {
|
||||||
headers["x-budibase-app-id"] = svelteGet(store).appId
|
headers["x-budibase-app-id"] = svelteGet(store).appId
|
||||||
|
const json = headers["Content-Type"] === "application/json"
|
||||||
return await fetch(url, {
|
return await fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
body: body && JSON.stringify(body),
|
body: json ? JSON.stringify(body) : body,
|
||||||
headers,
|
headers,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processFiles(fileList) {
|
async function processFiles(fileList) {
|
||||||
const fileArray = Array.from(fileList)
|
let data = new FormData()
|
||||||
|
for (let i = 0; i < fileList.length; i++) {
|
||||||
const filesToProcess = fileArray.map(({ name, path, size, type }) => ({
|
data.append("file", fileList[i])
|
||||||
name,
|
}
|
||||||
path,
|
const response = await api.post(`/api/attachments/process`, data, {})
|
||||||
size,
|
|
||||||
type,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const response = await api.post(`/api/attachments/process`, {
|
|
||||||
files: filesToProcess,
|
|
||||||
})
|
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -123,13 +123,19 @@
|
||||||
async function createNewApp() {
|
async function createNewApp() {
|
||||||
submitting = true
|
submitting = true
|
||||||
try {
|
try {
|
||||||
// Create App
|
// Create form data to create app
|
||||||
const appResp = await post("/api/applications", {
|
let data = new FormData()
|
||||||
name: $createAppStore.values.applicationName,
|
data.append("name", $createAppStore.values.applicationName)
|
||||||
template,
|
data.append("useTemplate", template != null)
|
||||||
})
|
if (template) {
|
||||||
const appJson = await appResp.json()
|
data.append("templateName", template.name)
|
||||||
|
data.append("templateKey", template.key)
|
||||||
|
data.append("templateFile", template.file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create App
|
||||||
|
const appResp = await post("/api/applications", data, {})
|
||||||
|
const appJson = await appResp.json()
|
||||||
if (!appResp.ok) {
|
if (!appResp.ok) {
|
||||||
throw new Error(appJson.message)
|
throw new Error(appJson.message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { Label, Heading, Input } from "@budibase/bbui"
|
import { Label, Heading, Input } from "@budibase/bbui"
|
||||||
import Dropzone from "components/common/Dropzone.svelte"
|
|
||||||
|
|
||||||
const BYTES_IN_MB = 1000000
|
const BYTES_IN_MB = 1000000
|
||||||
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
|
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
|
||||||
|
@ -20,8 +19,8 @@
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
file = fileArray[0]
|
file = evt.target.files[0]
|
||||||
template.fileImportPath = file.path
|
template.file = file
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,6 @@ async function getAppUrlIfNotInUse(ctx) {
|
||||||
|
|
||||||
async function createInstance(template) {
|
async function createInstance(template) {
|
||||||
const appId = generateAppID()
|
const appId = generateAppID()
|
||||||
|
|
||||||
const db = new CouchDB(appId)
|
const db = new CouchDB(appId)
|
||||||
await db.put({
|
await db.put({
|
||||||
_id: "_design/database",
|
_id: "_design/database",
|
||||||
|
@ -106,10 +105,10 @@ async function createInstance(template) {
|
||||||
// replicate the template data to the instance DB
|
// replicate the template data to the instance DB
|
||||||
// this is currently very hard to test, downloading and importing template files
|
// this is currently very hard to test, downloading and importing template files
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (template) {
|
if (template && template.useTemplate === "true") {
|
||||||
let dbDumpReadStream
|
let dbDumpReadStream
|
||||||
if (template.fileImportPath) {
|
if (template.file) {
|
||||||
dbDumpReadStream = fs.createReadStream(template.fileImportPath)
|
dbDumpReadStream = fs.createReadStream(template.file.path)
|
||||||
} else {
|
} else {
|
||||||
const templatePath = await downloadTemplate(...template.key.split("/"))
|
const templatePath = await downloadTemplate(...template.key.split("/"))
|
||||||
dbDumpReadStream = fs.createReadStream(
|
dbDumpReadStream = fs.createReadStream(
|
||||||
|
@ -162,8 +161,17 @@ exports.fetchAppPackage = async function(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
|
const { useTemplate, templateKey } = ctx.request.body
|
||||||
|
const instanceConfig = {
|
||||||
|
useTemplate,
|
||||||
|
key: templateKey,
|
||||||
|
}
|
||||||
|
if (ctx.request.files && ctx.request.files.templateFile) {
|
||||||
|
instanceConfig.file = ctx.request.files.templateFile
|
||||||
|
}
|
||||||
|
const instance = await createInstance(instanceConfig)
|
||||||
|
|
||||||
const url = await getAppUrlIfNotInUse(ctx)
|
const url = await getAppUrlIfNotInUse(ctx)
|
||||||
const instance = await createInstance(ctx.request.body.template)
|
|
||||||
const appId = instance._id
|
const appId = instance._id
|
||||||
const version = packageJson.version
|
const version = packageJson.version
|
||||||
const newApplication = {
|
const newApplication = {
|
||||||
|
|
|
@ -152,26 +152,6 @@ async function processLocalFileUploads({ files, outputPath, appId }) {
|
||||||
return processedFiles
|
return processedFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.performLocalFileProcessing = async function(ctx) {
|
|
||||||
const { files } = ctx.request.body
|
|
||||||
|
|
||||||
const processedFileOutputPath = resolve(
|
|
||||||
budibaseAppsDir(),
|
|
||||||
ctx.user.appId,
|
|
||||||
"attachments"
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
|
||||||
ctx.body = await processLocalFileUploads({
|
|
||||||
files,
|
|
||||||
outputPath: processedFileOutputPath,
|
|
||||||
appId: ctx.user.appId,
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
ctx.throw(500, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.serveApp = async function(ctx) {
|
exports.serveApp = async function(ctx) {
|
||||||
let appId = ctx.params.appId
|
let appId = ctx.params.appId
|
||||||
if (env.SELF_HOSTED) {
|
if (env.SELF_HOSTED) {
|
||||||
|
|
|
@ -29,11 +29,7 @@ if (env.SELF_HOSTED) {
|
||||||
}
|
}
|
||||||
|
|
||||||
router
|
router
|
||||||
.post(
|
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
||||||
"/api/attachments/process",
|
|
||||||
authorized(BUILDER),
|
|
||||||
controller.performLocalFileProcessing
|
|
||||||
)
|
|
||||||
.post("/api/attachments/upload", usage, controller.uploadFile)
|
.post("/api/attachments/upload", usage, controller.uploadFile)
|
||||||
.get("/componentlibrary", controller.serveComponentLibrary)
|
.get("/componentlibrary", controller.serveComponentLibrary)
|
||||||
.get("/assets/:file*", controller.serveAppAsset)
|
.get("/assets/:file*", controller.serveAppAsset)
|
||||||
|
|
Loading…
Reference in New Issue