From 0727df6f98dc6641d8551b47b3bf705ffe08830b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 6 Dec 2023 11:39:46 +0000 Subject: [PATCH] Breaking attachment out into constant that can be re-used, and fixing some imports. --- packages/server/src/sdk/app/backups/constants.ts | 1 + packages/server/src/sdk/app/backups/exports.ts | 12 +++++++----- packages/server/src/sdk/app/backups/imports.ts | 13 ++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/server/src/sdk/app/backups/constants.ts b/packages/server/src/sdk/app/backups/constants.ts index 0584fcb3d0..ddb1954f8f 100644 --- a/packages/server/src/sdk/app/backups/constants.ts +++ b/packages/server/src/sdk/app/backups/constants.ts @@ -1,3 +1,4 @@ export const DB_EXPORT_FILE = "db.txt" export const GLOBAL_DB_EXPORT_FILE = "global.txt" export const STATIC_APP_FILES = ["manifest.json", "budibase-client.js"] +export const ATTACHMENT_DIRECTORY = "attachments" diff --git a/packages/server/src/sdk/app/backups/exports.ts b/packages/server/src/sdk/app/backups/exports.ts index cc0b78e34f..813f813177 100644 --- a/packages/server/src/sdk/app/backups/exports.ts +++ b/packages/server/src/sdk/app/backups/exports.ts @@ -8,13 +8,15 @@ import { TABLE_ROW_PREFIX, USER_METDATA_PREFIX, } from "../../../db/utils" -import { DB_EXPORT_FILE, STATIC_APP_FILES } from "./constants" +import { + DB_EXPORT_FILE, + STATIC_APP_FILES, + ATTACHMENT_DIRECTORY, +} from "./constants" import fs from "fs" import { join } from "path" import env from "../../../environment" - -const uuid = require("uuid/v4") - +import { v4 as uuid } from "uuid" import tar from "tar" const MemoryStream = require("memorystream") @@ -150,7 +152,7 @@ export async function exportApp(appId: string, config?: ExportOpts) { const path = join(tmpPath, file) // skip the attachments - too big to encrypt - if (file !== "attachments") { + if (file !== ATTACHMENT_DIRECTORY) { await encryption.encryptFile( { dir: tmpPath, filename: file }, config.encryptPassword diff --git a/packages/server/src/sdk/app/backups/imports.ts b/packages/server/src/sdk/app/backups/imports.ts index 4c0030abf9..7f76945107 100644 --- a/packages/server/src/sdk/app/backups/imports.ts +++ b/packages/server/src/sdk/app/backups/imports.ts @@ -8,15 +8,18 @@ import { } from "@budibase/types" import { getAutomationParams } from "../../../db/utils" import { budibaseTempDir } from "../../../utilities/budibaseDir" -import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants" +import { + DB_EXPORT_FILE, + GLOBAL_DB_EXPORT_FILE, + ATTACHMENT_DIRECTORY, +} from "./constants" import { downloadTemplate } from "../../../utilities/fileSystem" import { ObjectStoreBuckets } from "../../../constants" import { join } from "path" import fs from "fs" import sdk from "../../" - -const uuid = require("uuid/v4") -const tar = require("tar") +import { v4 as uuid } from "uuid" +import tar from "tar" type TemplateType = { file?: { @@ -129,7 +132,7 @@ async function decryptFiles(path: string, password: string) { try { for (let file of fs.readdirSync(path)) { const inputPath = join(path, file) - if (!inputPath.endsWith("attachments")) { + if (!inputPath.endsWith(ATTACHMENT_DIRECTORY)) { const outputPath = inputPath.replace(/\.enc$/, "") await encryption.decryptFile(inputPath, outputPath, password) fs.rmSync(inputPath)