mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(mermaid): bypass security issue when generating PNG
This commit is contained in:
parent
3d0ec27038
commit
6976c9555e
@ -665,14 +665,12 @@ function downloadSvgAsPng(nameWithoutExtension: string, svgContent: string) {
|
|||||||
|
|
||||||
// Convert the image to a blob.
|
// Convert the image to a blob.
|
||||||
const { width, height } = result;
|
const { width, height } = result;
|
||||||
const svgBlob = new Blob([ svgContent ], {
|
|
||||||
type: SVG_MIME
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create an image element and load the SVG.
|
// Create an image element and load the SVG.
|
||||||
const imageEl = new Image();
|
const imageEl = new Image();
|
||||||
imageEl.width = width;
|
imageEl.width = width;
|
||||||
imageEl.height = height;
|
imageEl.height = height;
|
||||||
|
imageEl.crossOrigin = "anonymous";
|
||||||
imageEl.onload = () => {
|
imageEl.onload = () => {
|
||||||
try {
|
try {
|
||||||
// Draw the image with a canvas.
|
// Draw the image with a canvas.
|
||||||
@ -687,7 +685,6 @@ function downloadSvgAsPng(nameWithoutExtension: string, svgContent: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx?.drawImage(imageEl, 0, 0);
|
ctx?.drawImage(imageEl, 0, 0);
|
||||||
URL.revokeObjectURL(imageEl.src);
|
|
||||||
|
|
||||||
const imgUri = canvasEl.toDataURL("image/png")
|
const imgUri = canvasEl.toDataURL("image/png")
|
||||||
triggerDownload(`${nameWithoutExtension}.png`, imgUri);
|
triggerDownload(`${nameWithoutExtension}.png`, imgUri);
|
||||||
@ -698,7 +695,8 @@ function downloadSvgAsPng(nameWithoutExtension: string, svgContent: string) {
|
|||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
imageEl.src = URL.createObjectURL(svgBlob);
|
imageEl.onerror = (e) => reject(e);
|
||||||
|
imageEl.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgContent)}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user