Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: add importWorkspaceSnapshot for testing (#7224)

pengx175307a55f8a73
diff --git a/packages/frontend/core/src/pages/workspace/index.tsx b/packages/frontend/core/src/pages/workspace/index.tsx
index feb65ef0b1..093b57952c 100644
--- a/packages/frontend/core/src/pages/workspace/index.tsx
+++ b/packages/frontend/core/src/pages/workspace/index.tsx
@@ -28,7 +28,9 @@ declare global {
// eslint-disable-next-line no-var
var currentWorkspace: Workspace | undefined;
// eslint-disable-next-line no-var
- var exportWorkspaceSnapshot: () => Promise<void>;
+ var exportWorkspaceSnapshot: (docs?: string[]) => Promise<void>;
+ // eslint-disable-next-line no-var
+ var importWorkspaceSnapshot: () => Promise<void>;
interface WindowEventMap {
'affine:workspace:change': CustomEvent<{ id: string }>;
}
@@ -81,6 +83,29 @@ export const Component = (): ReactElement => {
a.click();
URL.revokeObjectURL(url);
};
+ window.importWorkspaceSnapshot = async () => {
+ const input = document.createElement('input');
+ input.type = 'file';
+ input.accept = '.zip';
+ input.onchange = async () => {
+ if (input.files && input.files.length > 0) {
+ const file = input.files[0];
+ const blob = new Blob([file], { type: 'application/zip' });
+ const newDocs = await ZipTransformer.importDocs(
+ workspace.docCollection,
+ blob
+ );
+ console.log(
+ 'imported docs',
+ newDocs.map(doc => ({
+ id: doc.id,
+ title: doc.meta?.title,
+ }))
+ );
+ }
+ };
+ input.click();
+ };
localStorage.setItem('last_workspace_id', workspace.id);
globalContext.workspaceId.set(workspace.id);
return () => {