From d7c54d92b5e9bfcb95e1748ce8dc33f4bb45aa2d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 26 Sep 2025 22:57:38 -0500 Subject: [PATCH] refac --- src/lib/components/AddToolServerModal.svelte | 39 +++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/lib/components/AddToolServerModal.svelte b/src/lib/components/AddToolServerModal.svelte index bb46d176f3..08489348b3 100644 --- a/src/lib/components/AddToolServerModal.svelte +++ b/src/lib/components/AddToolServerModal.svelte @@ -152,7 +152,16 @@ console.log('importHandler', json); try { - const data = JSON.parse(json); + let data = JSON.parse(json); + // validate data + if (Array.isArray(data)) { + if (data.length === 0) { + toast.error($i18n.t('Please select a valid JSON file')); + return; + } + data = data[0]; + } + if (data.type) type = data.type; if (data.url) url = data.url; @@ -184,23 +193,25 @@ const exportHandler = async () => { // export current connection as json file - const json = JSON.stringify({ - type, - url, + const json = JSON.stringify([ + { + type, + url, - spec_type, - spec, - path, + spec_type, + spec, + path, - auth_type, - key, + auth_type, + key, - info: { - id: id, - name: name, - description: description + info: { + id: id, + name: name, + description: description + } } - }); + ]); const blob = new Blob([json], { type: 'application/json'