From b9d879330a789a52542a989b1d543d31c0f20461 Mon Sep 17 00:00:00 2001 From: Khairul Hidayat Date: Wed, 6 Nov 2024 09:50:41 +0000 Subject: [PATCH] feat: update using gofiber --- .../containers/interactive-session.tsx | 5 +- frontend/components/containers/terminal.tsx | 23 ++- server/go.mod | 23 ++- server/go.sum | 43 +++- server/lib/ssh-session.go | 162 +++++++++++++++ server/main.go | 184 +++--------------- 6 files changed, 275 insertions(+), 165 deletions(-) create mode 100644 server/lib/ssh-session.go diff --git a/frontend/components/containers/interactive-session.tsx b/frontend/components/containers/interactive-session.tsx index 5312f32..f5e3c15 100644 --- a/frontend/components/containers/interactive-session.tsx +++ b/frontend/components/containers/interactive-session.tsx @@ -1,4 +1,3 @@ -import { View, Text } from "react-native"; import React from "react"; import Terminal from "./terminal"; import { BASE_WS_URL } from "@/lib/api"; @@ -19,7 +18,9 @@ const InteractiveSession = ({ type, options }: Props) => { serverId: options.serverId, token: "token", }); - return ; + return ( + + ); default: throw new Error("Unknown interactive session type"); diff --git a/frontend/components/containers/terminal.tsx b/frontend/components/containers/terminal.tsx index b38c19e..0defd70 100644 --- a/frontend/components/containers/terminal.tsx +++ b/frontend/components/containers/terminal.tsx @@ -26,20 +26,33 @@ const Keys = { Tab: "\x09", }; -type TerminalProps = ComponentPropsWithoutRef & { +type XTermJsProps = { + client: "xtermjs"; wsUrl: string; }; -const Terminal = ({ wsUrl, style, ...props }: TerminalProps) => { - const ref = React.useRef(null); +type TerminalProps = ComponentPropsWithoutRef & XTermJsProps; + +const Terminal = ({ client, style, ...props }: TerminalProps) => { + const xtermRef = React.useRef(null); const send = (data: string) => { - ref.current?.send(data); + switch (client) { + case "xtermjs": + xtermRef.current?.send(data); + break; + } }; return ( - + {client === "xtermjs" && ( + + )}