From 37df6823ab7e245385a6b507666cf2655cf1e157 Mon Sep 17 00:00:00 2001 From: seven Date: Sun, 12 May 2024 15:45:34 +0800 Subject: [PATCH 1/3] fix: query not execute when the searched index is not in fetched indices list Signed-off-by: seven --- src/store/connectionStore.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/store/connectionStore.ts b/src/store/connectionStore.ts index e3b1236b..781952fa 100644 --- a/src/store/connectionStore.ts +++ b/src/store/connectionStore.ts @@ -147,13 +147,13 @@ export const useConnectionStore = defineStore('connectionStore', { const newIndex = this.established.indices.find( ({ index: indexName }: ConnectionIndex) => indexName === index, ); - if (!newIndex) { - return; + if (newIndex) { + if (!newIndex.mapping) { + newIndex.mapping = await client.get(`/${index}/_mapping`, 'format=json'); + } + console.log('update active index', newIndex); + this.established = { ...this.established, activeIndex: newIndex }; } - if (!newIndex.mapping) { - newIndex.mapping = await client.get(`/${index}/_mapping`, 'format=json'); - } - this.established = { ...this.established, activeIndex: newIndex }; } } catch (err) { console.error('failed to refresh index mapping', err); From ab050d9b50fd744a7aec97cf42ce312297825c35 Mon Sep 17 00:00:00 2001 From: seven Date: Sun, 12 May 2024 16:02:46 +0800 Subject: [PATCH 2/3] fix: display success response but non-json payload Signed-off-by: seven --- src/electron/fetchApi.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/electron/fetchApi.ts b/src/electron/fetchApi.ts index f669ae78..40a0ee38 100644 --- a/src/electron/fetchApi.ts +++ b/src/electron/fetchApi.ts @@ -40,8 +40,13 @@ const fetchApi: { [key: string]: (key: string, val: unknown) => unknown } = { body: payload ? JSON.parse(payload) : undefined, agent, }); + console.log('fetchApi fetch result:', result.headers.get('content-type')); if (result.ok) { - return { status: result.status, data: await result.json() }; + const data = result.headers.get('content-type').includes('application/json') + ? await result.json() + : (await result.text())?.split('\n')?.filter(Boolean); + + return { status: result.status, data }; } throw new CustomError(result.status, await result.text()); } catch (e) { From fd4905f3e5c9027ed351ca85fa9d109f542a355b Mon Sep 17 00:00:00 2001 From: seven Date: Sun, 12 May 2024 16:07:03 +0800 Subject: [PATCH 3/3] fix: remove debug console.log Signed-off-by: seven --- src/electron/fetchApi.ts | 1 - src/store/connectionStore.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/electron/fetchApi.ts b/src/electron/fetchApi.ts index 40a0ee38..73f5433e 100644 --- a/src/electron/fetchApi.ts +++ b/src/electron/fetchApi.ts @@ -40,7 +40,6 @@ const fetchApi: { [key: string]: (key: string, val: unknown) => unknown } = { body: payload ? JSON.parse(payload) : undefined, agent, }); - console.log('fetchApi fetch result:', result.headers.get('content-type')); if (result.ok) { const data = result.headers.get('content-type').includes('application/json') ? await result.json() diff --git a/src/store/connectionStore.ts b/src/store/connectionStore.ts index 781952fa..a0cd90be 100644 --- a/src/store/connectionStore.ts +++ b/src/store/connectionStore.ts @@ -151,7 +151,6 @@ export const useConnectionStore = defineStore('connectionStore', { if (!newIndex.mapping) { newIndex.mapping = await client.get(`/${index}/_mapping`, 'format=json'); } - console.log('update active index', newIndex); this.established = { ...this.established, activeIndex: newIndex }; } }