Вынес запросы в клиент

jwt
Sipachev Igor 2 years ago
parent e0a9da229e
commit 5fcfb8694c
  1. 4
      api/sm/requests/get-processes.ts
  2. 4
      api/sm/requests/pagination.ts
  3. 3
      api/sm/requests/process-ouput.ts
  4. 4
      api/sm/requests/repeat-process.ts
  5. 4
      api/sm/requests/run-command.ts
  6. 11
      api/sm/schemas/process-output.ts
  7. 10
      api/sm/schemas/repeat-process.ts
  8. 22
      api/sm/sm-client.ts
  9. 29
      components/elements/processes/index.tsx

@ -4,6 +4,6 @@ export enum ProcessesType
HISTORY = 'history', HISTORY = 'history',
} }
export class GetProcessesRequest { export interface GetProcessesRequest {
type?: ProcessesType type?: ProcessesType
} }

@ -1,4 +1,4 @@
export class PaginationRequest { export interface PaginationRequest {
page?: number page?: number
limit?: number limit?: number
} }

@ -0,0 +1,3 @@
export interface ProcessOutputRequest {
id: string
}

@ -0,0 +1,4 @@
export interface RepeatProcessRequest {
id: string
requestId: string
}

@ -0,0 +1,4 @@
export interface RunCommandRequest {
commandName: string
requestId: string
}

@ -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

@ -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

@ -7,6 +7,10 @@ import {ResponseInterface} from "./responses/response";
import {CommandResponseInterface} from "./responses/comamnds"; import {CommandResponseInterface} from "./responses/comamnds";
import commandsSchema from "./schemas/commands"; import commandsSchema from "./schemas/commands";
import runCommandsSchema from "./schemas/run-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 { export class SMClient {
schemaClient: SchemaClient schemaClient: SchemaClient
@ -40,7 +44,23 @@ export class SMClient {
headers: headers headers: headers
} }
} }
async repeatProcess(data: RepeatProcessRequest): Promise<ResponseInterface> {
let { responseData, headers } = await this.schemaClient.send(repeatProcessSchema, data)
return {
data: responseData as ProcessesResponseInterface[],
headers: headers
}
}
async getProcessOutput(data: ProcessOutputRequest): Promise<ResponseInterface> {
let { responseData, headers } = await this.schemaClient.send(processOutputSchema, data)
return {
data: responseData,
headers: headers
}
}
} }
export let smClient = new SMClient export let smClient = new SMClient
export default smClient export default smClient

@ -85,15 +85,10 @@ export default function Processes() {
refreshLock = false refreshLock = false
} }
let output = async (process: ProcessInterface) => { let output = async (process: ProcessInterface) => {
let response = await fetch(`http://fmw.sipachev.sv/system-monitoring/processes/${process.id}/output`, const { data: output } = await smClient.getProcessOutput({
{ id: process.id
method: 'GET', })
headers: {
'X-Plugin-Token': 'passw0rd',
'X-Pagination-Count': '0',
},
});
const output: string = await response.text()
let a = document.createElement("a"); let a = document.createElement("a");
let file = new Blob([output], {type: 'plain/text'}); let file = new Blob([output], {type: 'plain/text'});
a.href = URL.createObjectURL(file); a.href = URL.createObjectURL(file);
@ -126,18 +121,12 @@ export default function Processes() {
return return
} }
lock = true lock = true
let url = `http://fmw.sipachev.sv/system-monitoring/processes/${selectedProcess.id}/repeat`
let data = { await smClient.repeatProcess({
id: selectedProcess.id,
requestId: dialogId 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 lock = false
setSelectedProcess(null) setSelectedProcess(null)
setOpen(false) setOpen(false)

Loading…
Cancel
Save