mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 20:52:44 +03:00
feat: fix type problem
This commit is contained in:
parent
84bea54916
commit
2ff46fa831
@ -2,11 +2,13 @@ import { describe, test, expect } from 'vitest';
|
|||||||
import { Workspaces } from '../../workspaces';
|
import { Workspaces } from '../../workspaces';
|
||||||
import { LocalProvider } from './local';
|
import { LocalProvider } from './local';
|
||||||
import 'fake-indexeddb/auto';
|
import 'fake-indexeddb/auto';
|
||||||
|
import { BlobStorage } from '@blocksuite/store';
|
||||||
|
|
||||||
describe('local provider', () => {
|
describe('local provider', () => {
|
||||||
const workspaces = new Workspaces();
|
const workspaces = new Workspaces();
|
||||||
const provider = new LocalProvider({
|
const provider = new LocalProvider({
|
||||||
workspaces: workspaces.createScope(),
|
workspaces: workspaces.createScope(),
|
||||||
|
blobs: new BlobStorage(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const workspaceName = 'workspace-test';
|
const workspaceName = 'workspace-test';
|
||||||
@ -27,6 +29,7 @@ describe('local provider', () => {
|
|||||||
const workspaces1 = new Workspaces();
|
const workspaces1 = new Workspaces();
|
||||||
const provider1 = new LocalProvider({
|
const provider1 = new LocalProvider({
|
||||||
workspaces: workspaces1.createScope(),
|
workspaces: workspaces1.createScope(),
|
||||||
|
blobs: new BlobStorage(),
|
||||||
});
|
});
|
||||||
await provider1.loadWorkspaces();
|
await provider1.loadWorkspaces();
|
||||||
expect(workspaces1.workspaces.length).toEqual(1);
|
expect(workspaces1.workspaces.length).toEqual(1);
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { LocalProvider } from '../local/index.js';
|
|
||||||
import { WebsocketProvider } from './sync.js';
|
|
||||||
|
|
||||||
export class SelfHostedProvider extends LocalProvider {
|
|
||||||
static id = 'selfhosted';
|
|
||||||
private _ws?: WebsocketProvider;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
async destroy() {
|
|
||||||
this._ws?.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
async initData() {
|
|
||||||
const databases = await indexedDB.databases();
|
|
||||||
await super.initData(
|
|
||||||
// set locally to true if exists a same name db
|
|
||||||
databases
|
|
||||||
.map(db => db.name)
|
|
||||||
.filter(v => v)
|
|
||||||
.includes(this._workspace.room)
|
|
||||||
);
|
|
||||||
|
|
||||||
const workspace = this._workspace;
|
|
||||||
const doc = workspace.doc;
|
|
||||||
|
|
||||||
if (workspace.room) {
|
|
||||||
try {
|
|
||||||
// Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
|
|
||||||
this._ws = new WebsocketProvider(this.host, workspace.room, doc);
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
|
||||||
// TODO: synced will also be triggered on reconnection after losing sync
|
|
||||||
// There needs to be an event mechanism to emit the synchronization state to the upper layer
|
|
||||||
assert(this._ws);
|
|
||||||
this._ws.once('synced', () => resolve());
|
|
||||||
this._ws.once('lost-connection', () => resolve());
|
|
||||||
this._ws.once('connection-error', () => reject());
|
|
||||||
});
|
|
||||||
this._signals.listAdd.emit({
|
|
||||||
workspace: workspace.room,
|
|
||||||
provider: this.id,
|
|
||||||
locally: true,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
this._logger('Failed to init cloud workspace', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if after update, the space:meta is empty
|
|
||||||
// then we need to get map with doc
|
|
||||||
// just a workaround for yjs
|
|
||||||
doc.getMap('space:meta');
|
|
||||||
}
|
|
||||||
|
|
||||||
private get host() {
|
|
||||||
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
||||||
return `${protocol}//${location.host}/collaboration/`;
|
|
||||||
}
|
|
||||||
}
|
|
63
packages/data-center/src/provider/selfhosted/index.ts.bk
Normal file
63
packages/data-center/src/provider/selfhosted/index.ts.bk
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// import assert from 'assert';
|
||||||
|
|
||||||
|
// import { LocalProvider } from '../local/index.js';
|
||||||
|
// import { WebsocketProvider } from './sync.js';
|
||||||
|
|
||||||
|
// export class SelfHostedProvider extends LocalProvider {
|
||||||
|
// static id = 'selfhosted';
|
||||||
|
// private _ws?: WebsocketProvider;
|
||||||
|
|
||||||
|
// constructor() {
|
||||||
|
// super();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async destroy() {
|
||||||
|
// this._ws?.disconnect();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async initData() {
|
||||||
|
// const databases = await indexedDB.databases();
|
||||||
|
// await super.initData(
|
||||||
|
// // set locally to true if exists a same name db
|
||||||
|
// databases
|
||||||
|
// .map(db => db.name)
|
||||||
|
// .filter(v => v)
|
||||||
|
// .includes(this._workspace.room)
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const workspace = this._workspace;
|
||||||
|
// const doc = workspace.doc;
|
||||||
|
|
||||||
|
// if (workspace.room) {
|
||||||
|
// try {
|
||||||
|
// // Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
|
||||||
|
// this._ws = new WebsocketProvider(this.host, workspace.room, doc);
|
||||||
|
// await new Promise<void>((resolve, reject) => {
|
||||||
|
// // TODO: synced will also be triggered on reconnection after losing sync
|
||||||
|
// // There needs to be an event mechanism to emit the synchronization state to the upper layer
|
||||||
|
// assert(this._ws);
|
||||||
|
// this._ws.once('synced', () => resolve());
|
||||||
|
// this._ws.once('lost-connection', () => resolve());
|
||||||
|
// this._ws.once('connection-error', () => reject());
|
||||||
|
// });
|
||||||
|
// this._signals.listAdd.emit({
|
||||||
|
// workspace: workspace.room,
|
||||||
|
// provider: this.id,
|
||||||
|
// locally: true,
|
||||||
|
// });
|
||||||
|
// } catch (e) {
|
||||||
|
// this._logger('Failed to init cloud workspace', e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // if after update, the space:meta is empty
|
||||||
|
// // then we need to get map with doc
|
||||||
|
// // just a workaround for yjs
|
||||||
|
// doc.getMap('space:meta');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private get host() {
|
||||||
|
// const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
|
// return `${protocol}//${location.host}/collaboration/`;
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user