feat: make file handling more robust (#5057)

This commit is contained in:
David Luzar 2022-05-09 15:53:04 +02:00 committed by GitHub
parent 0d70690ec8
commit d2e687ed0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 328 additions and 152 deletions

View file

@ -9,7 +9,7 @@ import {
import { clearElementsForDatabase, clearElementsForExport } from "../element";
import { ExcalidrawElement } from "../element/types";
import { AppState, BinaryFiles, LibraryItems } from "../types";
import { isImageFileHandle, loadFromBlob } from "./blob";
import { isImageFileHandle, loadFromBlob, normalizeFile } from "./blob";
import {
ExportedDataState,
@ -93,13 +93,13 @@ export const loadFromJSON = async (
localAppState: AppState,
localElements: readonly ExcalidrawElement[] | null,
) => {
const blob = await fileOpen({
const file = await fileOpen({
description: "Excalidraw files",
// ToDo: Be over-permissive until https://bugs.webkit.org/show_bug.cgi?id=34442
// gets resolved. Else, iOS users cannot open `.excalidraw` files.
// extensions: ["json", "excalidraw", "png", "svg"],
});
return loadFromBlob(blob, localAppState, localElements);
return loadFromBlob(await normalizeFile(file), localAppState, localElements);
};
export const isValidExcalidrawData = (data?: {