diff --git a/app/containers/MessageBox/UploadModal.js b/app/containers/MessageBox/UploadModal.js index 6616ccc08b..5c8e5bb54e 100644 --- a/app/containers/MessageBox/UploadModal.js +++ b/app/containers/MessageBox/UploadModal.js @@ -13,6 +13,7 @@ import Button from '../Button'; import I18n from '../../i18n'; import sharedStyles from '../../views/Styles'; import { isIOS } from '../../utils/deviceInfo'; +import { canUploadFile } from '../../utils/media'; import { COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE, COLOR_DANGER } from '../../constants/colors'; @@ -291,9 +292,11 @@ export default class UploadModal extends Component { } render() { - const { window: { width }, isVisible, close } = this.props; + const { + window: { width }, isVisible, close, file, FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize + } = this.props; const { name, description } = this.state; - const showError = !this.canUploadFile(); + const showError = !canUploadFile(file, { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize }); return ( { + const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = serverInfo; + if (!(file && file.path)) { + return true; + } + if (file.size > FileUpload_MaxFileSize) { + return false; + } + // if white list is empty, all media types are enabled + if (!FileUpload_MediaTypeWhiteList) { + return true; + } + const allowedMime = FileUpload_MediaTypeWhiteList.split(','); + if (allowedMime.includes(file.mime)) { + return true; + } + const wildCardGlob = '/*'; + const wildCards = allowedMime.filter(item => item.indexOf(wildCardGlob) > 0); + if (wildCards.includes(file.mime.replace(/(\/.*)$/, wildCardGlob))) { + return true; + } + return false; +}; diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index 5d0ba2b367..da4fc3b41d 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -16,6 +16,7 @@ import { isIOS, isAndroid } from '../../utils/deviceInfo'; import I18n from '../../i18n'; import { CustomIcon } from '../../lib/Icons'; import log from '../../utils/log'; +import { canUploadFile } from '../../utils/media'; import DirectoryItem, { ROW_HEIGHT } from '../../presentation/DirectoryItem'; import ServerItem from '../../presentation/ServerItem'; import { CloseShareExtensionButton, CustomHeaderButtons, Item } from '../../containers/HeaderButton'; @@ -130,7 +131,7 @@ export default class ShareListView extends React.Component { name: data.filename, description: '', size: data.size, - type: mime.lookup(data.path), + mime: mime.lookup(data.path), store: 'Uploads', path: isIOS ? data.path : `file://${ data.path }` }; @@ -187,6 +188,7 @@ export default class ShareListView extends React.Component { } getSubscriptions = (server, fileInfo) => { + const { fileInfo: fileData } = this.state; const { serversDB } = database.databases; if (server) { @@ -199,7 +201,7 @@ export default class ShareListView extends React.Component { chats: this.chats ? this.chats.slice() : [], servers: this.servers ? this.servers.slice() : [], loading: false, - showError: !this.canUploadFile(serverInfo, fileInfo), + showError: !canUploadFile(fileInfo || fileData, serverInfo), serverInfo }); this.forceUpdate(); @@ -227,32 +229,6 @@ export default class ShareListView extends React.Component { }); } - canUploadFile = (serverInfo, fileInfo) => { - const { fileInfo: fileData } = this.state; - const file = fileInfo || fileData; - const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = serverInfo; - - if (!(file && file.path)) { - return true; - } - if (file.size > FileUpload_MaxFileSize) { - return false; - } - if (!FileUpload_MediaTypeWhiteList) { - return false; - } - const allowedMime = FileUpload_MediaTypeWhiteList.split(','); - if (allowedMime.includes(file.type)) { - return true; - } - const wildCardGlob = '/*'; - const wildCards = allowedMime.filter(item => item.indexOf(wildCardGlob) > 0); - if (wildCards.includes(file.type.replace(/(\/.*)$/, wildCardGlob))) { - return true; - } - return false; - } - search = (text) => { const result = database.objects('subscriptions').filtered('name CONTAINS[c] $0', text); this.internalSetState({ @@ -423,7 +399,7 @@ export default class ShareListView extends React.Component { {I18n.t(errorMessage)} - { file.type } + { file.mime } ); diff --git a/app/views/ShareView/index.js b/app/views/ShareView/index.js index 8f4b783db1..2829462733 100644 --- a/app/views/ShareView/index.js +++ b/app/views/ShareView/index.js @@ -137,7 +137,7 @@ export default class ShareView extends React.Component { renderPreview = () => { const { fileInfo } = this.state; - const icon = fileInfo.type.match(/image/) + const icon = fileInfo.mime.match(/image/) ? : (