fix: add token and api to blocksuitWorkspace
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import { WorkspaceUnitCollection } from './workspace-unit-collection.js';
|
import { WorkspaceUnitCollection } from './workspace-unit-collection.js';
|
||||||
import type { WorkspaceUnitCollectionChangeEvent } from './workspace-unit-collection';
|
import type { WorkspaceUnitCollectionChangeEvent } from './workspace-unit-collection';
|
||||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
import {
|
||||||
|
StoreOptions,
|
||||||
|
Workspace as BlocksuiteWorkspace,
|
||||||
|
} from '@blocksuite/store';
|
||||||
import type {
|
import type {
|
||||||
BaseProvider,
|
BaseProvider,
|
||||||
CreateWorkspaceInfoParams,
|
CreateWorkspaceInfoParams,
|
||||||
@@ -14,7 +17,7 @@ import { getLogger } from './logger';
|
|||||||
import { createBlocksuiteWorkspace } from './utils/index.js';
|
import { createBlocksuiteWorkspace } from './utils/index.js';
|
||||||
import { MessageCenter } from './message';
|
import { MessageCenter } from './message';
|
||||||
import { WorkspaceUnit } from './workspace-unit';
|
import { WorkspaceUnit } from './workspace-unit';
|
||||||
|
import { token } from './provider/affine/apis/token';
|
||||||
/**
|
/**
|
||||||
* @class DataCenter
|
* @class DataCenter
|
||||||
* @classdesc Data center is made for managing different providers for business
|
* @classdesc Data center is made for managing different providers for business
|
||||||
@@ -116,12 +119,12 @@ export class DataCenter {
|
|||||||
* get a new workspace only has room id
|
* get a new workspace only has room id
|
||||||
* @param {string} workspaceId workspace id
|
* @param {string} workspaceId workspace id
|
||||||
*/
|
*/
|
||||||
private _getBlocksuiteWorkspace(workspaceId: string) {
|
private _getBlocksuiteWorkspace(workspaceId: string, params: StoreOptions) {
|
||||||
// const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
// const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||||
// assert(workspaceInfo, 'Workspace not found');
|
// assert(workspaceInfo, 'Workspace not found');
|
||||||
return (
|
return (
|
||||||
// this._workspaceInstances.get(workspaceId) ||
|
// this._workspaceInstances.get(workspaceId) ||
|
||||||
createBlocksuiteWorkspace(workspaceId)
|
createBlocksuiteWorkspace(workspaceId, params)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +165,15 @@ export class DataCenter {
|
|||||||
const provider = this.providerMap.get(workspaceUnit.provider);
|
const provider = this.providerMap.get(workspaceUnit.provider);
|
||||||
assert(provider, `provide '${workspaceUnit.provider}' is not registered`);
|
assert(provider, `provide '${workspaceUnit.provider}' is not registered`);
|
||||||
this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId);
|
this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId);
|
||||||
const workspace = this._getBlocksuiteWorkspace(workspaceId);
|
|
||||||
|
const params: StoreOptions = {};
|
||||||
|
if (provider.id === 'affine') {
|
||||||
|
params.blobOptionsGetter = (k: string) =>
|
||||||
|
({ api: '/api/workspace', token: token.token }[k]);
|
||||||
|
} else {
|
||||||
|
params.blobOptionsGetter = (k: string) => undefined;
|
||||||
|
}
|
||||||
|
const workspace = this._getBlocksuiteWorkspace(workspaceId, params);
|
||||||
this._workspaceInstances.set(workspaceId, workspace);
|
this._workspaceInstances.set(workspaceId, workspace);
|
||||||
await provider.warpWorkspace(workspace);
|
await provider.warpWorkspace(workspace);
|
||||||
this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => {
|
this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => {
|
||||||
@@ -178,7 +189,7 @@ export class DataCenter {
|
|||||||
// FIXME: hard code for public workspace
|
// FIXME: hard code for public workspace
|
||||||
const provider = this.providerMap.get('affine');
|
const provider = this.providerMap.get('affine');
|
||||||
assert(provider);
|
assert(provider);
|
||||||
const blocksuiteWorkspace = this._getBlocksuiteWorkspace(workspaceId);
|
const blocksuiteWorkspace = this._getBlocksuiteWorkspace(workspaceId, {});
|
||||||
await provider.loadPublicWorkspace(blocksuiteWorkspace);
|
await provider.loadPublicWorkspace(blocksuiteWorkspace);
|
||||||
|
|
||||||
const workspaceUnitForPublic = new WorkspaceUnit({
|
const workspaceUnitForPublic = new WorkspaceUnit({
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
import {
|
||||||
|
StoreOptions,
|
||||||
|
Workspace as BlocksuiteWorkspace,
|
||||||
|
} from '@blocksuite/store';
|
||||||
import { builtInSchemas } from '@blocksuite/blocks/models';
|
import { builtInSchemas } from '@blocksuite/blocks/models';
|
||||||
|
|
||||||
export const createBlocksuiteWorkspace = (workspaceId: string) => {
|
export const createBlocksuiteWorkspace = (
|
||||||
|
workspaceId: string,
|
||||||
|
workspaceOption?: StoreOptions
|
||||||
|
) => {
|
||||||
return new BlocksuiteWorkspace({
|
return new BlocksuiteWorkspace({
|
||||||
room: workspaceId,
|
room: workspaceId,
|
||||||
|
...workspaceOption,
|
||||||
}).register(builtInSchemas);
|
}).register(builtInSchemas);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user