From 021f6d37d4691666666ff978a3298b45dc71a55e Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 4 Feb 2025 20:07:47 +0100 Subject: [PATCH] Fixes SAMSUNG update issue where blob.type === "" when adding image from gallery --- packages/excalidraw/data/blob.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index 2293f860c..ffa472767 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -107,6 +107,17 @@ export const isImageFileHandle = (handle: FileSystemHandle | null) => { return type === "png" || type === "svg"; }; +const getExtensionFromFilename = (filename?: string): string | null => { + if (!filename) return null; + const ext = filename.split('.').pop()?.toLowerCase(); + return ext || null; +}; + +const isSupportedExtension = (filename?: string) => { + const extension = getExtensionFromFilename(filename); + return !!extension && extension in IMAGE_MIME_TYPES; +}; + export const isSupportedImageFileType = (type: string | null | undefined) => { return !!type && (Object.values(IMAGE_MIME_TYPES) as string[]).includes(type); }; @@ -115,7 +126,11 @@ export const isSupportedImageFile = ( blob: Blob | null | undefined, ): blob is Blob & { type: ValueOf } => { const { type } = blob || {}; - return isSupportedImageFileType(type); + if (type) { + return isSupportedImageFileType(type); + } + const { name } = blob || {}; + return isSupportedExtension(name); }; export const loadSceneOrLibraryFromBlob = async (