mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
fix: create workspace optimize
This commit is contained in:
@@ -128,20 +128,20 @@ export class DataCenter {
|
|||||||
* login to all providers, it will default run all auth ,
|
* login to all providers, it will default run all auth ,
|
||||||
* maybe need a params to control which provider to auth
|
* maybe need a params to control which provider to auth
|
||||||
*/
|
*/
|
||||||
public async login() {
|
public async login(providerId = 'affine') {
|
||||||
this.providers.forEach(p => {
|
const provider = this.providerMap.get(providerId);
|
||||||
// TODO: may be add params of auth
|
assert(provider, `provide '${providerId}' is not registered`);
|
||||||
p.auth();
|
await provider.auth();
|
||||||
});
|
provider.loadWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logout from all providers
|
* logout from all providers
|
||||||
*/
|
*/
|
||||||
public async logout() {
|
public async logout(providerId = 'affine') {
|
||||||
this.providers.forEach(p => {
|
const provider = this.providerMap.get(providerId);
|
||||||
p.logout();
|
assert(provider, `provide '${providerId}' is not registered`);
|
||||||
});
|
await provider.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ export class AffineProvider extends BaseProvider {
|
|||||||
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
||||||
super(params);
|
super(params);
|
||||||
this._apis = apis || getApis();
|
this._apis = apis || getApis();
|
||||||
|
this.init().then(() => {
|
||||||
|
if (this._apis.token.isLogin) {
|
||||||
|
this.loadWorkspaces();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
override async init() {
|
override async init() {
|
||||||
@@ -78,7 +83,12 @@ export class AffineProvider extends BaseProvider {
|
|||||||
|
|
||||||
let ws = this._wsMap.get(room);
|
let ws = this._wsMap.get(room);
|
||||||
if (!ws) {
|
if (!ws) {
|
||||||
ws = new WebsocketProvider('/', room, doc);
|
const wsUrl = `${
|
||||||
|
window.location.protocol === 'https:' ? 'wss' : 'ws'
|
||||||
|
}://${window.location.host}/api/sync/`;
|
||||||
|
ws = new WebsocketProvider(wsUrl, room, doc, {
|
||||||
|
params: { token: this._apis.token.refresh },
|
||||||
|
});
|
||||||
this._wsMap.set(room, ws);
|
this._wsMap.set(room, ws);
|
||||||
}
|
}
|
||||||
// close all websocket links
|
// close all websocket links
|
||||||
@@ -186,8 +196,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const user = await this._apis.signInWithGoogle?.();
|
await this._apis.signInWithGoogle?.();
|
||||||
assert(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async getUserInfo(): Promise<User | undefined> {
|
public override async getUserInfo(): Promise<User | undefined> {
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ export const getAuthorizer = () => {
|
|||||||
|
|
||||||
return [signInWithGoogle, onAuthStateChanged] as const;
|
return [signInWithGoogle, onAuthStateChanged] as const;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
getLogger('getAuthorizer')(e);
|
||||||
return [] as const;
|
return [] as const;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ export class LocalProvider extends BaseProvider {
|
|||||||
|
|
||||||
this.linkLocal(blocksuiteWorkspace);
|
this.linkLocal(blocksuiteWorkspace);
|
||||||
blocksuiteWorkspace.meta.setName(meta.name);
|
blocksuiteWorkspace.meta.setName(meta.name);
|
||||||
|
|
||||||
if (!meta.avatar) {
|
if (!meta.avatar) {
|
||||||
// set default avatar
|
// set default avatar
|
||||||
const blob = await getDefaultHeadImgBlob(meta.name);
|
const blob = await getDefaultHeadImgBlob(meta.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user