Fixing importing - still some work to get links correct.

This commit is contained in:
mike12345567 2023-12-01 19:37:43 +00:00
parent 00a3c630ef
commit 19c069946a
4 changed files with 25 additions and 19 deletions

View File

@ -59,6 +59,7 @@ const environment = {
BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD, BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD,
PLUGINS_DIR: process.env.PLUGINS_DIR || "/plugins", PLUGINS_DIR: process.env.PLUGINS_DIR || "/plugins",
OPENAI_API_KEY: process.env.OPENAI_API_KEY, OPENAI_API_KEY: process.env.OPENAI_API_KEY,
MAX_IMPORT_SIZE_MB: process.env.MAX_IMPORT_SIZE_MB,
// flags // flags
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS, ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
DISABLE_THREADING: process.env.DISABLE_THREADING, DISABLE_THREADING: process.env.DISABLE_THREADING,

View File

@ -1,5 +1,5 @@
import env from "./environment" import env from "./environment"
import Koa, { ExtendableContext } from "koa" import Koa from "koa"
import koaBody from "koa-body" import koaBody from "koa-body"
import http from "http" import http from "http"
import * as api from "./api" import * as api from "./api"
@ -27,6 +27,9 @@ export default function createKoaApp() {
// @ts-ignore // @ts-ignore
enableTypes: ["json", "form", "text"], enableTypes: ["json", "form", "text"],
parsedMethods: ["POST", "PUT", "PATCH", "DELETE"], parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
formidable: {
maxFileSize: parseInt(env.MAX_IMPORT_SIZE_MB || "100") * 1024 * 1024,
},
}) })
) )

View File

@ -30,12 +30,11 @@ export interface ExportOpts extends DBDumpOpts {
encryptPassword?: string encryptPassword?: string
} }
function tarFilesToTmp(tmpDir: string, files: string[]) { async function tarFilesToTmp(tmpDir: string, files: string[]) {
const fileName = `${uuid()}.tar.gz` const fileName = `${uuid()}.tar.gz`
const exportFile = join(budibaseTempDir(), fileName) const exportFile = join(budibaseTempDir(), fileName)
tar.create( await tar.create(
{ {
sync: true,
gzip: true, gzip: true,
file: exportFile, file: exportFile,
noDirRecurse: false, noDirRecurse: false,
@ -150,19 +149,21 @@ export async function exportApp(appId: string, config?: ExportOpts) {
for (let file of fs.readdirSync(tmpPath)) { for (let file of fs.readdirSync(tmpPath)) {
const path = join(tmpPath, file) const path = join(tmpPath, file)
await encryption.encryptFile( // skip the attachments - too big to encrypt
{ dir: tmpPath, filename: file }, if (file !== "attachments") {
config.encryptPassword await encryption.encryptFile(
) { dir: tmpPath, filename: file },
config.encryptPassword
fs.rmSync(path) )
fs.rmSync(path)
}
} }
} }
// if tar requested, return where the tarball is // if tar requested, return where the tarball is
if (config?.tar) { if (config?.tar) {
// now the tmpPath contains both the DB export and attachments, tar this // now the tmpPath contains both the DB export and attachments, tar this
const tarPath = tarFilesToTmp(tmpPath, fs.readdirSync(tmpPath)) const tarPath = await tarFilesToTmp(tmpPath, fs.readdirSync(tmpPath))
// cleanup the tmp export files as tarball returned // cleanup the tmp export files as tarball returned
fs.rmSync(tmpPath, { recursive: true, force: true }) fs.rmSync(tmpPath, { recursive: true, force: true })

View File

@ -6,7 +6,7 @@ import {
AutomationTriggerStepId, AutomationTriggerStepId,
RowAttachment, RowAttachment,
} from "@budibase/types" } from "@budibase/types"
import { getAutomationParams, TABLE_ROW_PREFIX } from "../../../db/utils" import { getAutomationParams } from "../../../db/utils"
import { budibaseTempDir } from "../../../utilities/budibaseDir" import { budibaseTempDir } from "../../../utilities/budibaseDir"
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants" import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
import { downloadTemplate } from "../../../utilities/fileSystem" import { downloadTemplate } from "../../../utilities/fileSystem"
@ -114,12 +114,11 @@ async function getTemplateStream(template: TemplateType) {
} }
} }
export function untarFile(file: { path: string }) { export async function untarFile(file: { path: string }) {
const tmpPath = join(budibaseTempDir(), uuid()) const tmpPath = join(budibaseTempDir(), uuid())
fs.mkdirSync(tmpPath) fs.mkdirSync(tmpPath)
// extract the tarball // extract the tarball
tar.extract({ await tar.extract({
sync: true,
cwd: tmpPath, cwd: tmpPath,
file: file.path, file: file.path,
}) })
@ -130,9 +129,11 @@ async function decryptFiles(path: string, password: string) {
try { try {
for (let file of fs.readdirSync(path)) { for (let file of fs.readdirSync(path)) {
const inputPath = join(path, file) const inputPath = join(path, file)
const outputPath = inputPath.replace(/\.enc$/, "") if (!inputPath.endsWith("attachments")) {
await encryption.decryptFile(inputPath, outputPath, password) const outputPath = inputPath.replace(/\.enc$/, "")
fs.rmSync(inputPath) await encryption.decryptFile(inputPath, outputPath, password)
fs.rmSync(inputPath)
}
} }
} catch (err: any) { } catch (err: any) {
if (err.message === "incorrect header check") { if (err.message === "incorrect header check") {
@ -162,7 +163,7 @@ export async function importApp(
const isDirectory = const isDirectory =
template.file && fs.lstatSync(template.file.path).isDirectory() template.file && fs.lstatSync(template.file.path).isDirectory()
if (template.file && (isTar || isDirectory)) { if (template.file && (isTar || isDirectory)) {
const tmpPath = isTar ? untarFile(template.file) : template.file.path const tmpPath = isTar ? await untarFile(template.file) : template.file.path
if (isTar && template.file.password) { if (isTar && template.file.password) {
await decryptFiles(tmpPath, template.file.password) await decryptFiles(tmpPath, template.file.password)
} }