mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00: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.'
|
||||
);
|
||||
|
||||
const workspaceId = await this._mainProvider.createWorkspaceId(
|
||||
const workspaceInfo = await this._mainProvider.createWorkspaceInfo(
|
||||
workspaceMeta
|
||||
);
|
||||
|
||||
const workspace = createBlocksuiteWorkspace(workspaceId);
|
||||
const workspace = createBlocksuiteWorkspace(workspaceInfo.id);
|
||||
|
||||
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
||||
return workspace;
|
||||
@@ -292,11 +292,11 @@ export class DataCenter {
|
||||
const newProvider = this.providerMap.get(providerId);
|
||||
assert(newProvider, `provide '${providerId}' is not registered`);
|
||||
this._logger(`create ${providerId} workspace: `, workspaceInfo.name);
|
||||
const newWorkspaceId = await newProvider.createWorkspaceId({
|
||||
const newWorkspaceInfo = await newProvider.createWorkspaceInfo({
|
||||
name: workspaceInfo.name,
|
||||
avatar: workspaceInfo.avatar,
|
||||
});
|
||||
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceId);
|
||||
const newWorkspace = createBlocksuiteWorkspace(newWorkspaceInfo.id);
|
||||
// TODO optimize this function
|
||||
await newProvider.createWorkspace(newWorkspace, {
|
||||
name: workspaceInfo.name,
|
||||
|
||||
@@ -263,13 +263,24 @@ export class AffineProvider extends BaseProvider {
|
||||
// return workspace;
|
||||
}
|
||||
|
||||
public override async createWorkspaceId(
|
||||
public override async createWorkspaceInfo(
|
||||
meta: WorkspaceMeta
|
||||
): Promise<string> {
|
||||
): Promise<WorkspaceInfo> {
|
||||
const { id } = await this._apis.createWorkspace(
|
||||
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(
|
||||
|
||||
@@ -28,8 +28,10 @@ export class BaseProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
public async createWorkspaceId(meta: WorkspaceMeta): Promise<string> {
|
||||
return uuidv4();
|
||||
public async createWorkspaceInfo(
|
||||
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;
|
||||
|
||||
test('create workspace', async () => {
|
||||
workspaceId = await provider.createWorkspaceId({
|
||||
const workspaceInfo = await provider.createWorkspaceInfo({
|
||||
name: workspaceName,
|
||||
avatar: 'avatar-url-test',
|
||||
});
|
||||
workspaceId = workspaceInfo.id;
|
||||
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceId);
|
||||
await provider.createWorkspace(blocksuiteWorkspace, {
|
||||
name: workspaceName,
|
||||
|
||||
@@ -75,6 +75,22 @@ export class LocalProvider extends BaseProvider {
|
||||
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(
|
||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||
meta: WorkspaceMeta
|
||||
|
||||
Reference in New Issue
Block a user