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-Type", "application/zip");
res.setHeader( res.setHeader(
"Content-Disposition", "Content-Disposition",
`attachment; filename="excalidraw-drawings-${new Date().toISOString().split("T")[0] `attachment; filename="excalidraw-drawings-${new Date().toISOString().split("T")[0]}.zip"`,
}.zip"`
); );
const archive = archiver("zip", { zlib: { level: 9 } }); const archive = archiver("zip", { zlib: { level: 9 } });
@@ -1396,6 +1395,9 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
type DrawingExportItem = { type DrawingExportItem = {
name: string; name: string;
data: { data: {
type: "excalidraw";
version: 2;
source: string;
elements: unknown[]; elements: unknown[];
appState: Record<string, unknown>; appState: Record<string, unknown>;
files: 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 drawingsByCollection: Record<string, DrawingExportItem[]> = {};
const exportSource = `${req.protocol}://${req.get("host")}`;
drawings.forEach((drawing: DrawingWithCollection) => { drawings.forEach((drawing: DrawingWithCollection) => {
const collectionName = drawing.collection?.name || "Unorganized"; const collectionName = drawing.collection?.name || "Unorganized";
@@ -1411,6 +1414,9 @@ app.get("/export/json", requireAuth, asyncHandler(async (req, res, next) => {
} }
const drawingData = { const drawingData = {
type: "excalidraw" as const,
version: 2 as const,
source: exportSource,
elements: JSON.parse(drawing.elements) as unknown[], elements: JSON.parse(drawing.elements) as unknown[],
appState: JSON.parse(drawing.appState) as Record<string, unknown>, appState: JSON.parse(drawing.appState) as Record<string, unknown>,
files: JSON.parse(drawing.files || "{}") 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( Object.entries(drawingsByCollection).forEach(
([collectionName, collectionDrawings]) => { ([collectionName, collectionDrawings]) => {
const folderName = collectionName.replace(/[<>:"/\\|?*]/g, "_"); const folderName = collectionName.replace(/[<>:"/\\|?*]/g, "_");
collectionDrawings.forEach((drawing, index) => { collectionDrawings.forEach((drawing) => {
const fileName = `${drawing.name.replace( const fileName = `${drawing.name.replace(/[<>:"/\\|?*]/g, "_")}.excalidraw`;
/[<>:"/\\|?*]/g,
"_"
)}.excalidraw`;
const filePath = `${folderName}/${fileName}`; const filePath = `${folderName}/${fileName}`;
archive.append(JSON.stringify(drawing.data, null, 2), { archive.append(JSON.stringify(drawing.data, null, 2), {
name: filePath, name: filePath,
}); });
}); });
} },
); );
const readmeContent = `ExcaliDash Export const readmeContent = `ExcaliDash Export