mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
feat(core): preview template & snapshot import (#8193)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user