fix(export): include excalidraw source/version metadata

This commit is contained in:
Zimeng Xiong
2026-02-06 00:26:31 -08:00
parent 75a1f11a96
commit 7a54123e93
+11 -8
View File
@@ -1376,8 +1376,7 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
res.setHeader("Content-Type", "application/zip");
res.setHeader(
"Content-Disposition",
`attachment; filename="excalidraw-drawings-${new Date().toISOString().split("T")[0]
}.zip"`
`attachment; filename="excalidraw-drawings-${new Date().toISOString().split("T")[0]}.zip"`,
);
const archive = archiver("zip", { zlib: { level: 9 } });
@@ -1396,6 +1395,9 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
type DrawingExportItem = {
name: string;
data: {
type: "excalidraw";
version: 2;
source: string;
elements: unknown[];
appState: Record<string, unknown>;
files: Record<string, unknown>;
@@ -1403,6 +1405,7 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
};
const drawingsByCollection: Record<string, DrawingExportItem[]> = {};
const exportSource = `${req.protocol}://${req.get("host")}`;
drawings.forEach((drawing: DrawingWithCollection) => {
const collectionName = drawing.collection?.name || "Unorganized";
@@ -1411,6 +1414,9 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
}
const drawingData = {
type: "excalidraw" as const,
version: 2 as const,
source: exportSource,
elements: JSON.parse(drawing.elements) as unknown[],
appState: JSON.parse(drawing.appState) as Record<string, unknown>,
files: JSON.parse(drawing.files || "{}") as Record<string, unknown>,
@@ -1425,18 +1431,15 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
Object.entries(drawingsByCollection).forEach(
([collectionName, collectionDrawings]) => {
const folderName = collectionName.replace(/[<>:"/\\|?*]/g, "_");
collectionDrawings.forEach((drawing, index) => {
const fileName = `${drawing.name.replace(
/[<>:"/\\|?*]/g,
"_"
)}.excalidraw`;
collectionDrawings.forEach((drawing) => {
const fileName = `${drawing.name.replace(/[<>:"/\\|?*]/g, "_")}.excalidraw`;
const filePath = `${folderName}/${fileName}`;
archive.append(JSON.stringify(drawing.data, null, 2), {
name: filePath,
});
});
}
},
);
const readmeContent = `ExcaliDash Export