mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
fix: first binary on y-indexeddb (#1972)
This commit is contained in:
22
packages/y-indexeddb/src/utils.ts
Normal file
22
packages/y-indexeddb/src/utils.ts
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user