mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-06 08:50:50 +08:00
feat(core): use zip snapshot for onboarding page (#6495)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useWorkspace } from '@affine/core/hooks/use-workspace';
|
||||
import { ZipTransformer } from '@blocksuite/blocks';
|
||||
import type { Workspace } from '@toeverything/infra';
|
||||
import {
|
||||
ServiceProviderContext,
|
||||
@@ -28,6 +29,8 @@ declare global {
|
||||
*/
|
||||
// eslint-disable-next-line no-var
|
||||
var currentWorkspace: Workspace | undefined;
|
||||
// eslint-disable-next-line no-var
|
||||
var exportWorkspaceSnapshot: () => Promise<void>;
|
||||
interface WindowEventMap {
|
||||
'affine:workspace:change': CustomEvent<{ id: string }>;
|
||||
}
|
||||
@@ -60,6 +63,19 @@ export const Component = (): ReactElement => {
|
||||
|
||||
// for debug purpose
|
||||
window.currentWorkspace = workspace;
|
||||
window.exportWorkspaceSnapshot = async () => {
|
||||
const zip = await ZipTransformer.exportDocs(
|
||||
workspace.docCollection,
|
||||
Array.from(workspace.docCollection.docs.values())
|
||||
);
|
||||
const url = URL.createObjectURL(zip);
|
||||
// download url
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${workspace.docCollection.meta.name}.zip`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('affine:workspace:change', {
|
||||
detail: {
|
||||
|
||||
Reference in New Issue
Block a user