fix: file save timing out with big file sizes (#7649)

This commit is contained in:
David Luzar 2024-02-03 11:53:35 +01:00 committed by GitHub
parent 0c3dffb082
commit d67eaa8710
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View file

@ -76,7 +76,7 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
}; };
export const fileSave = ( export const fileSave = (
blob: Blob, blob: Blob | Promise<Blob>,
opts: { opts: {
/** supply without the extension */ /** supply without the extension */
name: string; name: string;

View file

@ -100,7 +100,7 @@ export const exportCanvas = async (
throw new Error(t("alerts.cannotExportEmptyCanvas")); throw new Error(t("alerts.cannotExportEmptyCanvas"));
} }
if (type === "svg" || type === "clipboard-svg") { if (type === "svg" || type === "clipboard-svg") {
const tempSvg = await exportToSvg( const svgPromise = exportToSvg(
elements, elements,
{ {
exportBackground, exportBackground,
@ -113,9 +113,12 @@ export const exportCanvas = async (
files, files,
{ exportingFrame }, { exportingFrame },
); );
if (type === "svg") { if (type === "svg") {
return await fileSave( return fileSave(
new Blob([tempSvg.outerHTML], { type: MIME_TYPES.svg }), svgPromise.then((svg) => {
return new Blob([svg.outerHTML], { type: MIME_TYPES.svg });
}),
{ {
description: "Export to SVG", description: "Export to SVG",
name, name,
@ -124,7 +127,9 @@ export const exportCanvas = async (
}, },
); );
} else if (type === "clipboard-svg") { } else if (type === "clipboard-svg") {
await copyTextToSystemClipboard(tempSvg.outerHTML); await copyTextToSystemClipboard(
await svgPromise.then((svg) => svg.outerHTML),
);
return; return;
} }
} }
@ -137,17 +142,20 @@ export const exportCanvas = async (
}); });
if (type === "png") { if (type === "png") {
let blob = await canvasToBlob(tempCanvas); let blob = canvasToBlob(tempCanvas);
if (appState.exportEmbedScene) { if (appState.exportEmbedScene) {
blob = await ( blob = blob.then((blob) =>
await import("./image") import("./image").then(({ encodePngMetadata }) =>
).encodePngMetadata({ encodePngMetadata({
blob, blob,
metadata: serializeAsJSON(elements, appState, files, "local"), metadata: serializeAsJSON(elements, appState, files, "local"),
}); }),
),
);
} }
return await fileSave(blob, { return fileSave(blob, {
description: "Export to PNG", description: "Export to PNG",
name, name,
// FIXME reintroduce `excalidraw.png` when most people upgrade away // FIXME reintroduce `excalidraw.png` when most people upgrade away