feat(nbstore): add blob sync (#8996)

This commit is contained in:
EYHN
2024-12-07 08:05:03 +00:00
parent f54f6e88cb
commit 7225f59138
7 changed files with 214 additions and 19 deletions
+24 -8
View File
@@ -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);
}
})(),
]);
}
}