mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-16 21:11:56 +03:00
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import url from 'url';
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
export default class AppPermission extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
const curlBase = this.getCurlBase();
|
|
this.state = { curlBase: curlBase};
|
|
}
|
|
|
|
// Return string representation of content URL without query parameters
|
|
getCurlBase() {
|
|
const wurl = url.parse(this.props.url);
|
|
let curl;
|
|
let curlString;
|
|
|
|
const searchParams = new URLSearchParams(wurl.search);
|
|
|
|
if(searchParams && searchParams.get('url')) {
|
|
curl = url.parse(searchParams.get('url'));
|
|
if(curl) {
|
|
curl.search = curl.query = "";
|
|
curlString = curl.format();
|
|
}
|
|
}
|
|
if (!curl && wurl) {
|
|
wurl.search = wurl.query = "";
|
|
curlString = wurl.format();
|
|
}
|
|
return curlString;
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div className='mx_AppPermissionWarning'>
|
|
<div className='mx_AppPermissionWarningImage'>
|
|
<img src='img/warning.svg' alt={_t('Warning!')}/>
|
|
</div>
|
|
<div className='mx_AppPermissionWarningText'>
|
|
<span className='mx_AppPermissionWarningTextLabel'>Do you want to load widget from URL:</span> <span className='mx_AppPermissionWarningTextURL'>{this.state.curlBase}</span>
|
|
</div>
|
|
<input
|
|
className='mx_AppPermissionButton'
|
|
type='button'
|
|
value={_t('Allow')}
|
|
onClick={this.props.onPermissionGranted}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
AppPermission.propTypes = {
|
|
url: PropTypes.string.isRequired,
|
|
onPermissionGranted: PropTypes.func.isRequired,
|
|
};
|
|
AppPermission.defaultProps = {
|
|
onPermissionGranted: function() {},
|
|
};
|