From 5fcfb8694c3261f3d4ff24641dc0b1da51c20045 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Mon, 23 Jan 2023 13:57:59 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=BD=D0=B5=D1=81=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=8B=20=D0=B2=20=D0=BA=D0=BB=D0=B8?= =?UTF-8?q?=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/sm/requests/get-processes.ts | 4 ++-- api/sm/requests/pagination.ts | 4 ++-- api/sm/requests/process-ouput.ts | 3 +++ api/sm/requests/repeat-process.ts | 4 ++++ api/sm/requests/run-command.ts | 4 ++++ api/sm/schemas/process-output.ts | 11 ++++++++++ api/sm/schemas/repeat-process.ts | 10 +++++++++ api/sm/sm-client.ts | 22 ++++++++++++++++++- components/elements/processes/index.tsx | 29 ++++++++----------------- 9 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 api/sm/requests/process-ouput.ts create mode 100644 api/sm/requests/repeat-process.ts create mode 100644 api/sm/requests/run-command.ts create mode 100644 api/sm/schemas/process-output.ts create mode 100644 api/sm/schemas/repeat-process.ts diff --git a/api/sm/requests/get-processes.ts b/api/sm/requests/get-processes.ts index 2555b48..440bcc1 100644 --- a/api/sm/requests/get-processes.ts +++ b/api/sm/requests/get-processes.ts @@ -4,6 +4,6 @@ export enum ProcessesType HISTORY = 'history', } -export class GetProcessesRequest { +export interface GetProcessesRequest { type?: ProcessesType -} \ No newline at end of file +} diff --git a/api/sm/requests/pagination.ts b/api/sm/requests/pagination.ts index 566c7aa..0c23de5 100644 --- a/api/sm/requests/pagination.ts +++ b/api/sm/requests/pagination.ts @@ -1,4 +1,4 @@ -export class PaginationRequest { +export interface PaginationRequest { page?: number limit?: number -} \ No newline at end of file +} diff --git a/api/sm/requests/process-ouput.ts b/api/sm/requests/process-ouput.ts new file mode 100644 index 0000000..be125f8 --- /dev/null +++ b/api/sm/requests/process-ouput.ts @@ -0,0 +1,3 @@ +export interface ProcessOutputRequest { + id: string +} diff --git a/api/sm/requests/repeat-process.ts b/api/sm/requests/repeat-process.ts new file mode 100644 index 0000000..15b18bd --- /dev/null +++ b/api/sm/requests/repeat-process.ts @@ -0,0 +1,4 @@ +export interface RepeatProcessRequest { + id: string + requestId: string +} diff --git a/api/sm/requests/run-command.ts b/api/sm/requests/run-command.ts new file mode 100644 index 0000000..bda5069 --- /dev/null +++ b/api/sm/requests/run-command.ts @@ -0,0 +1,4 @@ +export interface RunCommandRequest { + commandName: string + requestId: string +} diff --git a/api/sm/schemas/process-output.ts b/api/sm/schemas/process-output.ts new file mode 100644 index 0000000..56b5bf9 --- /dev/null +++ b/api/sm/schemas/process-output.ts @@ -0,0 +1,11 @@ +import {Method, SchemaInterface} from "../../schema-client"; + +class ProcessOutputSchema implements SchemaInterface { + method = Method.GET + url = '/system-monitoring/processes/{id}/output' + contentType = null +} + +export let processOutputSchema = new ProcessOutputSchema() +export default processOutputSchema + diff --git a/api/sm/schemas/repeat-process.ts b/api/sm/schemas/repeat-process.ts new file mode 100644 index 0000000..6be656a --- /dev/null +++ b/api/sm/schemas/repeat-process.ts @@ -0,0 +1,10 @@ +import {Method, SchemaInterface} from "../../schema-client"; + +class RepeatProcessSchema implements SchemaInterface { + method = Method.POST + url = '/system-monitoring/processes/{id}/repeat' + contentType = null +} + +export let repeatProcessSchema = new RepeatProcessSchema() +export default repeatProcessSchema diff --git a/api/sm/sm-client.ts b/api/sm/sm-client.ts index 59977af..0f64415 100644 --- a/api/sm/sm-client.ts +++ b/api/sm/sm-client.ts @@ -7,6 +7,10 @@ import {ResponseInterface} from "./responses/response"; import {CommandResponseInterface} from "./responses/comamnds"; import commandsSchema from "./schemas/commands"; import runCommandsSchema from "./schemas/run-commands"; +import {RepeatProcessRequest} from "./requests/repeat-process"; +import repeatProcessSchema from "./schemas/repeat-process"; +import processOutputSchema from "./schemas/process-output"; +import {ProcessOutputRequest} from "./requests/process-ouput"; export class SMClient { schemaClient: SchemaClient @@ -40,7 +44,23 @@ export class SMClient { headers: headers } } + + async repeatProcess(data: RepeatProcessRequest): Promise { + let { responseData, headers } = await this.schemaClient.send(repeatProcessSchema, data) + return { + data: responseData as ProcessesResponseInterface[], + headers: headers + } + } + + async getProcessOutput(data: ProcessOutputRequest): Promise { + let { responseData, headers } = await this.schemaClient.send(processOutputSchema, data) + return { + data: responseData, + headers: headers + } + } } export let smClient = new SMClient -export default smClient \ No newline at end of file +export default smClient diff --git a/components/elements/processes/index.tsx b/components/elements/processes/index.tsx index 374e15f..4b4e786 100644 --- a/components/elements/processes/index.tsx +++ b/components/elements/processes/index.tsx @@ -85,15 +85,10 @@ export default function Processes() { refreshLock = false } let output = async (process: ProcessInterface) => { - let response = await fetch(`http://fmw.sipachev.sv/system-monitoring/processes/${process.id}/output`, - { - method: 'GET', - headers: { - 'X-Plugin-Token': 'passw0rd', - 'X-Pagination-Count': '0', - }, - }); - const output: string = await response.text() + const { data: output } = await smClient.getProcessOutput({ + id: process.id + }) + let a = document.createElement("a"); let file = new Blob([output], {type: 'plain/text'}); a.href = URL.createObjectURL(file); @@ -126,18 +121,12 @@ export default function Processes() { return } lock = true - let url = `http://fmw.sipachev.sv/system-monitoring/processes/${selectedProcess.id}/repeat` - let data = { + + await smClient.repeatProcess({ + id: selectedProcess.id, requestId: dialogId - } - let response = await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json;charset=utf-8', - 'X-Plugin-Token': 'passw0rd' - }, - body: JSON.stringify(data) - }); + }) + lock = false setSelectedProcess(null) setOpen(false)