From 08ea461caab833cf9ac27ffab398080ebe864269 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 15 Mar 2021 12:10:21 +0000 Subject: [PATCH] Remove electron specific attachment uploads inside the builder --- packages/builder/src/builderStore/api.js | 3 +- .../src/components/common/Dropzone.svelte | 17 +++----- .../src/api/controllers/static/index.js | 43 ------------------- packages/server/src/api/routes/static.js | 6 +-- 4 files changed, 8 insertions(+), 61 deletions(-) diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/builderStore/api.js index 46304e1486..0202c5e8ab 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/builderStore/api.js @@ -7,9 +7,10 @@ const apiCall = method => async ( headers = { "Content-Type": "application/json" } ) => { headers["x-budibase-app-id"] = svelteGet(store).appId + const json = headers["Content-Type"] === "application/json" return await fetch(url, { method: method, - body: body && JSON.stringify(body), + body: json ? JSON.stringify(body) : body, headers, }) } diff --git a/packages/builder/src/components/common/Dropzone.svelte b/packages/builder/src/components/common/Dropzone.svelte index be93829084..0b98f2b256 100644 --- a/packages/builder/src/components/common/Dropzone.svelte +++ b/packages/builder/src/components/common/Dropzone.svelte @@ -15,18 +15,11 @@ } async function processFiles(fileList) { - const fileArray = Array.from(fileList) - - const filesToProcess = fileArray.map(({ name, path, size, type }) => ({ - name, - path, - size, - type, - })) - - const response = await api.post(`/api/attachments/process`, { - files: filesToProcess, - }) + let data = new FormData() + for (let i = 0; i < fileList.length; i++) { + data.append("file", fileList[i]) + } + const response = await api.post(`/api/attachments/process`, data, {}) return await response.json() } diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index bf01314795..bc9384b892 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -74,29 +74,6 @@ exports.uploadFile = async function(ctx) { "attachments" ) - if (env.CLOUD) { - // remote upload - const s3 = new AWS.S3({ - params: { - Bucket: "prod-budi-app-assets", - }, - }) - - const uploads = files.map(file => { - const fileExtension = [...file.name.split(".")].pop() - const processedFileName = `${uuid.v4()}.${fileExtension}` - - return prepareUpload({ - file, - s3Key: `assets/${ctx.user.appId}/attachments/${processedFileName}`, - s3, - }) - }) - - ctx.body = await Promise.all(uploads) - return - } - ctx.body = await processLocalFileUploads({ files, outputPath: attachmentsPath, @@ -152,26 +129,6 @@ async function processLocalFileUploads({ files, outputPath, appId }) { 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) { let appId = ctx.params.appId if (env.SELF_HOSTED) { diff --git a/packages/server/src/api/routes/static.js b/packages/server/src/api/routes/static.js index c812c4d3b1..30701d578b 100644 --- a/packages/server/src/api/routes/static.js +++ b/packages/server/src/api/routes/static.js @@ -29,11 +29,7 @@ if (env.SELF_HOSTED) { } router - .post( - "/api/attachments/process", - authorized(BUILDER), - controller.performLocalFileProcessing - ) + .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile) .post("/api/attachments/upload", usage, controller.uploadFile) .get("/componentlibrary", controller.serveComponentLibrary) .get("/assets/:file*", controller.serveAppAsset)