fix: first binary on y-indexeddb (#1972)
This commit is contained in:
1 parent
4cb6b8fdc8
commit
9c517907eb
4 files changed
+139
-60
No files matched your search
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user