mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-11-14 09:45:27 +01:00
feat: better file normalization (#10024)
* feat: better file normalization * fix lint * fix png detection * optimize * fix type
This commit is contained in:
committed by
Mark Tolmacs
parent
af4e1befef
commit
2fbfca5067
@@ -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 = (
|
||||
|
||||
Reference in New Issue
Block a user