Virtual whiteboard for sketching hand-drawn like diagrams
Load only valid excalidraw json when drag&drop (#678)
Faustino Kialungilaabd04cb8700e
diff --git a/src/scene/data.ts b/src/scene/data.tsindex 584a127e59..095c4f6585 100644--- a/src/scene/data.ts+++ b/src/scene/data.ts@@ -24,6 +24,9 @@ const BACKEND_GET = "https://json.excalidraw.com/api/v1/";(window as any).handle = null;interface DataState {+ type?: string;+ version?: string;+ source?: string;elements: readonly ExcalidrawElement[];appState: AppState | null;selectedId?: number;@@ -92,6 +95,9 @@ export async function loadFromBlob(blob: any) {let appState = defaultAppState;try {const data = JSON.parse(contents);+ if (data.type !== "excalidraw") {+ throw new Error("Cannot load invalid json");+ }elements = data.elements || [];appState = { ...defaultAppState, ...data.appState };} catch (e) {@@ -120,6 +126,9 @@ export async function loadFromBlob(blob: any) {})();}const { elements, appState } = updateAppState(contents);+ if (!elements.length) {+ return Promise.reject("Cannot load invalid json");+ }return new Promise<DataState>(resolve => {resolve(restore(elements, appState, { scrollToContent: true }));});