mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
refactor: optimize createWorkspaceInfo
This commit is contained in:
@@ -89,11 +89,11 @@ export class DataCenter {
|
|||||||
'There is no provider. You should add provider first.'
|
'There is no provider. You should add provider first.'
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspaceId = await this._mainProvider.createWorkspaceId(
|
const workspaceInfo = await this._mainProvider.createWorkspaceInfo(
|
||||||
workspaceMeta
|
workspaceMeta
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspace = createBlocksuiteWorkspace(workspaceId);
|
const workspace = createBlocksuiteWorkspace(workspaceInfo.id);
|
||||||
|
|
||||||
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
||||||
return workspace;
|
return workspace;
|
||||||
@@ -292,11 +292,11 @@ export class DataCenter {
|
|||||||
const newProvider = this.providerMap.get(providerId);
|
const newProvider = this.providerMap.get(providerId);
|
||||||
assert(newProvider, `provide '${providerId}' is not registered`);
|
assert(newProvider, `provide '${providerId}' is not registered`);
|
||||||
this._logger(`create ${providerId} workspace: `, workspaceInfo.name);
|
this._logger(`create ${providerId} workspace: `, workspaceInfo.name);
|
||||||
const newWorkspaceId = await newProvider.createWorkspaceId({
|
const newWorkspaceInfo = await newProvider.createWorkspaceInfo({
|
||||||
name: workspaceInfo.name,
|
name: workspaceInfo.name,
|
||||||
avatar: workspaceInfo.avatar,
|
avatar: workspaceInfo.avatar,
|
||||||
});
|
});
|
||||||
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceId);
|
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceInfo.id);
|
||||||
// TODO optimize this function
|
// TODO optimize this function
|
||||||
await newProvider.createWorkspace(newWorkspace, {
|
await newProvider.createWorkspace(newWorkspace, {
|
||||||
name: workspaceInfo.name,
|
name: workspaceInfo.name,
|
||||||
|
|||||||
@@ -263,13 +263,24 @@ export class AffineProvider extends BaseProvider {
|
|||||||
// return workspace;
|
// return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async createWorkspaceId(
|
public override async createWorkspaceInfo(
|
||||||
meta: WorkspaceMeta
|
meta: WorkspaceMeta
|
||||||
): Promise<string> {
|
): Promise<WorkspaceInfo> {
|
||||||
const { id } = await this._apis.createWorkspace(
|
const { id } = await this._apis.createWorkspace(
|
||||||
meta as Required<WorkspaceMeta>
|
meta as Required<WorkspaceMeta>
|
||||||
);
|
);
|
||||||
return id;
|
|
||||||
|
const workspaceInfo: WorkspaceInfo = {
|
||||||
|
name: meta.name,
|
||||||
|
id: id,
|
||||||
|
isPublish: false,
|
||||||
|
avatar: '',
|
||||||
|
owner: await this.getUserInfo(),
|
||||||
|
isLocal: true,
|
||||||
|
memberCount: 1,
|
||||||
|
provider: 'affine',
|
||||||
|
};
|
||||||
|
return workspaceInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async createWorkspace(
|
public override async createWorkspace(
|
||||||
|
|||||||
@@ -28,8 +28,10 @@ export class BaseProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createWorkspaceId(meta: WorkspaceMeta): Promise<string> {
|
public async createWorkspaceInfo(
|
||||||
return uuidv4();
|
meta: WorkspaceMeta
|
||||||
|
): Promise<WorkspaceInfo> {
|
||||||
|
throw new Error(`provider: ${this.id} createWorkspaceInfo Not implemented`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ test.describe.serial('local provider', () => {
|
|||||||
let workspaceId: string | undefined;
|
let workspaceId: string | undefined;
|
||||||
|
|
||||||
test('create workspace', async () => {
|
test('create workspace', async () => {
|
||||||
workspaceId = await provider.createWorkspaceId({
|
const workspaceInfo = await provider.createWorkspaceInfo({
|
||||||
name: workspaceName,
|
name: workspaceName,
|
||||||
avatar: 'avatar-url-test',
|
avatar: 'avatar-url-test',
|
||||||
});
|
});
|
||||||
|
workspaceId = workspaceInfo.id;
|
||||||
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceId);
|
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceId);
|
||||||
await provider.createWorkspace(blocksuiteWorkspace, {
|
await provider.createWorkspace(blocksuiteWorkspace, {
|
||||||
name: workspaceName,
|
name: workspaceName,
|
||||||
|
|||||||
@@ -75,6 +75,22 @@ export class LocalProvider extends BaseProvider {
|
|||||||
this._storeWorkspaces(this._workspaces.list());
|
this._storeWorkspaces(this._workspaces.list());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async createWorkspaceInfo(
|
||||||
|
meta: WorkspaceMeta
|
||||||
|
): Promise<WorkspaceInfo> {
|
||||||
|
const workspaceInfo: WorkspaceInfo = {
|
||||||
|
name: meta.name,
|
||||||
|
id: uuidv4(),
|
||||||
|
isPublish: false,
|
||||||
|
avatar: '',
|
||||||
|
owner: undefined,
|
||||||
|
isLocal: true,
|
||||||
|
memberCount: 1,
|
||||||
|
provider: 'local',
|
||||||
|
};
|
||||||
|
return Promise.resolve(workspaceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
public override async createWorkspace(
|
public override async createWorkspace(
|
||||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||||
meta: WorkspaceMeta
|
meta: WorkspaceMeta
|
||||||
|
|||||||
Reference in New Issue
Block a user