feat(core): preview template & snapshot import (#8193)

This commit is contained in:
EYHN
2024-09-11 07:11:33 +00:00
parent 52d9569f47
commit 8c191e6baa
9 changed files with 123 additions and 29 deletions
@@ -1,4 +1,5 @@
import type { WorkspaceFlavour } from '@affine/env/workspace';
import { ZipTransformer } from '@blocksuite/blocks';
import type { WorkspaceMetadata, WorkspacesService } from '@toeverything/infra';
import { Service } from '@toeverything/infra';
@@ -16,13 +17,18 @@ export class ImportTemplateService extends Service {
metadata: workspaceMetadata,
});
await workspace.engine.waitForRootDocReady();
const newDoc = workspace.docCollection.createDoc({});
await workspace.engine.doc.storage.behavior.doc.set(
newDoc.spaceDoc.guid,
docBinary
const [importedDoc] = await ZipTransformer.importDocs(
workspace.docCollection,
new Blob([docBinary], {
type: 'application/zip',
})
);
disposeWorkspace();
return newDoc.id;
if (importedDoc) {
disposeWorkspace();
return importedDoc.id;
} else {
throw new Error('Failed to import doc');
}
}
async importToNewWorkspace(
@@ -7,9 +7,12 @@ export class TemplateDownloaderStore extends Store {
super();
}
async download(workspaceId: string, docId: string) {
async download(
/* not support workspaceid for now */ _workspaceId: string,
docId: string
) {
const response = await this.fetchService.fetch(
`/api/workspaces/${workspaceId}/docs/${docId}`,
`https://affine.pro/templates/snapshots/${docId}.zip `,
{
priority: 'high',
} as any