implemented all the review comments

This commit is contained in:
lip-d 2018-02-21 19:57:15 +09:00
parent d4060d0d59
commit dcc7819dea

View file

@ -157,31 +157,14 @@ const MattermostView = createReactClass({
console.warn(message); console.warn(message);
break; break;
case 2: case 2:
let match = e.message.match(/Not allowed to load local resource:\s*(.+)/); const fileURL = this.extractFileURL(e.message);
let resURL = ""; if (this.isNetworkDrive(fileURL)) {
let isNetworkDrive = false; // Network drive: Should be allowed.
if (!shell.openExternal(decodeURI(fileURL))) {
if (match != null) { console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`);
if (match.length == 2) {
resURL = match[1];
let u = url.parse(resURL);
// Is it on a network drive?
if (u.protocol === 'file:' && u.host) {
isNetworkDrive = true;
}
} }
} } else {
// Local drive such as 'C:\Windows': Should not be allowed.
// Network drive: Should be allowed.
if (isNetworkDrive) {
if (!shell.openExternal(decodeURI(resURL))) {
console.log(`[${this.props.name}] shell.openExternal failed: ${resURL}`);
}
}
// Local drive such as 'C:\Windows': Should not be allowed.
else {
console.error(message); console.error(message);
} }
break; break;
@ -256,6 +239,22 @@ const MattermostView = createReactClass({
); );
}, },
extractFileURL(message) {
const matched = message.match(/Not allowed to load local resource:\s*(.+)/);
if (matched) {
return matched[1];
}
return '';
},
isNetworkDrive(fileURL) {
const u = url.parse(fileURL);
if (u.protocol === 'file:' && u.host) {
return true;
}
return false;
},
render() { render() {
const errorView = this.state.errorInfo ? ( const errorView = this.state.errorInfo ? (
<ErrorView <ErrorView