Skip to content

Commit f2217da

Browse files
committed
enh: verify terminal connection
1 parent b312318 commit f2217da

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/lib/components/AddTerminalServerModal.svelte

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import XMark from '$lib/components/icons/XMark.svelte';
1111
import AccessControlModal from '$lib/components/workspace/common/AccessControlModal.svelte';
1212
import LockClosed from '$lib/components/icons/LockClosed.svelte';
13+
import Tooltip from '$lib/components/common/Tooltip.svelte';
14+
import { getTerminalConfig } from '$lib/apis/terminal';
1315
1416
export let show = false;
1517
export let edit = false;
@@ -56,6 +58,22 @@
5658
init();
5759
}
5860
61+
const verifyHandler = async () => {
62+
const _url = url.replace(/\/$/, '');
63+
if (!_url) {
64+
toast.error($i18n.t('Please enter a valid URL'));
65+
return;
66+
}
67+
68+
const res = await getTerminalConfig(_url, key);
69+
70+
if (res) {
71+
toast.success($i18n.t('Server connection verified'));
72+
} else {
73+
toast.error($i18n.t('Server connection failed'));
74+
}
75+
};
76+
5977
const submitHandler = () => {
6078
if (url === '') {
6179
toast.error($i18n.t('Please enter a valid URL'));
@@ -176,6 +194,31 @@
176194
/>
177195
</div>
178196
</div>
197+
198+
<Tooltip content={$i18n.t('Verify Connection')} className="self-end -mb-1">
199+
<button
200+
class="self-center p-1 bg-transparent hover:bg-gray-100 dark:hover:bg-gray-850 rounded-lg transition"
201+
on:click={() => {
202+
verifyHandler();
203+
}}
204+
type="button"
205+
aria-label={$i18n.t('Verify Connection')}
206+
>
207+
<svg
208+
xmlns="http://www.w3.org/2000/svg"
209+
viewBox="0 0 20 20"
210+
fill="currentColor"
211+
aria-hidden="true"
212+
class="w-4 h-4"
213+
>
214+
<path
215+
fill-rule="evenodd"
216+
d="M15.312 11.424a5.5 5.5 0 01-9.201 2.466l-.312-.311h2.433a.75.75 0 000-1.5H3.989a.75.75 0 00-.75.75v4.242a.75.75 0 001.5 0v-2.43l.31.31a7 7 0 0011.712-3.138.75.75 0 00-1.449-.39zm1.23-3.723a.75.75 0 00.219-.53V2.929a.75.75 0 00-1.5 0V5.36l-.31-.31A7 7 0 003.239 8.188a.75.75 0 101.448.389A5.5 5.5 0 0113.89 6.11l.311.31h-2.432a.75.75 0 000 1.5h4.243a.75.75 0 00.53-.219z"
217+
clip-rule="evenodd"
218+
/>
219+
</svg>
220+
</button>
221+
</Tooltip>
179222
</div>
180223

181224
<div class="flex items-center justify-between">

0 commit comments

Comments
 (0)