Revert "refactor: remove unsued files"

This reverts commit d20f86ffe1.
This commit is contained in:
Mauricio Siu
2024-12-14 23:05:19 -06:00
parent d20f86ffe1
commit fc2b0abdb1
15 changed files with 681 additions and 107 deletions

View File

@@ -110,12 +110,12 @@ export const setupDockerContainerTerminalWebSocketServer = (
shell,
["-c", `docker exec -it ${containerId} ${activeWay}`],
{
// name: "xterm-256color",
// cwd: process.env.HOME,
// env: process.env,
// encoding: "utf8",
// cols: 80,
// rows: 30,
name: "xterm-256color",
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
rows: 30,
},
);

View File

@@ -70,44 +70,53 @@ export const setupTerminalWebSocketServer = (
let stderr = "";
conn
.once("ready", () => {
conn.shell({}, (err, stream) => {
if (err) throw err;
conn.shell(
{
term: "terminal",
cols: 80,
rows: 30,
height: 30,
width: 80,
},
(err, stream) => {
if (err) throw err;
stream
.on("close", (code: number, signal: string) => {
ws.send(`\nContainer closed with code: ${code}\n`);
conn.end();
})
.on("data", (data: string) => {
stdout += data.toString();
ws.send(data.toString());
})
.stderr.on("data", (data) => {
stderr += data.toString();
ws.send(data.toString());
console.error("Error: ", data.toString());
stream
.on("close", (code: number, signal: string) => {
ws.send(`\nContainer closed with code: ${code}\n`);
conn.end();
})
.on("data", (data: string) => {
stdout += data.toString();
ws.send(data.toString());
})
.stderr.on("data", (data) => {
stderr += data.toString();
ws.send(data.toString());
console.error("Error: ", data.toString());
});
ws.on("message", (message) => {
try {
let command: string | Buffer[] | Buffer | ArrayBuffer;
if (Buffer.isBuffer(message)) {
command = message.toString("utf8");
} else {
command = message;
}
stream.write(command.toString());
} catch (error) {
// @ts-ignore
const errorMessage = error?.message as unknown as string;
ws.send(errorMessage);
}
});
ws.on("message", (message) => {
try {
let command: string | Buffer[] | Buffer | ArrayBuffer;
if (Buffer.isBuffer(message)) {
command = message.toString("utf8");
} else {
command = message;
}
stream.write(command.toString());
} catch (error) {
// @ts-ignore
const errorMessage = error?.message as unknown as string;
ws.send(errorMessage);
}
});
ws.on("close", () => {
stream.end();
});
});
ws.on("close", () => {
stream.end();
});
},
);
})
.on("error", (err) => {
if (err.level === "client-authentication") {