FIX: improves UI state when no extensions are allowed for upload

This commit is contained in:
Joffrey JAFFEUX
2018-01-26 18:12:23 +01:00
committed by GitHub
parent 56834dbd98
commit 3d595a52ca
4 changed files with 36 additions and 8 deletions

View File

@ -193,6 +193,8 @@ export function validateUploadedFiles(files, opts) {
}
export function validateUploadedFile(file, opts) {
if (!authorizesOneOrMoreExtensions()) return false;
opts = opts || {};
const name = file && file.name;
@ -277,6 +279,21 @@ export function authorizesAllExtensions() {
return Discourse.SiteSettings.authorized_extensions.indexOf("*") >= 0;
}
export function authorizesOneOrMoreExtensions() {
if (authorizesAllExtensions()) return true;
return Discourse.SiteSettings.authorized_extensions
.split("|")
.filter(ext => ext)
.length > 0;
}
export function authorizesOneOrMoreImageExtensions() {
if (authorizesAllExtensions()) return true;
return imagesExtensions().length > 0;
}
export function isAnImage(path) {
return (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)$/i).test(path);
}