mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 12:52:57 +03:00
refactor: optimize setDefaultAvatar in provider
This commit is contained in:
parent
dcfe8237ef
commit
39f0b1b252
@ -8,9 +8,9 @@ import { storage } from './storage.js';
|
||||
import assert from 'assert';
|
||||
import { WebsocketProvider } from './sync.js';
|
||||
// import { IndexedDBProvider } from '../local/indexeddb';
|
||||
import { getDefaultHeadImgBlob } from '../../utils/index.js';
|
||||
import { getApis } from './apis/index.js';
|
||||
import type { Apis, WorkspaceDetail, Callback } from './apis';
|
||||
import { setDefaultAvatar } from '../utils.js';
|
||||
|
||||
export interface AffineProviderConstructorParams
|
||||
extends ProviderConstructorParams {
|
||||
@ -295,16 +295,8 @@ export class AffineProvider extends BaseProvider {
|
||||
};
|
||||
|
||||
if (!blocksuiteWorkspace.meta.avatar) {
|
||||
// set default avatar
|
||||
const blob = await getDefaultHeadImgBlob(meta.name);
|
||||
const blobStorage = await blocksuiteWorkspace.blobs;
|
||||
assert(blobStorage, 'No blob storage');
|
||||
const blobId = await blobStorage.set(blob);
|
||||
const avatar = await blobStorage.get(blobId);
|
||||
if (avatar) {
|
||||
blocksuiteWorkspace.meta.setAvatar(avatar);
|
||||
workspaceInfo.avatar = avatar;
|
||||
}
|
||||
await setDefaultAvatar(blocksuiteWorkspace);
|
||||
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
|
||||
}
|
||||
this._workspaces.add(workspaceInfo);
|
||||
return blocksuiteWorkspace;
|
||||
|
@ -5,7 +5,7 @@ import { WorkspaceInfo, WorkspaceMeta } from '../../types';
|
||||
import { Workspace as BlocksuiteWorkspace, uuidv4 } from '@blocksuite/store';
|
||||
import { IndexedDBProvider } from './indexeddb.js';
|
||||
import assert from 'assert';
|
||||
import { getDefaultHeadImgBlob } from '../../utils/index.js';
|
||||
import { setDefaultAvatar } from '../utils.js';
|
||||
|
||||
const WORKSPACE_KEY = 'workspaces';
|
||||
|
||||
@ -97,16 +97,8 @@ export class LocalProvider extends BaseProvider {
|
||||
blocksuiteWorkspace.meta.setName(meta.name);
|
||||
|
||||
if (!meta.avatar) {
|
||||
// set default avatar
|
||||
const blob = await getDefaultHeadImgBlob(meta.name);
|
||||
const blobStorage = await blocksuiteWorkspace.blobs;
|
||||
assert(blobStorage, 'No blob storage');
|
||||
const blobId = await blobStorage.set(blob);
|
||||
const avatar = await blobStorage.get(blobId);
|
||||
if (avatar) {
|
||||
blocksuiteWorkspace.meta.setAvatar(avatar);
|
||||
workspaceInfo.avatar = avatar;
|
||||
}
|
||||
await setDefaultAvatar(blocksuiteWorkspace);
|
||||
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
|
||||
}
|
||||
|
||||
this._workspaces.add(workspaceInfo);
|
||||
|
16
packages/data-center/src/provider/utils.ts
Normal file
16
packages/data-center/src/provider/utils.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import assert from 'assert';
|
||||
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
|
||||
import { getDefaultHeadImgBlob } from '../utils/index.js';
|
||||
|
||||
export const setDefaultAvatar = async (
|
||||
blocksuiteWorkspace: BlocksuiteWorkspace
|
||||
) => {
|
||||
const blob = await getDefaultHeadImgBlob(blocksuiteWorkspace.meta.name);
|
||||
const blobStorage = await blocksuiteWorkspace.blobs;
|
||||
assert(blobStorage, 'No blob storage');
|
||||
const blobId = await blobStorage.set(blob);
|
||||
const avatar = await blobStorage.get(blobId);
|
||||
if (avatar) {
|
||||
blocksuiteWorkspace.meta.setAvatar(avatar);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user