Skip to content

Commit

Permalink
refactor: remove unsued files
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Dec 15, 2024
1 parent e643255 commit d20f86f
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 680 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FitAddon } from "xterm-addon-fit";
import "@xterm/xterm/css/xterm.css";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { AttachAddon } from "@xterm/addon-attach";
import { WebLinksAddon } from "@xterm/addon-web-links";

interface Props {
id: string;
Expand All @@ -25,13 +26,11 @@ export const DockerTerminal: React.FC<Props> = ({
}
const term = new Terminal({
cursorBlink: true,
cols: 80,
rows: 30,
lineHeight: 1.4,
convertEol: true,
theme: {
cursor: "transparent",
background: "rgba(0, 0, 0, 0)",
background: "transparent",
},
});
const addonFit = new FitAddon();
Expand All @@ -47,15 +46,16 @@ export const DockerTerminal: React.FC<Props> = ({
term.open(termRef.current);
term.loadAddon(addonFit);
term.loadAddon(addonAttach);
term.loadAddon(new WebLinksAddon());
addonFit.fit();
return () => {
ws.readyState === WebSocket.OPEN && ws.close();
};
}, [containerId, activeWay, id]);

return (
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-4 w-full">
<div className="flex flex-col gap-2 w-full">
<span>
Select way to connect to <b>{containerId}</b>
</span>
Expand All @@ -66,7 +66,7 @@ export const DockerTerminal: React.FC<Props> = ({
</TabsList>
</Tabs>
</div>
<div className="w-full h-full rounded-lg p-2 bg-[#19191A]">
<div className="w-full h-full rounded-lg p-2 border min-h-[50vh]">
<div id={id} ref={termRef} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { api } from "@/utils/api";
import dynamic from "next/dynamic";
import type React from "react";

const Terminal = dynamic(() => import("./terminal").then((e) => e.Terminal), {
const Terminal = dynamic(async () => (await import("./terminal")).Terminal, {
ssr: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useRef } from "react";
import { FitAddon } from "xterm-addon-fit";
import "@xterm/xterm/css/xterm.css";
import { AttachAddon } from "@xterm/addon-attach";
import { WebLinksAddon } from "@xterm/addon-web-links";

interface Props {
id: string;
Expand All @@ -20,13 +21,11 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
}
const term = new XTerm({
cursorBlink: true,
cols: 80,
rows: 30,
lineHeight: 1.4,
convertEol: true,
theme: {
cursor: "transparent",
background: "#19191A",
background: "transparent",
},
});
const addonFit = new FitAddon();
Expand All @@ -42,15 +41,17 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
term.open(termRef.current);
term.loadAddon(addonFit);
term.loadAddon(addonAttach);
term.loadAddon(new WebLinksAddon());
addonFit.fit();

return () => {
ws.readyState === WebSocket.OPEN && ws.close();
};
}, [id, serverId]);

return (
<div className="flex flex-col gap-4">
<div className="w-full h-full bg-input rounded-lg p-2 ">
<div className="flex flex-col gap-4 w-full">
<div className="w-full h-full border rounded-lg p-2 min-h-[50vh]">
<div id={id} ref={termRef} className="rounded-xl" />
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions apps/dokploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"test": "vitest --config __test__/vitest.config.ts"
},
"dependencies": {
"xterm-addon-fit": "0.8.0",
"@xterm/xterm": "^5.3.0",
"xterm": "5.2.1",
"@xterm/addon-attach": "^0.11.0",
"@xterm/addon-web-links": "^0.10.0",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-yaml": "^6.1.1",
"@codemirror/language": "^6.10.1",
Expand Down Expand Up @@ -71,8 +76,6 @@
"@trpc/server": "^10.43.6",
"@uiw/codemirror-theme-github": "^4.22.1",
"@uiw/react-codemirror": "^4.22.1",
"@xterm/addon-attach": "0.10.0",
"@xterm/xterm": "^5.4.0",
"adm-zip": "^0.5.14",
"bcrypt": "5.1.1",
"bullmq": "5.4.2",
Expand Down Expand Up @@ -117,7 +120,6 @@
"undici": "^6.19.2",
"use-resize-observer": "9.1.0",
"ws": "8.16.0",
"xterm-addon-fit": "^0.8.0",
"zod": "^3.23.4",
"zod-form-data": "^2.0.2"
},
Expand Down
12 changes: 6 additions & 6 deletions apps/dokploy/server/wss/docker-container-terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);

Expand Down
77 changes: 34 additions & 43 deletions apps/dokploy/server/wss/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,53 +70,44 @@ export const setupTerminalWebSocketServer = (
let stderr = "";
conn
.once("ready", () => {
conn.shell(
{
term: "terminal",
cols: 80,
rows: 30,
height: 30,
width: 80,
},
(err, stream) => {
if (err) throw err;
conn.shell({}, (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") {
Expand Down
5 changes: 0 additions & 5 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ export * from "./utils/traefik/security";
export * from "./utils/traefik/types";
export * from "./utils/traefik/web-server";

export * from "./wss/docker-container-logs";
export * from "./wss/docker-container-terminal";
export * from "./wss/docker-stats";
export * from "./wss/listen-deployment";
export * from "./wss/terminal";
export * from "./wss/utils";

export * from "./utils/access-log/handler";
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
auth,
users,
} from "@dokploy/server/db/schema";
import { getPublicIpWithFallback } from "@dokploy/server/wss/terminal";
import { getPublicIpWithFallback } from "@dokploy/server/wss/utils";
import { TRPCError } from "@trpc/server";
import * as bcrypt from "bcrypt";
import { eq } from "drizzle-orm";
Expand Down
133 changes: 0 additions & 133 deletions packages/server/src/wss/docker-container-logs.ts

This file was deleted.

Loading

0 comments on commit d20f86f

Please sign in to comment.