Connect tenant merge planner to exports
This commit is contained in:
@@ -1025,41 +1025,14 @@ export const importTenantFullExportArchive = async (
|
||||
archiveBuffer: Buffer,
|
||||
options: ImportOptions = {}
|
||||
): Promise<ImportResult> => {
|
||||
const rawExportData = await readTenantFullExportArchive(archiveBuffer)
|
||||
const exportData = remapTenantScopedExport(rawExportData, options.targetTenantId)
|
||||
const reader = new ZipReader(new BlobReader(new Blob([archiveBuffer])))
|
||||
|
||||
try {
|
||||
const entries = await reader.getEntries()
|
||||
const entriesByName = new Map(entries.map((entry: any) => [entry.filename, entry]))
|
||||
const manifest = JSON.parse(await readZipTextEntry(entriesByName, "manifest.json")) as TenantArchiveManifest
|
||||
|
||||
if (manifest?.format !== "fedeo.tenant-archive-export" || manifest.version !== 1) {
|
||||
throw new Error("Ungültiges FEDEO Mandantenarchiv-Format")
|
||||
}
|
||||
|
||||
const tables: TableRows = {}
|
||||
for (const table of manifest.tables || []) {
|
||||
tables[table.name] = JSON.parse(await readZipTextEntry(entriesByName, table.path))
|
||||
}
|
||||
|
||||
const rawExportData: TenantFullExport = {
|
||||
format: "fedeo.tenant-full-export",
|
||||
version: 1,
|
||||
exportedAt: manifest.exportedAt,
|
||||
tenantId: manifest.tenantId,
|
||||
tables,
|
||||
files: (manifest.files || []).map((file) => ({
|
||||
id: file.id,
|
||||
path: file.path,
|
||||
name: file.name,
|
||||
mimeType: file.mimeType,
|
||||
size: file.size,
|
||||
contentBase64: null,
|
||||
missing: file.missing,
|
||||
error: file.error,
|
||||
})),
|
||||
}
|
||||
|
||||
const exportData = remapTenantScopedExport(rawExportData, options.targetTenantId)
|
||||
const sourceTenantId = rawExportData.tenantId
|
||||
const targetTenantId = exportData.tenantId
|
||||
const sourcePrefix = `${sourceTenantId}/`
|
||||
@@ -1086,3 +1059,43 @@ export const importTenantFullExportArchive = async (
|
||||
await reader.close()
|
||||
}
|
||||
}
|
||||
|
||||
export const readTenantFullExportArchive = async (archiveBuffer: Buffer): Promise<TenantFullExport> => {
|
||||
const reader = new ZipReader(new BlobReader(new Blob([archiveBuffer])))
|
||||
|
||||
try {
|
||||
const entries = await reader.getEntries()
|
||||
const entriesByName = new Map(entries.map((entry: any) => [entry.filename, entry]))
|
||||
const manifest = JSON.parse(await readZipTextEntry(entriesByName, "manifest.json")) as TenantArchiveManifest
|
||||
|
||||
if (manifest?.format !== "fedeo.tenant-archive-export" || manifest.version !== 1) {
|
||||
throw new Error("Ungültiges FEDEO Mandantenarchiv-Format")
|
||||
}
|
||||
|
||||
const tables: TableRows = {}
|
||||
for (const table of manifest.tables || []) {
|
||||
tables[table.name] = JSON.parse(await readZipTextEntry(entriesByName, table.path))
|
||||
}
|
||||
|
||||
return {
|
||||
format: "fedeo.tenant-full-export",
|
||||
version: 1,
|
||||
exportedAt: manifest.exportedAt,
|
||||
tenantId: manifest.tenantId,
|
||||
tables,
|
||||
files: (manifest.files || []).map((file) => ({
|
||||
id: file.id,
|
||||
path: file.path,
|
||||
name: file.name,
|
||||
mimeType: file.mimeType,
|
||||
size: file.size,
|
||||
contentBase64: null,
|
||||
missing: file.missing,
|
||||
error: file.error,
|
||||
})),
|
||||
}
|
||||
|
||||
} finally {
|
||||
await reader.close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user