@@ -3,13 +3,13 @@ import { createSlice } from '@reduxjs/toolkit'
3
3
import { CliOutputFormatterType , cliTexts } from 'uiSrc/constants/cliOutput'
4
4
import { apiService , localStorageService } from 'uiSrc/services'
5
5
import { ApiEndpoints , BrowserStorageItem } from 'uiSrc/constants'
6
- import { cliCommandOutput , cliParseTextResponseWithOffset } from 'uiSrc/utils/cliHelper'
7
- import { getUrl , getApiErrorMessage , isStatusSuccessful } from 'uiSrc/utils'
8
6
import {
9
- SendClusterCommandDto ,
10
- SendClusterCommandResponse ,
11
- SendCommandResponse ,
12
- } from 'apiSrc/modules/cli/dto/cli.dto'
7
+ cliCommandOutput ,
8
+ cliParseTextResponseWithOffset ,
9
+ cliParseTextResponseWithRedirect ,
10
+ } from 'uiSrc/utils/cliHelper'
11
+ import { getApiErrorMessage , getUrl , isStatusSuccessful } from 'uiSrc/utils'
12
+ import { SendClusterCommandDto , SendClusterCommandResponse , SendCommandResponse , } from 'apiSrc/modules/cli/dto/cli.dto'
13
13
14
14
import { AppDispatch , RootState } from '../store'
15
15
import { CommandExecutionStatus , StateCliOutput } from '../interfaces/cli'
@@ -124,6 +124,7 @@ export function sendCliClusterCommandAction(
124
124
) {
125
125
return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
126
126
try {
127
+ const outputFormat = CliOutputFormatterType . Raw
127
128
const state = stateInit ( )
128
129
const { id = '' } = state . connections . instances ?. connectedInstance
129
130
@@ -137,7 +138,7 @@ export function sendCliClusterCommandAction(
137
138
138
139
const {
139
140
data : [
140
- { response, status : dataStatus }
141
+ { response, status : dataStatus , node : nodeOptionsResponse }
141
142
] = [ ] ,
142
143
status
143
144
} = await apiService . post < SendClusterCommandResponse [ ] > (
@@ -147,15 +148,23 @@ export function sendCliClusterCommandAction(
147
148
state . cli . settings ?. cliClientUuid ,
148
149
ApiEndpoints . SEND_CLUSTER_COMMAND
149
150
) ,
150
- { ...options , command, outputFormat : CliOutputFormatterType . Raw }
151
+ { ...options , command, outputFormat }
151
152
)
152
153
153
154
if ( isStatusSuccessful ( status ) ) {
155
+ let isRedirected = false
156
+ if ( options . nodeOptions && nodeOptionsResponse ) {
157
+ const requestNodeAddress = `${ options . nodeOptions . host } :${ options . nodeOptions . port } `
158
+ const responseNodeAddress = `${ nodeOptionsResponse . host } :${ nodeOptionsResponse . port } `
159
+ isRedirected = requestNodeAddress !== responseNodeAddress
160
+ }
154
161
onSuccessAction ?.( )
155
162
dispatch ( sendCliCommandSuccess ( ) )
156
- dispatch (
157
- concatToOutput ( cliParseTextResponseWithOffset ( response , command , dataStatus ) )
158
- )
163
+ const result = outputFormat === CliOutputFormatterType . Raw && isRedirected
164
+ ? cliParseTextResponseWithRedirect ( response , command , dataStatus , nodeOptionsResponse )
165
+ : cliParseTextResponseWithOffset ( response , command , dataStatus )
166
+
167
+ dispatch ( concatToOutput ( result ) )
159
168
}
160
169
} catch ( error ) {
161
170
const errorMessage = getApiErrorMessage ( error )
0 commit comments