fix: first binary on y-indexeddb (#1972)

This commit is contained in:
Himself65
2023-04-16 21:33:54 -05:00
committed by GitHub
parent 4cb6b8fdc8
commit 9c517907eb
4 changed files with 139 additions and 60 deletions

View File

@@ -0,0 +1,22 @@
import { openDB } from 'idb';
import { mergeUpdates } from 'yjs';
import type { BlockSuiteBinaryDB, UpdateMessage } from './shared';
import { dbVersion, DEFAULT_DB_NAME, upgradeDB } from './shared';
export async function downloadBinary(
id: string,
dbName = DEFAULT_DB_NAME
): Promise<UpdateMessage['update']> {
const dbPromise = openDB<BlockSuiteBinaryDB>(dbName, dbVersion, {
upgrade: upgradeDB,
});
const db = await dbPromise;
const t = db.transaction('workspace', 'readonly').objectStore('workspace');
const doc = await t.get(id);
if (!doc) {
return new Uint8Array(0);
} else {
return mergeUpdates(doc.updates.map(({ update }) => update));
}
}