diff --git a/packages/data-center/src/provider/local/local.spec.ts b/packages/data-center/src/provider/local/local.spec.ts index 442263c070..72803370ba 100644 --- a/packages/data-center/src/provider/local/local.spec.ts +++ b/packages/data-center/src/provider/local/local.spec.ts @@ -2,11 +2,13 @@ import { describe, test, expect } from 'vitest'; import { Workspaces } from '../../workspaces'; import { LocalProvider } from './local'; import 'fake-indexeddb/auto'; +import { BlobStorage } from '@blocksuite/store'; describe('local provider', () => { const workspaces = new Workspaces(); const provider = new LocalProvider({ workspaces: workspaces.createScope(), + blobs: new BlobStorage(), }); const workspaceName = 'workspace-test'; @@ -27,6 +29,7 @@ describe('local provider', () => { const workspaces1 = new Workspaces(); const provider1 = new LocalProvider({ workspaces: workspaces1.createScope(), + blobs: new BlobStorage(), }); await provider1.loadWorkspaces(); expect(workspaces1.workspaces.length).toEqual(1); diff --git a/packages/data-center/src/provider/selfhosted/index.ts b/packages/data-center/src/provider/selfhosted/index.ts deleted file mode 100644 index 48632480ef..0000000000 --- a/packages/data-center/src/provider/selfhosted/index.ts +++ /dev/null @@ -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((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/`; - } -} diff --git a/packages/data-center/src/provider/selfhosted/index.ts.bk b/packages/data-center/src/provider/selfhosted/index.ts.bk new file mode 100644 index 0000000000..c74a13cf81 --- /dev/null +++ b/packages/data-center/src/provider/selfhosted/index.ts.bk @@ -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((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/`; +// } +// }