feat: create workspace from loading existing exported file (#2122)

Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
Peng Xiao
2023-05-09 15:30:01 +08:00
committed by GitHub
parent 5432aae85c
commit 7c2574b1ca
93 changed files with 2999 additions and 1406 deletions

View File

@@ -1,24 +1,28 @@
import type { BlobStorage } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
export const createSQLiteStorage = (workspaceId: string): BlobStorage => {
const apis = window.apis;
assertExists(apis);
return {
crud: {
get: async (key: string) => {
const buffer = await window.apis.db.getBlob(workspaceId, key);
const buffer = await apis.db.getBlob(workspaceId, key);
return buffer ? new Blob([buffer]) : null;
},
set: async (key: string, value: Blob) => {
return window.apis.db.addBlob(
await apis.db.addBlob(
workspaceId,
key,
new Uint8Array(await value.arrayBuffer())
);
return key;
},
delete: async (key: string) => {
return window.apis.db.deleteBlob(workspaceId, key);
return apis.db.deleteBlob(workspaceId, key);
},
list: async () => {
return window.apis.db.getPersistedBlobs(workspaceId);
return apis.db.getPersistedBlobs(workspaceId);
},
},
};