@@ -10,8 +10,8 @@ import * as WebSocket from 'ws';
1010import { IServerOptions , Server as WsServer } from 'ws' ;
1111import { CommandInstruction } from '../data/CommandInstruction' ;
1212import { CompressInstruction } from '../data/CompressInstruction' ;
13- import { UploadFileHelper } from './UploadFileHelper' ;
1413import { logger } from './LogService' ;
14+ import { UploadFileHelper } from './UploadFileHelper' ;
1515
1616export class WebSocketCommandService {
1717
@@ -52,7 +52,7 @@ export class WebSocketCommandService {
5252 private init ( ) {
5353 const self = this ;
5454 self . wss . on ( 'connection' , ( ws : WebSocket ) => {
55- ws . on ( 'message' , ( message ) => {
55+ ws . on ( 'message' , ( message : any ) => {
5656 logger . log ( 'debug' , 'received command instruction' , message ) ;
5757 // Interpret which command to execute => Prevent XSS Injects!
5858 const compressInstruction = JSON . parse ( message ) as CompressInstruction ;
@@ -71,6 +71,7 @@ export class WebSocketCommandService {
7171 payload : {
7272 text : commandInstruction . command + ' ' + commandInstruction . commandArguments . join ( ' ' ) ,
7373 } ,
74+ compressInstruction : compressInstruction ,
7475 type : 'cmd' ,
7576 } ) ) ;
7677 cmd . on ( 'error' , ( error : any ) => {
@@ -79,6 +80,7 @@ export class WebSocketCommandService {
7980 payload : {
8081 text : error . toString ( ) ,
8182 } ,
83+ compressInstruction : compressInstruction ,
8284 type : 'stderr' ,
8385 } ) ) ;
8486 } catch ( error ) {
@@ -91,6 +93,7 @@ export class WebSocketCommandService {
9193 payload : {
9294 text : data . toString ( ) ,
9395 } ,
96+ compressInstruction : compressInstruction ,
9497 type : 'stdout' ,
9598 } ) ) ;
9699 } catch ( error ) {
@@ -103,6 +106,7 @@ export class WebSocketCommandService {
103106 payload : {
104107 text : data . toString ( ) ,
105108 } ,
109+ compressInstruction : compressInstruction ,
106110 type : 'stderr' ,
107111 } ) ) ;
108112 } catch ( error ) {
@@ -116,11 +120,15 @@ export class WebSocketCommandService {
116120 payload : {
117121 compressedSize : sizeInBytes ,
118122 } ,
123+ compressInstruction : compressInstruction ,
119124 type : 'compressResult' ,
120125 } ) ) ;
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+ } ) ) ;
124132 } catch ( error ) {
125133 logger . log ( 'error' , 'failed to send ws' , error ) ;
126134 }
0 commit comments