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 = (
blob: Blob,
blob: Blob | Promise<Blob>,
opts: {
/** supply without the extension */
name: string;

View file

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