mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-05 11:35:34 +08:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,13 +23,19 @@ async function exportDocs(collection: DocCollection, docs: Doc[]) {
|
||||
);
|
||||
|
||||
const assets = zip.folder('assets');
|
||||
const pathBlobIdMap = job.assetsManager.getPathBlobIdMap();
|
||||
const assetsMap = job.assets;
|
||||
|
||||
for (const [id, blob] of assetsMap) {
|
||||
const ext = getAssetName(assetsMap, id).split('.').at(-1);
|
||||
const name = `${id}.${ext}`;
|
||||
await assets.file(name, blob);
|
||||
}
|
||||
await Promise.all(
|
||||
Array.from(pathBlobIdMap.values()).map(async blobId => {
|
||||
await job.assetsManager.readFromBlob(blobId);
|
||||
const ext = getAssetName(assetsMap, blobId).split('.').at(-1);
|
||||
const blob = assetsMap.get(blobId);
|
||||
if (blob) {
|
||||
await assets.file(`${blobId}.${ext}`, blob);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
const downloadBlob = await zip.generate();
|
||||
return download(downloadBlob, `${collection.id}.bs.zip`);
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { DraftModel } from './draft.js';
|
||||
import { fromJSON, toJSON } from './json.js';
|
||||
import type { BlockSnapshot } from './type.js';
|
||||
|
||||
type BlockSnapshotLeaf = Pick<
|
||||
export type BlockSnapshotLeaf = Pick<
|
||||
BlockSnapshot,
|
||||
'id' | 'flavour' | 'props' | 'version'
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user