mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 03:54:00 +03:00
fix: add token and api to blocksuitWorkspace
This commit is contained in:
parent
6cc39171eb
commit
82c261767f
@ -1,6 +1,9 @@
|
||||
import { WorkspaceUnitCollection } from './workspace-unit-collection.js';
|
||||
import type { WorkspaceUnitCollectionChangeEvent } from './workspace-unit-collection';
|
||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||
import {
|
||||
StoreOptions,
|
||||
Workspace as BlocksuiteWorkspace,
|
||||
} from '@blocksuite/store';
|
||||
import type {
|
||||
BaseProvider,
|
||||
CreateWorkspaceInfoParams,
|
||||
@ -14,7 +17,7 @@ import { getLogger } from './logger';
|
||||
import { createBlocksuiteWorkspace } from './utils/index.js';
|
||||
import { MessageCenter } from './message';
|
||||
import { WorkspaceUnit } from './workspace-unit';
|
||||
|
||||
import { token } from './provider/affine/apis/token';
|
||||
/**
|
||||
* @class DataCenter
|
||||
* @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
|
||||
* @param {string} workspaceId workspace id
|
||||
*/
|
||||
private _getBlocksuiteWorkspace(workspaceId: string) {
|
||||
private _getBlocksuiteWorkspace(workspaceId: string, params: StoreOptions) {
|
||||
// const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||
// assert(workspaceInfo, 'Workspace not found');
|
||||
return (
|
||||
// this._workspaceInstances.get(workspaceId) ||
|
||||
createBlocksuiteWorkspace(workspaceId)
|
||||
createBlocksuiteWorkspace(workspaceId, params)
|
||||
);
|
||||
}
|
||||
|
||||
@ -162,7 +165,15 @@ export class DataCenter {
|
||||
const provider = this.providerMap.get(workspaceUnit.provider);
|
||||
assert(provider, `provide '${workspaceUnit.provider}' is not registered`);
|
||||
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);
|
||||
await provider.warpWorkspace(workspace);
|
||||
this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => {
|
||||
@ -178,7 +189,7 @@ export class DataCenter {
|
||||
// FIXME: hard code for public workspace
|
||||
const provider = this.providerMap.get('affine');
|
||||
assert(provider);
|
||||
const blocksuiteWorkspace = this._getBlocksuiteWorkspace(workspaceId);
|
||||
const blocksuiteWorkspace = this._getBlocksuiteWorkspace(workspaceId, {});
|
||||
await provider.loadPublicWorkspace(blocksuiteWorkspace);
|
||||
|
||||
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';
|
||||
|
||||
export const createBlocksuiteWorkspace = (workspaceId: string) => {
|
||||
export const createBlocksuiteWorkspace = (
|
||||
workspaceId: string,
|
||||
workspaceOption?: StoreOptions
|
||||
) => {
|
||||
return new BlocksuiteWorkspace({
|
||||
room: workspaceId,
|
||||
...workspaceOption,
|
||||
}).register(builtInSchemas);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user