import { WebSocketMessageParam } from "@/src/types";
import sendData from "../(utils)/send-data";
import sendError from "../(utils)/send-error";
import grabTtydInfo from "@/src/functions/ttyd/grab-ttyd-info";

export default async function socketClientRelayPm2Logs({
    ws,
    data,
}: WebSocketMessageParam) {
    try {
        const user = ws.data.user;

        const ttyd = await grabTtydInfo({
            cmd: `pm2 logs`,
            user,
        });

        sendData(ws, {
            event: "server:relay-pm2-logs",
            ttyd,
        });
    } catch (error: any) {
        sendError(ws, "Relay Shell Error! " + error.message);
    }
}
