From 71b8d91c7527028403f5856725276f74d8069776 Mon Sep 17 00:00:00 2001 From: seven Date: Fri, 29 Dec 2023 10:19:35 +0800 Subject: [PATCH] #10 fetch data from es --- src/electron/main.ts | 1 + src/lang/index.ts | 6 ++++ src/store/connectionStore.ts | 29 +++++++++++++++++ src/views/editor/index.vue | 62 ++++++++++++++++++++++++++---------- 4 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/electron/main.ts b/src/electron/main.ts index 6474741..72bf151 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -23,6 +23,7 @@ const BrowserWindowOptions: BrowserWindowConstructorOptions = { webPreferences: { preload: path.resolve(__dirname, 'preload.js'), devTools: isDev, + webSecurity: false, }, }; diff --git a/src/lang/index.ts b/src/lang/index.ts index decde20..6ba851c 100644 --- a/src/lang/index.ts +++ b/src/lang/index.ts @@ -43,6 +43,9 @@ const enUS = { cancel: 'Cancel', removeSuccess: 'Connection removed successfully', }, + editor: { + establishedRequired: 'Select a DB instance before execute actions', + }, }; const zhCN = { @@ -89,6 +92,9 @@ const zhCN = { cancel: '取消', removeSuccess: '连接删除成功', }, + editor: { + establishedRequired: '请选择执行操作的数据库实例', + }, }; const langType = localStorage.lang || 'auto'; diff --git a/src/store/connectionStore.ts b/src/store/connectionStore.ts index 6a28c34..38c735e 100644 --- a/src/store/connectionStore.ts +++ b/src/store/connectionStore.ts @@ -55,5 +55,34 @@ export const useConnectionStore = defineStore('connectionStore', { establishConnection(connection: Connection) { this.established = connection; }, + async searchQDSL(index: string | undefined, qdsl: string) { + const url = index + ? `${this.established?.host}:${this.established?.port}/${index}/_search` + : `${this.established?.host}:${this.established?.port}/_search?`; + + // eslint-disable-next-line no-console + console.log(`searchQDSL_URL ${url}`); + try { + const response = await fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: qdsl, + }); + const data = await response.json(); + if (!response.ok) throw new CustomError(response.status, data); + return data; + } catch (err) { + // eslint-disable-next-line no-console + console.log(`searchQDSL error ${JSON.stringify({ err })}`); + + if (err instanceof CustomError) { + throw new CustomError(err.status, err.details); + } + if (err instanceof Error) { + throw new CustomError(500, err.message); + } + throw new CustomError(500, `unknown error, trace: ${JSON.stringify(err)}`); + } + }, }, }); diff --git a/src/views/editor/index.vue b/src/views/editor/index.vue index 8d4da70..0b91d2d 100644 --- a/src/views/editor/index.vue +++ b/src/views/editor/index.vue @@ -4,16 +4,23 @@