fix(editor): missing resource files in exported snapshot zip (#9450)

Closes: [BS-2280](https://linear.app/affine-design/issue/BS-2280/导出-zip-snapshot-丢失-blob)
This commit is contained in:
Saul-Mirone
2024-12-31 05:13:43 +00:00
parent 7aba836dbe
commit 0f03c3fc5e
4 changed files with 48 additions and 8 deletions

View File

@@ -1,4 +1,9 @@
import type { FromSnapshotPayload, SnapshotNode } from '@blocksuite/store';
import type {
BlockSnapshotLeaf,
FromSnapshotPayload,
SnapshotNode,
ToSnapshotPayload,
} from '@blocksuite/store';
import { BaseBlockTransformer } from '@blocksuite/store';
import type { AttachmentBlockProps } from './attachment-model.js';
@@ -14,4 +19,16 @@ export class AttachmentBlockTransformer extends BaseBlockTransformer<AttachmentB
return snapshotRet;
}
override toSnapshot(
snapshot: ToSnapshotPayload<AttachmentBlockProps>
): BlockSnapshotLeaf {
const snapshotRet = super.toSnapshot(snapshot);
const sourceId = snapshot.model.sourceId;
if (sourceId) {
const pathBlobIdMap = snapshot.assets.getPathBlobIdMap();
pathBlobIdMap.set(snapshot.model.id, sourceId);
}
return snapshotRet;
}
}

View File

@@ -1,4 +1,9 @@
import type { FromSnapshotPayload, SnapshotNode } from '@blocksuite/store';
import type {
BlockSnapshotLeaf,
FromSnapshotPayload,
SnapshotNode,
ToSnapshotPayload,
} from '@blocksuite/store';
import { BaseBlockTransformer } from '@blocksuite/store';
import type { ImageBlockProps } from './image-model.js';
@@ -14,4 +19,16 @@ export class ImageBlockTransformer extends BaseBlockTransformer<ImageBlockProps>
return snapshotRet;
}
override toSnapshot(
snapshot: ToSnapshotPayload<ImageBlockProps>
): BlockSnapshotLeaf {
const snapshotRet = super.toSnapshot(snapshot);
const sourceId = snapshot.model.sourceId;
if (sourceId) {
const pathBlobIdMap = snapshot.assets.getPathBlobIdMap();
pathBlobIdMap.set(snapshot.model.id, sourceId);
}
return snapshotRet;
}
}