mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-29 04:55:03 +02:00
UBERF-6161: Storage configuration (#5109)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -47,7 +47,7 @@ export async function loadCollaborativeDoc (
|
||||
|
||||
return await ctx.with('loadCollaborativeDoc', { type: 'content' }, async (ctx) => {
|
||||
const yContent = await ctx.with('yDocFromMinio', { type: 'content' }, async () => {
|
||||
return await yDocFromStorage(storageAdapter, workspace, documentId, new YDoc({ gc: false }))
|
||||
return await yDocFromStorage(ctx, storageAdapter, workspace, documentId, new YDoc({ gc: false }))
|
||||
})
|
||||
|
||||
// the document does not exist
|
||||
@@ -60,7 +60,7 @@ export async function loadCollaborativeDoc (
|
||||
}
|
||||
|
||||
const yHistory = await ctx.with('yDocFromMinio', { type: 'history' }, async () => {
|
||||
return await yDocFromStorage(storageAdapter, workspace, historyDocumentId, new YDoc())
|
||||
return await yDocFromStorage(ctx, storageAdapter, workspace, historyDocumentId, new YDoc())
|
||||
})
|
||||
|
||||
// the history document does not exist
|
||||
@@ -98,7 +98,7 @@ export async function saveCollaborativeDocVersion (
|
||||
await ctx.with('saveCollaborativeDoc', {}, async (ctx) => {
|
||||
if (versionId === 'HEAD') {
|
||||
await ctx.with('yDocToMinio', {}, async () => {
|
||||
await yDocToStorage(storageAdapter, workspace, documentId, ydoc)
|
||||
await yDocToStorage(ctx, storageAdapter, workspace, documentId, ydoc)
|
||||
})
|
||||
} else {
|
||||
console.warn('Cannot save non HEAD document version', documentId, versionId)
|
||||
@@ -125,7 +125,7 @@ export async function removeCollaborativeDoc (
|
||||
}
|
||||
if (toRemove.length > 0) {
|
||||
await ctx.with('remove', {}, async () => {
|
||||
await storageAdapter.remove(workspace, toRemove)
|
||||
await storageAdapter.remove(ctx, workspace, toRemove)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -181,7 +181,7 @@ export async function takeCollaborativeDocSnapshot (
|
||||
await ctx.with('takeCollaborativeDocSnapshot', {}, async (ctx) => {
|
||||
const yHistory =
|
||||
(await ctx.with('yDocFromMinio', { type: 'history' }, async () => {
|
||||
return await yDocFromStorage(storageAdapter, workspace, historyDocumentId, new YDoc({ gc: false }))
|
||||
return await yDocFromStorage(ctx, storageAdapter, workspace, historyDocumentId, new YDoc({ gc: false }))
|
||||
})) ?? new YDoc()
|
||||
|
||||
await ctx.with('createYdocSnapshot', {}, async () => {
|
||||
@@ -189,7 +189,7 @@ export async function takeCollaborativeDocSnapshot (
|
||||
})
|
||||
|
||||
await ctx.with('yDocToMinio', { type: 'history' }, async () => {
|
||||
await yDocToStorage(storageAdapter, workspace, historyDocumentId, yHistory)
|
||||
await yDocToStorage(ctx, storageAdapter, workspace, historyDocumentId, yHistory)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { WorkspaceId } from '@hcengineering/core'
|
||||
import { MeasureContext, WorkspaceId } from '@hcengineering/core'
|
||||
import { StorageAdapter } from '@hcengineering/server-core'
|
||||
import { Doc as YDoc } from 'yjs'
|
||||
|
||||
@@ -21,6 +21,7 @@ import { yDocFromBuffer, yDocToBuffer } from './ydoc'
|
||||
|
||||
/** @public */
|
||||
export async function yDocFromStorage (
|
||||
ctx: MeasureContext,
|
||||
storageAdapter: StorageAdapter,
|
||||
workspace: WorkspaceId,
|
||||
minioDocumentId: string,
|
||||
@@ -31,7 +32,7 @@ export async function yDocFromStorage (
|
||||
ydoc ??= new YDoc({ gc: false })
|
||||
|
||||
try {
|
||||
const buffer = await storageAdapter.read(workspace, minioDocumentId)
|
||||
const buffer = await storageAdapter.read(ctx, workspace, minioDocumentId)
|
||||
return yDocFromBuffer(Buffer.concat(buffer), ydoc)
|
||||
} catch (err: any) {
|
||||
if (err?.code === 'NoSuchKey' || err?.code === 'NotFound') {
|
||||
@@ -43,12 +44,12 @@ export async function yDocFromStorage (
|
||||
|
||||
/** @public */
|
||||
export async function yDocToStorage (
|
||||
ctx: MeasureContext,
|
||||
storageAdapter: StorageAdapter,
|
||||
workspace: WorkspaceId,
|
||||
minioDocumentId: string,
|
||||
ydoc: YDoc
|
||||
): Promise<void> {
|
||||
const buffer = yDocToBuffer(ydoc)
|
||||
const metadata = { 'content-type': 'application/ydoc' }
|
||||
await storageAdapter.put(workspace, minioDocumentId, buffer, buffer.length, metadata)
|
||||
await storageAdapter.put(ctx, workspace, minioDocumentId, buffer, 'application/ydoc', buffer.length)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user