From 228d12a61c5f6a1e58e75fc875c4a8a1f90e7a8f Mon Sep 17 00:00:00 2001 From: UndefinedPony Date: Sun, 22 Dec 2024 19:01:02 +0100 Subject: [PATCH] refactor: code cleanup --- .../settings/web-server/terminal-modal.tsx | 2 +- .../dashboard/settings/web-server/terminal.tsx | 4 +--- apps/dokploy/server/wss/terminal.ts | 14 +++++++------- apps/dokploy/server/wss/utils.ts | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/web-server/terminal-modal.tsx b/apps/dokploy/components/dashboard/settings/web-server/terminal-modal.tsx index 2bfd00a0..7c64ebc0 100644 --- a/apps/dokploy/components/dashboard/settings/web-server/terminal-modal.tsx +++ b/apps/dokploy/components/dashboard/settings/web-server/terminal-modal.tsx @@ -66,7 +66,7 @@ export const TerminalModal = ({ children, serverId }: Props) => { )}
- +
diff --git a/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx b/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx index b6757b9c..e45b73d2 100644 --- a/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx +++ b/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx @@ -41,12 +41,10 @@ export const Terminal: React.FC = ({ id, serverId }) => { const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - const isLocalServer = serverId === "local"; - const urlParams = new URLSearchParams(); urlParams.set("serverId", serverId); - if (isLocalServer) { + if (serverId === "local") { const { port, username } = getLocalServerData(); urlParams.set("port", port.toString()); urlParams.set("username", username); diff --git a/apps/dokploy/server/wss/terminal.ts b/apps/dokploy/server/wss/terminal.ts index fa268124..78cda7ac 100644 --- a/apps/dokploy/server/wss/terminal.ts +++ b/apps/dokploy/server/wss/terminal.ts @@ -3,7 +3,7 @@ import { findServerById, validateWebSocketRequest } from "@dokploy/server"; import { publicIpv4, publicIpv6 } from "public-ip"; import { Client, type ConnectConfig } from "ssh2"; import { WebSocketServer } from "ws"; -import { getLocalServerPrivateKey } from "./utils"; +import { setupLocalServerSSHKey } from "./utils"; export const getPublicIpWithFallback = async () => { // @ts-ignore @@ -69,8 +69,8 @@ export const setupTerminalWebSocketServer = ( return; } - ws.send("Getting private SSH key...\n"); - const privateKey = await getLocalServerPrivateKey(); + ws.send("Setting up private SSH key...\n"); + const privateKey = await setupLocalServerSSHKey(); if (!privateKey) { ws.close(); @@ -92,16 +92,16 @@ export const setupTerminalWebSocketServer = ( return; } - const { ipAddress, port, username, sshKey, sshKeyId } = server; + const { ipAddress: host, port, username, sshKey, sshKeyId } = server; if (!sshKeyId) { throw new Error("No SSH key available for this server"); } connectionDetails = { - host: ipAddress, - port: port, - username: username, + host, + port, + username, privateKey: sshKey?.privateKey, }; } diff --git a/apps/dokploy/server/wss/utils.ts b/apps/dokploy/server/wss/utils.ts index 3172e36e..4971bac2 100644 --- a/apps/dokploy/server/wss/utils.ts +++ b/apps/dokploy/server/wss/utils.ts @@ -25,7 +25,7 @@ export const getShell = () => { }; /** Returns private SSH key for dokploy local server terminal. Uses already created SSH key or generates a new SSH key, also automatically appends the public key to `authorized_keys`, creating the file if needed. */ -export const getLocalServerPrivateKey = async () => { +export const setupLocalServerSSHKey = async () => { try { if (!fs.existsSync(LOCAL_SSH_KEY_PATH)) { // Generate new SSH key if it hasn't been created yet