Remove electron specific attachment uploads inside the builder
This commit is contained in:
parent
646ed4a7dd
commit
08ea461caa
|
@ -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>
|
||||||
|
|
|
@ -74,29 +74,6 @@ exports.uploadFile = async function(ctx) {
|
||||||
"attachments"
|
"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({
|
ctx.body = await processLocalFileUploads({
|
||||||
files,
|
files,
|
||||||
outputPath: attachmentsPath,
|
outputPath: attachmentsPath,
|
||||||
|
@ -152,26 +129,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