feat(canvas): 实现画布项目导出为ZIP压缩包功能

- 新增 canvas-export 工具模块,支持将画布项目打包为 ZIP 文件
- 修改导出功能,将原来的 JSON 格式改为 ZIP 压缩包,包含 projects.json 和相关媒体文件
- 添加对 fflate 库的依赖用于 ZIP 文件处理
- 更新画布库页面,支持多选项目批量导出
- 修改导入功能以支持读取新版 ZIP 格式的画布项目
- 新增 zip 处理工具库,封装压缩和解压操作
- 扩展文件存储服务,添加获取和设置 Blob 对象的方法
- 更新 AGENTS.md 文档,添加标准库使用原则
This commit is contained in:
HouYunFei
2026-05-26 13:00:16 +08:00
parent 567ead89b1
commit 1fb782819b
11 changed files with 160 additions and 28 deletions
+21
View File
@@ -0,0 +1,21 @@
import { unzipSync, zipSync } from "fflate";
type ZipFile = {
name: string;
data: BlobPart;
};
export async function createZip(files: ZipFile[]) {
const entries = await Promise.all(
files.map(async (file) => {
const data = new Uint8Array(await new Blob([file.data]).arrayBuffer());
return [file.name, data] as const;
}),
);
return new Blob([zipSync(Object.fromEntries(entries), { level: 0 })], { type: "application/zip" });
}
export async function readZip(file: Blob) {
const entries = unzipSync(new Uint8Array(await file.arrayBuffer()));
return new Map(Object.entries(entries).map(([name, data]) => [name, new Blob([data])]));
}