overleaf/services/web/frontend/js/features/file-tree/util/is-acceptable-file.ts
Jakob Ackermann aa480a2663 Merge pull request #18898 from overleaf/jpa-no-window
[web] migrate from window attributes to getMeta

GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
2024-06-19 08:04:21 +00:00

26 lines
660 B
TypeScript

import { Minimatch } from 'minimatch'
import getMeta from '@/utils/meta'
let fileIgnoreMatcher: Minimatch
export const isAcceptableFile = (name?: string, relativePath?: string) => {
if (!fileIgnoreMatcher) {
fileIgnoreMatcher = new Minimatch(
getMeta('ol-ExposedSettings').fileIgnorePattern,
{ nocase: true, dot: true }
)
}
if (!name) {
// the file must have a name, of course
return false
}
if (!relativePath) {
// uploading an individual file, so allow anything
return true
}
// uploading a file in a folder, so exclude unwanted file paths
return !fileIgnoreMatcher.match(relativePath + '/' + name)
}