Fix library dnd (#2314)

This commit is contained in:
David Luzar 2020-10-30 21:01:41 +01:00 committed by GitHub
parent 8a50916ef2
commit ba3f548b91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 261 additions and 168 deletions

View file

@ -55,13 +55,24 @@ export const parseFileContents = async (blob: Blob | File) => {
return contents;
};
const getMimeType = (blob: Blob): string => {
if (blob.type) {
return blob.type;
export const getMimeType = (blob: Blob | string): string => {
let name: string;
if (typeof blob === "string") {
name = blob;
} else {
if (blob.type) {
return blob.type;
}
name = blob.name || "";
}
const name = blob.name || "";
if (/\.(excalidraw|json)$/.test(name)) {
return "application/json";
} else if (/\.png$/.test(name)) {
return "image/png";
} else if (/\.jpe?g$/.test(name)) {
return "image/jpeg";
} else if (/\.svg$/.test(name)) {
return "image/svg+xml";
}
return "";
};