Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

509 B
Raw Blame
import DOMPurify from "dompurify";
import { JSDOM } from "jsdom";

export async function sanitizeFile(file: File) {
	if (file.type === "image/svg+xml") {
		const dom = new JSDOM(await file.text(), { contentType: "image/svg+xml" });
		const purify = DOMPurify(dom.window);
		const sanitizedSvg = purify.sanitize(
			dom.window.document.documentElement.outerHTML,
			{ USE_PROFILES: { svg: true, svgFilters: true } },
		);

		return new File([sanitizedSvg], file.name, { type: file.type });
	}

	return file;
}