is-acceptable-file.ts 618 B

12345678910111213141516171819202122232425
  1. import { Minimatch } from 'minimatch'
  2. let fileIgnoreMatcher: Minimatch
  3. export const isAcceptableFile = (name?: string, relativePath?: string) => {
  4. if (!fileIgnoreMatcher) {
  5. fileIgnoreMatcher = new Minimatch(
  6. window.ExposedSettings.fileIgnorePattern,
  7. { nocase: true, dot: true }
  8. )
  9. }
  10. if (!name) {
  11. // the file must have a name, of course
  12. return false
  13. }
  14. if (!relativePath) {
  15. // uploading an individual file, so allow anything
  16. return true
  17. }
  18. // uploading a file in a folder, so exclude unwanted file paths
  19. return !fileIgnoreMatcher.match(relativePath + '/' + name)
  20. }