refactor: code cleanup

This commit is contained in:
UndefinedPony
2024-12-22 19:01:02 +01:00
parent fd0a9b8b58
commit 228d12a61c
4 changed files with 10 additions and 12 deletions

View File

@@ -66,7 +66,7 @@ export const TerminalModal = ({ children, serverId }: Props) => {
)}
<div className="flex flex-col gap-4 h-[552px]">
<Terminal key={terminalKey} id="terminal" serverId={serverId} />
<Terminal id="terminal" key={terminalKey} serverId={serverId} />
</div>
</DialogContent>
</Dialog>

View File

@@ -41,12 +41,10 @@ export const Terminal: React.FC<Props> = ({ 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);

View File

@@ -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,
};
}

View File

@@ -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