Fix proper workspace dump of attachments (#577)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2021-12-08 16:08:34 +07:00 committed by GitHub
parent 6f41a078da
commit 1abcee26bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@ import contact from '@anticrm/contact'
import core, { DOMAIN_TX, Tx } from '@anticrm/core'
import builder, { migrateOperations } from '@anticrm/model-all'
import { existsSync } from 'fs'
import { mkdir, readFile, writeFile } from 'fs/promises'
import { mkdir, open, readFile, writeFile } from 'fs/promises'
import { BucketItem, Client, ItemBucketMetadata } from 'minio'
import { Document, MongoClient } from 'mongodb'
import { join } from 'path'
@ -157,14 +157,30 @@ export async function dumpWorkspace (mongoUrl: string, dbName: string, fileName:
}
for (const d of workspaceInfo.minioData) {
const stat = await minio.statObject(dbName, d.name)
const data = await minio.getObject(dbName, d.name)
const allData = []
d.metaData = stat.metaData
let chunk
while ((chunk = data.read()) !== null) {
allData.push(chunk)
const fileHandle = await open(join(minioDbLocation, d.name), 'w')
const data = await minio.getObject(dbName, d.name)
const chunks: Buffer[] = []
await new Promise((resolve) => {
data.on('readable', () => {
let chunk
while ((chunk = data.read()) !== null) {
const b = (chunk as Buffer)
chunks.push(b)
}
})
data.on('end', () => {
resolve(null)
})
})
for (const b of chunks) {
await fileHandle.write(b)
}
await writeFile(join(minioDbLocation, d.name), allData.join(''))
await fileHandle.close()
}
}