[FIX] Empty white list enables all media types upload (#1080)
* Create utils to media (canUpload) * Fix variable name
This commit is contained in:
parent
d250f77a5d
commit
8cfdf868ed
|
@ -13,6 +13,7 @@ import Button from '../Button';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import sharedStyles from '../../views/Styles';
|
import sharedStyles from '../../views/Styles';
|
||||||
import { isIOS } from '../../utils/deviceInfo';
|
import { isIOS } from '../../utils/deviceInfo';
|
||||||
|
import { canUploadFile } from '../../utils/media';
|
||||||
import {
|
import {
|
||||||
COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE, COLOR_DANGER
|
COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_WHITE, COLOR_DANGER
|
||||||
} from '../../constants/colors';
|
} from '../../constants/colors';
|
||||||
|
@ -291,9 +292,11 @@ export default class UploadModal extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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 { name, description } = this.state;
|
||||||
const showError = !this.canUploadFile();
|
const showError = !canUploadFile(file, { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize });
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isVisible={isVisible}
|
isVisible={isVisible}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
export const canUploadFile = (file, serverInfo) => {
|
||||||
|
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;
|
||||||
|
};
|
|
@ -16,6 +16,7 @@ import { isIOS, isAndroid } from '../../utils/deviceInfo';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { CustomIcon } from '../../lib/Icons';
|
import { CustomIcon } from '../../lib/Icons';
|
||||||
import log from '../../utils/log';
|
import log from '../../utils/log';
|
||||||
|
import { canUploadFile } from '../../utils/media';
|
||||||
import DirectoryItem, { ROW_HEIGHT } from '../../presentation/DirectoryItem';
|
import DirectoryItem, { ROW_HEIGHT } from '../../presentation/DirectoryItem';
|
||||||
import ServerItem from '../../presentation/ServerItem';
|
import ServerItem from '../../presentation/ServerItem';
|
||||||
import { CloseShareExtensionButton, CustomHeaderButtons, Item } from '../../containers/HeaderButton';
|
import { CloseShareExtensionButton, CustomHeaderButtons, Item } from '../../containers/HeaderButton';
|
||||||
|
@ -130,7 +131,7 @@ export default class ShareListView extends React.Component {
|
||||||
name: data.filename,
|
name: data.filename,
|
||||||
description: '',
|
description: '',
|
||||||
size: data.size,
|
size: data.size,
|
||||||
type: mime.lookup(data.path),
|
mime: mime.lookup(data.path),
|
||||||
store: 'Uploads',
|
store: 'Uploads',
|
||||||
path: isIOS ? data.path : `file://${ data.path }`
|
path: isIOS ? data.path : `file://${ data.path }`
|
||||||
};
|
};
|
||||||
|
@ -187,6 +188,7 @@ export default class ShareListView extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSubscriptions = (server, fileInfo) => {
|
getSubscriptions = (server, fileInfo) => {
|
||||||
|
const { fileInfo: fileData } = this.state;
|
||||||
const { serversDB } = database.databases;
|
const { serversDB } = database.databases;
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
|
@ -199,7 +201,7 @@ export default class ShareListView extends React.Component {
|
||||||
chats: this.chats ? this.chats.slice() : [],
|
chats: this.chats ? this.chats.slice() : [],
|
||||||
servers: this.servers ? this.servers.slice() : [],
|
servers: this.servers ? this.servers.slice() : [],
|
||||||
loading: false,
|
loading: false,
|
||||||
showError: !this.canUploadFile(serverInfo, fileInfo),
|
showError: !canUploadFile(fileInfo || fileData, serverInfo),
|
||||||
serverInfo
|
serverInfo
|
||||||
});
|
});
|
||||||
this.forceUpdate();
|
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) => {
|
search = (text) => {
|
||||||
const result = database.objects('subscriptions').filtered('name CONTAINS[c] $0', text);
|
const result = database.objects('subscriptions').filtered('name CONTAINS[c] $0', text);
|
||||||
this.internalSetState({
|
this.internalSetState({
|
||||||
|
@ -423,7 +399,7 @@ export default class ShareListView extends React.Component {
|
||||||
<View style={[styles.container, styles.centered]}>
|
<View style={[styles.container, styles.centered]}>
|
||||||
<Text style={styles.title}>{I18n.t(errorMessage)}</Text>
|
<Text style={styles.title}>{I18n.t(errorMessage)}</Text>
|
||||||
<CustomIcon name='circle-cross' size={120} style={styles.errorIcon} />
|
<CustomIcon name='circle-cross' size={120} style={styles.errorIcon} />
|
||||||
<Text style={styles.fileMime}>{ file.type }</Text>
|
<Text style={styles.fileMime}>{ file.mime }</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
|
@ -137,7 +137,7 @@ export default class ShareView extends React.Component {
|
||||||
renderPreview = () => {
|
renderPreview = () => {
|
||||||
const { fileInfo } = this.state;
|
const { fileInfo } = this.state;
|
||||||
|
|
||||||
const icon = fileInfo.type.match(/image/)
|
const icon = fileInfo.mime.match(/image/)
|
||||||
? <Image source={{ isStatic: true, uri: fileInfo.path }} style={styles.mediaImage} />
|
? <Image source={{ isStatic: true, uri: fileInfo.path }} style={styles.mediaImage} />
|
||||||
: (
|
: (
|
||||||
<View style={styles.mediaIconContainer}>
|
<View style={styles.mediaIconContainer}>
|
||||||
|
|
Loading…
Reference in New Issue