overleaf/services/web/frontend/js/features/file-tree/util/is-acceptable-file.ts
Alf Eaton bef2e4fbce Allow any single file to be uploaded (#17215)
GitOrigin-RevId: 9eecc9e044ec1a489b42ccf697806fecfbe5dfc8
2024-02-22 09:04:43 +00:00

21 lines
542 B
TypeScript

import { Minimatch } from 'minimatch'
const fileIgnoreMatcher = new Minimatch(
window.ExposedSettings.fileIgnorePattern,
{ nocase: true, dot: true }
)
export const isAcceptableFile = (name?: string, relativePath?: string) => {
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)
}