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>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {defineComponent, ref} from "vue";
|
|
|
|
|
2019-11-16 17:24:03 +00:00
|
|
|
import socket from "../../js/socket";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {useStore} from "../../js/store";
|
|
|
|
import NetworkForm, {NetworkFormDefaults} from "../NetworkForm.vue";
|
2019-03-01 13:29:00 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2019-03-01 13:29:00 +00:00
|
|
|
name: "Connect",
|
|
|
|
components: {
|
|
|
|
NetworkForm,
|
|
|
|
},
|
2019-11-08 18:50:28 +00:00
|
|
|
props: {
|
|
|
|
queryParams: Object,
|
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
setup(props) {
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
const disabled = ref(false);
|
|
|
|
|
|
|
|
const handleSubmit = (data: Record<string, any>) => {
|
|
|
|
disabled.value = true;
|
2019-03-01 13:29:00 +00:00
|
|
|
socket.emit("network:new", data);
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const parseOverrideParams = (params?: Record<string, string>) => {
|
|
|
|
if (!params) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const parsedParams: Record<string, any> = {};
|
2019-11-08 18:50:28 +00:00
|
|
|
|
|
|
|
for (let key of Object.keys(params)) {
|
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(
|
2022-06-19 00:25:21 +00:00
|
|
|
store.state.serverConfiguration?.defaults,
|
2019-11-08 18:50:28 +00:00
|
|
|
key
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the network is locked, URL overrides should not affect disabled fields
|
|
|
|
if (
|
2022-06-19 00:25:21 +00:00
|
|
|
store.state.serverConfiguration?.lockNetwork &&
|
2020-03-31 17:03:40 +00:00
|
|
|
["name", "host", "port", "tls", "rejectUnauthorized"].includes(key)
|
2019-11-08 18:50:28 +00:00
|
|
|
) {
|
|
|
|
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
|
2022-06-19 00:25:21 +00:00
|
|
|
switch (typeof store.state.serverConfiguration?.defaults[key]) {
|
2019-11-08 18:50:28 +00:00
|
|
|
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;
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaults = ref<Partial<NetworkFormDefaults>>(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
store.state.serverConfiguration?.defaults,
|
|
|
|
parseOverrideParams(props.queryParams)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
defaults,
|
|
|
|
disabled,
|
|
|
|
handleSubmit,
|
|
|
|
};
|
2019-03-01 13:29:00 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2019-03-01 13:29:00 +00:00
|
|
|
</script>
|