Quick fix to make sure that the important components of the app metadata are correctly updated - as well as adjusting the import modal to check if the export is encrypted.

This commit is contained in:
mike12345567 2023-10-13 17:43:14 +01:00
parent 7cef9bf597
commit 6a4877159d
2 changed files with 39 additions and 3 deletions

View File

@ -54,6 +54,7 @@
label="App export" label="App export"
on:change={e => { on:change={e => {
file = e.detail?.[0] file = e.detail?.[0]
encrypted = file?.name?.endsWith(".enc.tar.gz")
}} }}
/> />
<Toggle text="Encrypted" bind:value={encrypted} /> <Toggle text="Encrypted" bind:value={encrypted} />

View File

@ -4,6 +4,8 @@ import {
Document, Document,
Database, Database,
RowValue, RowValue,
DocumentType,
App,
} from "@budibase/types" } from "@budibase/types"
import backups from "../backups" import backups from "../backups"
@ -12,9 +14,39 @@ export type FileAttributes = {
path: string path: string
} }
async function getNewAppMetadata(
tempDb: Database,
appDb: Database
): Promise<App> {
// static doc denoting app information
const docId = DocumentType.APP_METADATA
try {
const [tempMetadata, appMetadata] = await Promise.all([
tempDb.get<App>(docId),
appDb.get<App>(docId),
])
return {
...appMetadata,
automationErrors: undefined,
theme: tempMetadata.theme,
customTheme: tempMetadata.customTheme,
features: tempMetadata.features,
icon: tempMetadata.icon,
navigation: tempMetadata.navigation,
type: tempMetadata.type,
version: tempMetadata.version,
}
} catch (err: any) {
throw new Error(
`Unable to retrieve app metadata for import - ${err.message}`
)
}
}
function mergeUpdateAndDeleteDocuments( function mergeUpdateAndDeleteDocuments(
updateDocs: Document[], updateDocs: Document[],
deleteDocs: Document[] deleteDocs: Document[],
metadata: App
) { ) {
// compress the documents to create and to delete (if same ID, then just update the rev) // compress the documents to create and to delete (if same ID, then just update the rev)
const finalToDelete = [] const finalToDelete = []
@ -26,7 +58,7 @@ function mergeUpdateAndDeleteDocuments(
finalToDelete.push(deleteDoc) finalToDelete.push(deleteDoc)
} }
} }
return [...updateDocs, ...finalToDelete] return [...updateDocs, ...finalToDelete, metadata]
} }
async function removeImportableDocuments(db: Database) { async function removeImportableDocuments(db: Database) {
@ -90,12 +122,15 @@ export async function updateWithExport(
await backups.importApp(devId, tempDb, template, { await backups.importApp(devId, tempDb, template, {
importObjStoreContents: false, importObjStoreContents: false,
}) })
const newMetadata = await getNewAppMetadata(tempDb, appDb)
// get the documents to copy // get the documents to copy
const toUpdate = await getImportableDocuments(tempDb) const toUpdate = await getImportableDocuments(tempDb)
// clear out the old documents // clear out the old documents
const toDelete = await removeImportableDocuments(appDb) const toDelete = await removeImportableDocuments(appDb)
// now bulk update documents - add new ones, delete old ones and update common ones // now bulk update documents - add new ones, delete old ones and update common ones
await appDb.bulkDocs(mergeUpdateAndDeleteDocuments(toUpdate, toDelete)) await appDb.bulkDocs(
mergeUpdateAndDeleteDocuments(toUpdate, toDelete, newMetadata)
)
} finally { } finally {
await tempDb.destroy() await tempDb.destroy()
} }