The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/utils/lib/fileUploadRestrictions.js

44 lines
1.0 KiB

import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
let settings;
if (Meteor.isClient) {
settings = require('../../settings/client').settings;
} else {
settings = require('../../settings/server').settings;
}
const fileUploadMediaWhiteList = function(customWhiteList) {
const mediaTypeWhiteList = customWhiteList || settings.get('FileUpload_MediaTypeWhiteList');
if (!mediaTypeWhiteList || mediaTypeWhiteList === '*') {
return;
}
return _.map(mediaTypeWhiteList.split(','), function(item) {
return item.trim();
});
};
export const fileUploadIsValidContentType = function(type, customWhiteList) {
const list = fileUploadMediaWhiteList(customWhiteList);
if (!list) {
return true;
}
if (!type) {
return false;
}
if (_.contains(list, type)) {
return true;
}
const wildCardGlob = '/*';
const wildcards = _.filter(list, function(item) {
return item.indexOf(wildCardGlob) > 0;
});
if (_.contains(wildcards, type.replace(/(\/.*)$/, wildCardGlob))) {
return true;
}
return false;
};