( typesOrRouteConfig: string[] | ExpandedRouteConfig, )
| 26 | }; |
| 27 | |
| 28 | export const generateMimeTypes = ( |
| 29 | typesOrRouteConfig: string[] | ExpandedRouteConfig, |
| 30 | ) => { |
| 31 | const fileTypes = Array.isArray(typesOrRouteConfig) |
| 32 | ? typesOrRouteConfig |
| 33 | : objectKeys(typesOrRouteConfig); |
| 34 | if (fileTypes.includes("blob")) return []; |
| 35 | |
| 36 | return fileTypes.map((type) => { |
| 37 | if (type === "pdf") return "application/pdf"; |
| 38 | if (type.includes("/")) return type; |
| 39 | |
| 40 | // Add wildcard to support all subtypes, e.g. image => "image/*" |
| 41 | // But some browsers/OSes don't support it, so we'll also dump all the mime types |
| 42 | // we know that starts with the type, e.g. image => "image/png, image/jpeg, ..." |
| 43 | if (type === "audio") return ["audio/*", ...objectKeys(audio)].join(", "); |
| 44 | if (type === "image") return ["image/*", ...objectKeys(image)].join(", "); |
| 45 | if (type === "text") return ["text/*", ...objectKeys(text)].join(", "); |
| 46 | if (type === "video") return ["video/*", ...objectKeys(video)].join(", "); |
| 47 | |
| 48 | return `${type}/*`; |
| 49 | }); |
| 50 | }; |
| 51 | |
| 52 | export const generateClientDropzoneAccept = (fileTypes: string[]) => { |
| 53 | const mimeTypes = generateMimeTypes(fileTypes); |
no test coverage detected