| 84 | } |
| 85 | |
| 86 | function isAcceptableFile(file: File, accept: string) { |
| 87 | if (!accept) { |
| 88 | return true |
| 89 | } |
| 90 | |
| 91 | const wildcards = ['audio/*', 'image/*', 'video/*'] |
| 92 | |
| 93 | return accept.split(',').some(acceptToken => { |
| 94 | if (acceptToken.startsWith('.')) { |
| 95 | // tokens starting with a dot represent a file extension |
| 96 | return file.name.endsWith(acceptToken) |
| 97 | } else if (wildcards.includes(acceptToken)) { |
| 98 | return file.type.startsWith(acceptToken.substr(0, acceptToken.length - 1)) |
| 99 | } |
| 100 | return file.type === acceptToken |
| 101 | }) |
| 102 | } |
| 103 | |
| 104 | export {upload} |