From 69e0f7783000df2edb506ff75b752b631ed50443 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 26 Nov 2023 17:29:53 +0800 Subject: [PATCH] Avoid multiple commands at the same for a stack --- backend/terminal.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/terminal.ts b/backend/terminal.ts index 2b22e69..96a8b01 100644 --- a/backend/terminal.ts +++ b/backend/terminal.ts @@ -5,8 +5,6 @@ import { LimitQueue } from "./utils/limit-queue"; import { DockgeSocket } from "./util-server"; import { allowedCommandList, allowedRawKeys, - getComposeTerminalName, - getCryptoRandomInt, PROGRESS_TERMINAL_ROWS, TERMINAL_COLS, TERMINAL_ROWS @@ -207,14 +205,20 @@ export class Terminal { } public static exec(server : DockgeServer, socket : DockgeSocket | undefined, terminalName : string, file : string, args : string | string[], cwd : string) : Promise { - const terminal = new Terminal(server, terminalName, file, args, cwd); - terminal.rows = PROGRESS_TERMINAL_ROWS; + return new Promise((resolve, reject) => { + // check if terminal exists + if (Terminal.terminalMap.has(terminalName)) { + reject("Another operation is already running, please try again later."); + return; + } - if (socket) { - terminal.join(socket); - } + let terminal = new Terminal(server, terminalName, file, args, cwd); + terminal.rows = PROGRESS_TERMINAL_ROWS; + + if (socket) { + terminal.join(socket); + } - return new Promise((resolve) => { terminal.onExit((exitCode : number) => { resolve(exitCode); });