mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-29 13:05:08 +02:00
Add file moving tool (#6223)
This commit is contained in:
@@ -24,7 +24,7 @@ describe('aggregator tests', () => {
|
||||
const ws1: WorkspaceId = { name: 'ws1', productId: '' }
|
||||
return { mem1, mem2, aggr, ws1, testCtx }
|
||||
}
|
||||
it('reuse existing storage', async () => {
|
||||
it('not reuse existing storage', async () => {
|
||||
const { mem1, aggr, ws1, testCtx } = prepare1()
|
||||
|
||||
// Test default provider
|
||||
@@ -37,7 +37,7 @@ describe('aggregator tests', () => {
|
||||
// Test content typed provider
|
||||
await aggr.put(testCtx, ws1, 'test', 'data2', 'text/plain')
|
||||
const stat2 = await aggr.stat(testCtx, ws1, 'test')
|
||||
expect(stat2?.provider).toEqual('mem1')
|
||||
expect(stat2?.provider).toEqual('mem2')
|
||||
|
||||
const dta = Buffer.concat(await aggr.read(testCtx, ws1, 'test')).toString()
|
||||
expect(dta).toEqual('data2')
|
||||
|
||||
@@ -317,12 +317,11 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
|
||||
contentType: string,
|
||||
size?: number | undefined
|
||||
): Promise<UploadedObjectInfo> {
|
||||
// We need to reuse same provider for existing documents.
|
||||
const stat = (
|
||||
await this.dbAdapter.find<Blob>(ctx, workspaceId, DOMAIN_BLOB, { _id: objectName as Ref<Blob> }, { limit: 1 })
|
||||
).shift()
|
||||
|
||||
const { provider, adapter } = this.selectProvider(stat?.provider, contentType)
|
||||
const { provider, adapter } = this.selectProvider(undefined, contentType)
|
||||
|
||||
const result = await adapter.put(ctx, workspaceId, objectName, stream, contentType, size)
|
||||
|
||||
@@ -351,6 +350,13 @@ export class AggregatorStorageAdapter implements StorageAdapter, StorageAdapterE
|
||||
}
|
||||
|
||||
await this.dbAdapter.upload<Blob>(ctx, workspaceId, DOMAIN_BLOB, [blobDoc])
|
||||
|
||||
// If the file is already stored in different provider, we need to remove it.
|
||||
if (stat !== undefined && stat.provider !== provider) {
|
||||
const adapter = this.adapters.get(stat.provider)
|
||||
await adapter?.remove(ctx, workspaceId, [stat._id])
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user