From 83d58cd363011e01069e44b64faff314bdcae00a Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 11 Nov 2023 21:29:09 +0800 Subject: [PATCH] Fix composerize --- .../socket-handlers/docker-socket-handler.ts | 22 +++++++++++++++++++ frontend/src/pages/DashboardHome.vue | 22 +++++++++++-------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/backend/socket-handlers/docker-socket-handler.ts b/backend/socket-handlers/docker-socket-handler.ts index e1049e8..e945bef 100644 --- a/backend/socket-handlers/docker-socket-handler.ts +++ b/backend/socket-handlers/docker-socket-handler.ts @@ -3,6 +3,9 @@ import { DockgeServer } from "../dockge-server"; import { callbackError, checkLogin, DockgeSocket, ValidationError } from "../util-server"; import { Stack } from "../stack"; +// @ts-ignore +import composerize from "composerize"; + export class DockerSocketHandler extends SocketHandler { create(socket : DockgeSocket, server : DockgeServer) { @@ -217,6 +220,25 @@ export class DockerSocketHandler extends SocketHandler { callbackError(e, callback); } }); + + // composerize + socket.on("composerize", async (dockerRunCommand : unknown, callback) => { + try { + checkLogin(socket); + + if (typeof(dockerRunCommand) !== "string") { + throw new ValidationError("dockerRunCommand must be a string"); + } + + const composeTemplate = composerize(dockerRunCommand); + callback({ + ok: true, + composeTemplate, + }); + } catch (e) { + callbackError(e, callback); + } + }); } saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, isAdd : unknown) : Stack { diff --git a/frontend/src/pages/DashboardHome.vue b/frontend/src/pages/DashboardHome.vue index 7785ed5..d32ce45 100644 --- a/frontend/src/pages/DashboardHome.vue +++ b/frontend/src/pages/DashboardHome.vue @@ -34,7 +34,6 @@