feat: use URL() rather than string concatenation

pull/8/head
c-cal 5 years ago
parent ea9e09c166
commit adfcd79c34
Signed by: watcha
GPG Key ID: 87DD78E7F7A1581D
  1. 13
      src/App.js
  2. 2
      src/CreateUserRightPanel.js
  3. 2
      src/DataToTable.js
  4. 4
      src/Monitoring.js
  5. 4
      src/StatsTab.js
  6. 40
      src/UserRightPanel.js

@ -46,15 +46,14 @@ class App extends Component {
.then(response => response.json())
.then(
data =>
data["default_server_config"]["m.homeserver"]["base_url"] +
"/"
data["default_server_config"]["m.homeserver"]["base_url"]
)
.catch(error => {
// should only occur in development environment when the chat
// and the administration interface do not have the same domain
// should only occur if the browser cache was cleared or
// in development environment when the chat and the
// administration interface do not have the same domain
const defaultHomeServer =
(process.env.REACT_APP_CORE || "http://localhost:8008") +
"/";
process.env.REACT_APP_CORE || "http://localhost:8008";
console.log(`Set ${defaultHomeServer} as default home server`);
return defaultHomeServer;
});
@ -85,7 +84,7 @@ class App extends Component {
<AdminHome
className="AdminHome"
token={this.state.client.getAccessToken()}
server={this.state.client.baseUrl + "/"}
server={this.state.client.baseUrl}
/>
) : this.state.loginError ? (
<Login client={this.state.client} setupClient={this.setupClient} />

@ -117,7 +117,7 @@ class CreateUserRightPanel extends Component {
? this.state.userIdValue
: this.state.suggestedUserId;
const USER_REQUEST = await fetch(
HOME_SERVER + "_matrix/client/r0/watcha_register",
new URL("_matrix/client/r0/watcha_register", HOME_SERVER),
{
method: "POST",
headers: {

@ -183,7 +183,7 @@ class DataToTable extends Component {
const HEADERS = this.state.type["header"];
try {
const TABLE_REQUEST = await fetch(
HOME_SERVER + this.state.type["apiAdress"],
new URL(this.state.type["apiAdress"], HOME_SERVER),
{
method: "GET",
headers: {

@ -18,7 +18,7 @@ class Monitoring extends Component {
try {
const LOG_REQUEST = await fetch(
HOME_SERVER + "_matrix/client/r0/watcha_log",
new URL("_matrix/client/r0/watcha_log", HOME_SERVER),
{
method: "GET",
headers: {
@ -44,7 +44,7 @@ class Monitoring extends Component {
try {
const SERVER_REPORT_REQUET = await fetch(
HOME_SERVER + "_matrix/client/r0/watcha_server_state",
new URL("_matrix/client/r0/watcha_server_state", HOME_SERVER),
{
method: "GET",
headers: {

@ -21,7 +21,7 @@ class StatsTab extends Component {
try {
const SERVER_REPORT_REQUET = await fetch(
HOME_SERVER + "_matrix/client/r0/watcha_server_state",
new URL("_matrix/client/r0/watcha_server_state", HOME_SERVER),
{
method: "GET",
headers: {
@ -47,7 +47,7 @@ class StatsTab extends Component {
try {
const STATS_REQUEST = await fetch(
HOME_SERVER + "_matrix/client/r0/watcha_admin_stats",
new URL("_matrix/client/r0/watcha_admin_stats", HOME_SERVER),
{
method: "GET",
headers: {

@ -72,10 +72,12 @@ class UserRightPanel extends Component {
const HOME_SERVER = this.props.server;
const ACCESS_TOKEN = this.props.token;
try {
const userId = encodeURIComponent(this.props.data["User name"]["data"])
const SERVER_REQUEST = await fetch(
HOME_SERVER +
"_matrix/client/r0/watcha_update_email/" +
encodeURIComponent(this.props.data["User name"]["data"]),
new URL(
`_matrix/client/r0/watcha_update_email/${userId}`,
HOME_SERVER
),
{
method: "PUT",
headers: {
@ -138,10 +140,12 @@ class UserRightPanel extends Component {
const HOME_SERVER = this.props.server;
const ACCESS_TOKEN = this.props.token;
try {
const userId = encodeURIComponent(this.props.data["User name"]["data"])
const SERVER_REQUEST = await fetch(
HOME_SERVER +
"_matrix/client/r0/watcha_user_ip/" +
encodeURIComponent(this.props.data["User name"]["data"]),
new URL(
`_matrix/client/r0/watcha_user_ip/${userId}`,
HOME_SERVER
),
{
method: "GET",
headers: {
@ -190,10 +194,12 @@ class UserRightPanel extends Component {
this.simplifiedUserId(this.props.data["User name"]["data"]) +
t(" with a new password");
try {
const userId = encodeURIComponent(this.props.data["User name"]["data"])
const SERVER_REQUEST = await fetch(
HOME_SERVER +
"_matrix/client/r0/watcha_reset_password" +
encodeURIComponent(this.props.data["User name"]["data"]),
new URL(
`_matrix/client/r0/watcha_reset_password/${userId}`,
HOME_SERVER
),
{
method: "POST",
headers: {
@ -248,10 +254,12 @@ class UserRightPanel extends Component {
const ACCESS_TOKEN = this.props.token;
const { t } = this.props;
try {
const userId = encodeURIComponent(this.props.data["User name"]["data"])
const SERVER_REQUEST = await fetch(
HOME_SERVER +
"_matrix/client/r0/admin/deactivate/" +
encodeURIComponent(this.props.data["User name"]["data"]),
new URL(
`_matrix/client/r0/admin/deactivate/${userId}`,
HOME_SERVER
),
{
method: "POST",
headers: {
@ -360,10 +368,12 @@ class UserRightPanel extends Component {
const HOME_SERVER = this.props.server;
const ACCESS_TOKEN = this.props.token;
try {
const userId = encodeURIComponent(this.props.data["User name"]["data"])
const SERVER_REQUEST = await fetch(
HOME_SERVER +
"_matrix/client/r0/watcha_update_partner_to_member/" +
encodeURIComponent(this.props.data["User name"]["data"]),
new URL(
`_matrix/client/r0/watcha_update_partner_to_member/${userId}`,
HOME_SERVER
),
{
method: "PUT",
headers: {

Loading…
Cancel
Save