@@ -10,8 +10,8 @@ import * as WebSocket from 'ws';
10
10
import { IServerOptions , Server as WsServer } from 'ws' ;
11
11
import { CommandInstruction } from '../data/CommandInstruction' ;
12
12
import { CompressInstruction } from '../data/CompressInstruction' ;
13
- import { UploadFileHelper } from './UploadFileHelper' ;
14
13
import { logger } from './LogService' ;
14
+ import { UploadFileHelper } from './UploadFileHelper' ;
15
15
16
16
export class WebSocketCommandService {
17
17
@@ -52,7 +52,7 @@ export class WebSocketCommandService {
52
52
private init ( ) {
53
53
const self = this ;
54
54
self . wss . on ( 'connection' , ( ws : WebSocket ) => {
55
- ws . on ( 'message' , ( message ) => {
55
+ ws . on ( 'message' , ( message : any ) => {
56
56
logger . log ( 'debug' , 'received command instruction' , message ) ;
57
57
// Interpret which command to execute => Prevent XSS Injects!
58
58
const compressInstruction = JSON . parse ( message ) as CompressInstruction ;
@@ -71,6 +71,7 @@ export class WebSocketCommandService {
71
71
payload : {
72
72
text : commandInstruction . command + ' ' + commandInstruction . commandArguments . join ( ' ' ) ,
73
73
} ,
74
+ compressInstruction : compressInstruction ,
74
75
type : 'cmd' ,
75
76
} ) ) ;
76
77
cmd . on ( 'error' , ( error : any ) => {
@@ -79,6 +80,7 @@ export class WebSocketCommandService {
79
80
payload : {
80
81
text : error . toString ( ) ,
81
82
} ,
83
+ compressInstruction : compressInstruction ,
82
84
type : 'stderr' ,
83
85
} ) ) ;
84
86
} catch ( error ) {
@@ -91,6 +93,7 @@ export class WebSocketCommandService {
91
93
payload : {
92
94
text : data . toString ( ) ,
93
95
} ,
96
+ compressInstruction : compressInstruction ,
94
97
type : 'stdout' ,
95
98
} ) ) ;
96
99
} catch ( error ) {
@@ -103,6 +106,7 @@ export class WebSocketCommandService {
103
106
payload : {
104
107
text : data . toString ( ) ,
105
108
} ,
109
+ compressInstruction : compressInstruction ,
106
110
type : 'stderr' ,
107
111
} ) ) ;
108
112
} catch ( error ) {
@@ -116,11 +120,15 @@ export class WebSocketCommandService {
116
120
payload : {
117
121
compressedSize : sizeInBytes ,
118
122
} ,
123
+ compressInstruction : compressInstruction ,
119
124
type : 'compressResult' ,
120
125
} ) ) ;
121
- // Cleanup is done in UploadFileHelper => one hour after upload file is deleted
122
- // close after command is done
123
- ws . close ( ) ;
126
+ // We unsubscribe on DONE in Frontend
127
+ ws . send ( JSON . stringify ( {
128
+ payload : { } ,
129
+ compressInstruction : compressInstruction ,
130
+ type : 'DONE' ,
131
+ } ) ) ;
124
132
} catch ( error ) {
125
133
logger . log ( 'error' , 'failed to send ws' , error ) ;
126
134
}
0 commit comments