mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-01 17:15:36 +03:00
Merge pull request #769 from toeverything/bugfix/upload-blob
fix: add token and api to blocksuitWorkspace
This commit is contained in:
commit
4a963321b1
@ -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,6 @@ import { getLogger } from './logger';
|
||||
import { createBlocksuiteWorkspace } from './utils/index.js';
|
||||
import { MessageCenter } from './message';
|
||||
import { WorkspaceUnit } from './workspace-unit';
|
||||
|
||||
/**
|
||||
* @class DataCenter
|
||||
* @classdesc Data center is made for managing different providers for business
|
||||
@ -116,12 +118,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 +164,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: provider.getToken() }[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 +188,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({
|
||||
|
@ -360,6 +360,10 @@ export class AffineProvider extends BaseProvider {
|
||||
await this._apis.updateWorkspace({ id, public: isPublish });
|
||||
}
|
||||
|
||||
public override getToken(): string {
|
||||
return this._apis.token.token;
|
||||
}
|
||||
|
||||
public override async getUserByEmail(
|
||||
workspace_id: string,
|
||||
email: string
|
||||
@ -393,7 +397,6 @@ export class AffineProvider extends BaseProvider {
|
||||
provider: this.id,
|
||||
syncMode: 'core',
|
||||
});
|
||||
|
||||
await migrateBlobDB(workspaceUnit.id, id);
|
||||
|
||||
const blocksuiteWorkspace = createBlocksuiteWorkspace(id);
|
||||
|
@ -66,7 +66,7 @@ export const migrateBlobDB = async (
|
||||
newWorkspaceId: string
|
||||
) => {
|
||||
const oldDB = getDatabase('blob', oldWorkspaceId);
|
||||
const oldPendingDB = getDatabase<PendingTask>('pending', newWorkspaceId);
|
||||
const oldPendingDB = getDatabase<PendingTask>('pending', oldWorkspaceId);
|
||||
|
||||
const newDB = getDatabase('blob', newWorkspaceId);
|
||||
const newPendingDB = getDatabase<PendingTask>('pending', newWorkspaceId);
|
||||
|
@ -64,6 +64,10 @@ export class BaseProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
public getToken(): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* warp workspace with provider functions
|
||||
* @param workspace
|
||||
|
@ -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