mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: code cleanup
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user