feat: better file normalization (#10024)

* feat: better file normalization

* fix lint

* fix png detection

* optimize

* fix type
This commit is contained in:
David Luzar
2025-09-25 22:26:58 +02:00
committed by Mark Tolmacs
parent af4e1befef
commit 2fbfca5067
4 changed files with 57 additions and 54 deletions

View File

@@ -8,13 +8,15 @@ import { EVENT, MIME_TYPES, debounce } from "@excalidraw/common";
import { AbortError } from "../errors";
import { normalizeFile } from "./blob";
import type { FileSystemHandle } from "browser-fs-access";
type FILE_EXTENSION = Exclude<keyof typeof MIME_TYPES, "binary">;
const INPUT_CHANGE_INTERVAL_MS = 500;
export const fileOpen = <M extends boolean | undefined = false>(opts: {
export const fileOpen = async <M extends boolean | undefined = false>(opts: {
extensions?: FILE_EXTENSION[];
description: string;
multiple?: M;
@@ -35,7 +37,7 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
return acc.concat(`.${ext}`);
}, [] as string[]);
return _fileOpen({
const files = await _fileOpen({
description: opts.description,
extensions,
mimeTypes,
@@ -74,7 +76,14 @@ export const fileOpen = <M extends boolean | undefined = false>(opts: {
}
};
},
}) as Promise<RetType>;
});
if (Array.isArray(files)) {
return (await Promise.all(
files.map((file) => normalizeFile(file)),
)) as RetType;
}
return (await normalizeFile(files)) as RetType;
};
export const fileSave = (