Skip to content

Commit

Permalink
Add possibility to add a proxy manually
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Aug 15, 2024
1 parent 6dbaa5d commit b0baf2c
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/components/Proxy/CustomProxies.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { NCard, NCheckbox, NDivider, NSwitch, NTooltip } from 'naive-ui';
import { computed, ref } from 'vue';
import { NCard, NCheckbox, NDivider, NSwitch, NTooltip, NInput } from 'naive-ui';
import Button from '@/components/Buttons/Button.vue';
import TitleCategory from '@/components/TitleCategory.vue';
Expand Down Expand Up @@ -30,6 +30,26 @@ const handleCustomProxySelect = (host: string) => {
hostProxySelect.value = true;
toggleLocations();
};
const customProxyDomain = ref('');
const formError = ref('');
const isValidDomain = (domain: string) => {
const domainRegex = /^([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,}$/;
return domainRegex.test(domain);
};
const selectLocationForNewProxy = () => {
if (!isValidDomain(customProxyDomain.value)) {
formError.value = 'Please enter a valid domain name.';
return;
}
customProxy.value = customProxyDomain.value;
hostProxySelect.value = true;
toggleLocations();
formError.value = '';
};
</script>

<template>
Expand Down Expand Up @@ -68,6 +88,21 @@ const handleCustomProxySelect = (host: string) => {
<Button color="error" @click="removeCustomProxy(host)">Remove proxy</Button>
</div>
</div>

<div class="mb-3">
<n-divider />
<TitleCategory title="Add a proxy manually" />

<div class="flex">
<NInput
v-model:value="customProxyDomain"
placeholder="Enter domain name"
class="flex-grow mr-2"
/>
<Button class="w-3/12" @click="selectLocationForNewProxy">Select location</Button>
</div>
<div v-if="formError" class="text-red-500 mt-2">{{ formError }}</div>
</div>
</NCard>

<NCard v-if="excludedHosts.length > 0" :bordered="false">
Expand Down

0 comments on commit b0baf2c

Please sign in to comment.