mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
feat(nbstore): add blob sync (#8996)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { DocStorage, SpaceStorage } from '../storage';
|
||||
import type { BlobStorage, DocStorage, SpaceStorage } from '../storage';
|
||||
import { BlobSyncEngine } from './blob';
|
||||
import { DocSyncEngine } from './doc';
|
||||
|
||||
export class SyncEngine {
|
||||
@@ -9,15 +10,30 @@ export class SyncEngine {
|
||||
|
||||
async run(signal?: AbortSignal) {
|
||||
const doc = this.local.tryGet('doc');
|
||||
const blob = this.local.tryGet('blob');
|
||||
const sync = this.local.tryGet('sync');
|
||||
|
||||
if (doc && sync) {
|
||||
const peerDocs = this.peers
|
||||
.map(peer => peer.tryGet('doc'))
|
||||
.filter((v): v is DocStorage => !!v);
|
||||
await Promise.allSettled([
|
||||
(async () => {
|
||||
if (doc && sync) {
|
||||
const peerDocs = this.peers
|
||||
.map(peer => peer.tryGet('doc'))
|
||||
.filter((v): v is DocStorage => !!v);
|
||||
|
||||
const engine = new DocSyncEngine(doc, sync, peerDocs);
|
||||
await engine.run(signal);
|
||||
}
|
||||
const engine = new DocSyncEngine(doc, sync, peerDocs);
|
||||
await engine.run(signal);
|
||||
}
|
||||
})(),
|
||||
(async () => {
|
||||
if (blob) {
|
||||
const peerBlobs = this.peers
|
||||
.map(peer => peer.tryGet('blob'))
|
||||
.filter((v): v is BlobStorage => !!v);
|
||||
|
||||
const engine = new BlobSyncEngine(blob, peerBlobs);
|
||||
await engine.run(signal);
|
||||
}
|
||||
})(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user