mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat: init affine blob storage (#2045)
This commit is contained in:
@@ -1,16 +1,47 @@
|
||||
import type { createWorkspaceApis } from '@affine/workspace/affine/api';
|
||||
import { createAffineBlobStorage } from '@affine/workspace/blob';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { BlobOptionsGetter, Generator } from '@blocksuite/store';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import type { Generator } from '@blocksuite/store';
|
||||
import { createIndexeddbStorage, Workspace } from '@blocksuite/store';
|
||||
|
||||
import { WorkspaceFlavour } from './type';
|
||||
|
||||
const hashMap = new Map<string, Workspace>();
|
||||
export const createEmptyBlockSuiteWorkspace = (
|
||||
|
||||
export function createEmptyBlockSuiteWorkspace(
|
||||
id: string,
|
||||
blobOptionsGetter?: BlobOptionsGetter,
|
||||
config?: {
|
||||
flavour: WorkspaceFlavour.AFFINE,
|
||||
config: {
|
||||
workspaceApis: ReturnType<typeof createWorkspaceApis>;
|
||||
cachePrefix?: string;
|
||||
idGenerator?: Generator;
|
||||
}
|
||||
): Workspace => {
|
||||
): Workspace;
|
||||
export function createEmptyBlockSuiteWorkspace(
|
||||
id: string,
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
config?: {
|
||||
workspaceApis?: ReturnType<typeof createWorkspaceApis>;
|
||||
cachePrefix?: string;
|
||||
idGenerator?: Generator;
|
||||
}
|
||||
): Workspace;
|
||||
export function createEmptyBlockSuiteWorkspace(
|
||||
id: string,
|
||||
flavour: WorkspaceFlavour,
|
||||
config?: {
|
||||
workspaceApis?: ReturnType<typeof createWorkspaceApis>;
|
||||
cachePrefix?: string;
|
||||
idGenerator?: Generator;
|
||||
}
|
||||
): Workspace {
|
||||
if (
|
||||
flavour === WorkspaceFlavour.AFFINE &&
|
||||
!config?.workspaceApis?.getBlob &&
|
||||
!config?.workspaceApis?.uploadBlob
|
||||
) {
|
||||
throw new Error('workspaceApis is required for affine flavour');
|
||||
}
|
||||
const prefix: string = config?.cachePrefix ?? '';
|
||||
const cacheKey = `${prefix}${id}`;
|
||||
if (hashMap.has(cacheKey)) {
|
||||
@@ -20,11 +51,16 @@ export const createEmptyBlockSuiteWorkspace = (
|
||||
const workspace = new Workspace({
|
||||
id,
|
||||
isSSR: typeof window === 'undefined',
|
||||
blobOptionsGetter,
|
||||
blobStorages:
|
||||
flavour === WorkspaceFlavour.AFFINE
|
||||
? [id => createAffineBlobStorage(id, config!.workspaceApis!)]
|
||||
: typeof window === 'undefined'
|
||||
? []
|
||||
: [createIndexeddbStorage],
|
||||
idGenerator,
|
||||
})
|
||||
.register(AffineSchemas)
|
||||
.register(__unstableSchemas);
|
||||
hashMap.set(cacheKey, workspace);
|
||||
return workspace;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user