Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit c60b917

Browse files
author
clouless
committed
added compressedSize at end of compress messages
1 parent 0ea3244 commit c60b917

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kartoffelstampf-server",
33
"description": "stampf it!",
4-
"version": "0.1.1",
4+
"version": "2.0.0",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/services/UploadFileHelper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export class UploadFileHelper {
2424
return this.TEMPORARY_FILE_PATH + temporaryFile;
2525
}
2626

27+
public static getTemporaryFileSizeInBytes(temporaryFile: string): number {
28+
const fileStats = fs.statSync(this.getFullTemporaryFilePath(temporaryFile));
29+
return fileStats.size;
30+
}
31+
2732
public static isValidTemporaryFileName(temporaryFile: string): boolean {
2833
if (temporaryFile !== undefined &&
2934
temporaryFile !== null &&

src/services/WebSocketCommandService.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ export class WebSocketCommandService {
5757
// Interpret which command to execute => Prevent XSS Injects!
5858
const compressInstruction = JSON.parse(message) as CompressInstruction;
5959
const commandInstruction = this.compressCommandInstruction(compressInstruction);
60-
self.dispatchCommandWithWebsocketResponse(ws, commandInstruction);
60+
self.dispatchCommandWithWebsocketResponse(ws, commandInstruction, compressInstruction);
6161
});
6262
});
6363
}
6464

65-
private dispatchCommandWithWebsocketResponse(ws: WebSocket, commandInstruction: CommandInstruction) {
65+
private dispatchCommandWithWebsocketResponse(
66+
ws: WebSocket,
67+
commandInstruction: CommandInstruction,
68+
compressInstruction: CompressInstruction) {
6669
const cmd = spawn(commandInstruction.command, commandInstruction.commandArguments);
6770
ws.send(JSON.stringify({
6871
payload: {
@@ -108,13 +111,15 @@ export class WebSocketCommandService {
108111
});
109112
cmd.on('exit', (code: Number) => {
110113
try {
114+
const sizeInBytes = UploadFileHelper.getTemporaryFileSizeInBytes(compressInstruction.temporaryFileName);
111115
ws.send(JSON.stringify({
112116
payload: {
113-
exitCode: code.toString(),
114-
text: 'child process exited with code ' + code.toString(),
117+
compressedSize: sizeInBytes,
115118
},
116-
type: 'processStatus',
119+
type: 'compressResult',
117120
}));
121+
// FIXME: Add file to cleanup job so that it is deleted
122+
118123
// close after command is done
119124
ws.close();
120125
} catch (error) {

0 commit comments

Comments
 (0)