Breaking attachment out into constant that can be re-used, and fixing some imports.

This commit is contained in:
mike12345567 2023-12-06 11:39:46 +00:00
parent 2f6bcdd620
commit 0727df6f98
3 changed files with 16 additions and 10 deletions

View File

@ -1,3 +1,4 @@
export const DB_EXPORT_FILE = "db.txt" export const DB_EXPORT_FILE = "db.txt"
export const GLOBAL_DB_EXPORT_FILE = "global.txt" export const GLOBAL_DB_EXPORT_FILE = "global.txt"
export const STATIC_APP_FILES = ["manifest.json", "budibase-client.js"] export const STATIC_APP_FILES = ["manifest.json", "budibase-client.js"]
export const ATTACHMENT_DIRECTORY = "attachments"

View File

@ -8,13 +8,15 @@ import {
TABLE_ROW_PREFIX, TABLE_ROW_PREFIX,
USER_METDATA_PREFIX, USER_METDATA_PREFIX,
} from "../../../db/utils" } 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 fs from "fs"
import { join } from "path" import { join } from "path"
import env from "../../../environment" import env from "../../../environment"
import { v4 as uuid } from "uuid"
const uuid = require("uuid/v4")
import tar from "tar" import tar from "tar"
const MemoryStream = require("memorystream") const MemoryStream = require("memorystream")
@ -150,7 +152,7 @@ export async function exportApp(appId: string, config?: ExportOpts) {
const path = join(tmpPath, file) const path = join(tmpPath, file)
// skip the attachments - too big to encrypt // skip the attachments - too big to encrypt
if (file !== "attachments") { if (file !== ATTACHMENT_DIRECTORY) {
await encryption.encryptFile( await encryption.encryptFile(
{ dir: tmpPath, filename: file }, { dir: tmpPath, filename: file },
config.encryptPassword config.encryptPassword

View File

@ -8,15 +8,18 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { getAutomationParams } 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,
ATTACHMENT_DIRECTORY,
} from "./constants"
import { downloadTemplate } from "../../../utilities/fileSystem" import { downloadTemplate } from "../../../utilities/fileSystem"
import { ObjectStoreBuckets } from "../../../constants" import { ObjectStoreBuckets } from "../../../constants"
import { join } from "path" import { join } from "path"
import fs from "fs" import fs from "fs"
import sdk from "../../" import sdk from "../../"
import { v4 as uuid } from "uuid"
const uuid = require("uuid/v4") import tar from "tar"
const tar = require("tar")
type TemplateType = { type TemplateType = {
file?: { file?: {
@ -129,7 +132,7 @@ 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)
if (!inputPath.endsWith("attachments")) { if (!inputPath.endsWith(ATTACHMENT_DIRECTORY)) {
const outputPath = inputPath.replace(/\.enc$/, "") const outputPath = inputPath.replace(/\.enc$/, "")
await encryption.decryptFile(inputPath, outputPath, password) await encryption.decryptFile(inputPath, outputPath, password)
fs.rmSync(inputPath) fs.rmSync(inputPath)