2019-03-01 13:29:00 +00:00
|
|
|
<template>
|
2019-11-08 18:50:28 +00:00
|
|
|
<NetworkForm :handle-submit="handleSubmit" :defaults="defaults" :disabled="disabled" />
|
2019-03-01 13:29:00 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-11-16 17:24:03 +00:00
|
|
|
import socket from "../../js/socket";
|
2019-03-01 13:29:00 +00:00
|
|
|
import NetworkForm from "../NetworkForm.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Connect",
|
|
|
|
components: {
|
|
|
|
NetworkForm,
|
|
|
|
},
|
2019-11-08 18:50:28 +00:00
|
|
|
props: {
|
|
|
|
queryParams: Object,
|
|
|
|
},
|
2019-03-01 13:29:00 +00:00
|
|
|
data() {
|
2019-11-08 18:50:28 +00:00
|
|
|
// Merge settings from url params into default settings
|
|
|
|
const defaults = Object.assign(
|
|
|
|
{},
|
|
|
|
this.$store.state.serverConfiguration.defaults,
|
|
|
|
this.parseOverrideParams(this.queryParams)
|
|
|
|
);
|
2019-03-01 13:29:00 +00:00
|
|
|
return {
|
|
|
|
disabled: false,
|
2019-11-08 18:50:28 +00:00
|
|
|
defaults,
|
2019-03-01 13:29:00 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleSubmit(data) {
|
|
|
|
this.disabled = true;
|
|
|
|
socket.emit("network:new", data);
|
|
|
|
},
|
2019-11-08 18:50:28 +00:00
|
|
|
parseOverrideParams(params) {
|
|
|
|
const parsedParams = {};
|
|
|
|
|
|
|
|
for (let key of Object.keys(params)) {
|
2019-11-12 10:39:46 +00:00
|
|
|
if (!params[key]) {
|
2019-11-08 18:50:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-11-23 22:45:04 +00:00
|
|
|
let value = params[key];
|
|
|
|
|
2019-11-08 18:50:28 +00:00
|
|
|
// Param can contain multiple values in an array if its supplied more than once
|
2019-11-23 22:45:04 +00:00
|
|
|
if (Array.isArray(value)) {
|
|
|
|
value = value[0];
|
|
|
|
}
|
2019-11-08 18:50:28 +00:00
|
|
|
|
|
|
|
// Support `channels` as a compatibility alias with other clients
|
|
|
|
if (key === "channels") {
|
|
|
|
key = "join";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!Object.prototype.hasOwnProperty.call(
|
|
|
|
this.$store.state.serverConfiguration.defaults,
|
|
|
|
key
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the network is locked, URL overrides should not affect disabled fields
|
|
|
|
if (
|
2019-11-12 10:39:46 +00:00
|
|
|
this.$store.state.serverConfiguration.lockNetwork &&
|
2019-11-08 18:50:28 +00:00
|
|
|
["host", "port", "tls", "rejectUnauthorized"].includes(key)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the network is not displayed, its name in the UI is not customizable
|
|
|
|
if (!this.$store.state.serverConfiguration.displayNetwork && key === "name") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key === "join") {
|
|
|
|
value = value
|
|
|
|
.split(",")
|
|
|
|
.map((chan) => {
|
|
|
|
if (!chan.match(/^[#&!+]/)) {
|
|
|
|
return `#${chan}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
})
|
|
|
|
.join(", ");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override server provided defaults with parameters passed in the URL if they match the data type
|
|
|
|
switch (typeof this.$store.state.serverConfiguration.defaults[key]) {
|
|
|
|
case "boolean":
|
2019-11-23 22:45:04 +00:00
|
|
|
if (value === "0" || value === "false") {
|
|
|
|
parsedParams[key] = false;
|
|
|
|
} else {
|
|
|
|
parsedParams[key] = !!value;
|
|
|
|
}
|
|
|
|
|
2019-11-08 18:50:28 +00:00
|
|
|
break;
|
|
|
|
case "number":
|
|
|
|
parsedParams[key] = Number(value);
|
|
|
|
break;
|
|
|
|
case "string":
|
|
|
|
parsedParams[key] = String(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedParams;
|
|
|
|
},
|
2019-03-01 13:29:00 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|