From cacee2221eac229a56f4a4678eb7292a7b11d777 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 26 Dec 2023 04:01:58 +0800 Subject: [PATCH] Fix ts issues --- backend/agent-socket-handler.ts | 2 +- .../docker-socket-handler.ts | 28 +++++++++---------- .../manage-agent-socket-handler.ts | 24 ++++++++++++---- package.json | 2 ++ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/backend/agent-socket-handler.ts b/backend/agent-socket-handler.ts index ab418ae..7886fe0 100644 --- a/backend/agent-socket-handler.ts +++ b/backend/agent-socket-handler.ts @@ -1,5 +1,5 @@ import { DockgeServer } from "./dockge-server"; -import { AgentSocket } from "../../common/agent-socket"; +import { AgentSocket } from "../common/agent-socket"; import { DockgeSocket } from "./util-server"; export abstract class AgentSocketHandler { diff --git a/backend/agent-socket-handlers/docker-socket-handler.ts b/backend/agent-socket-handlers/docker-socket-handler.ts index 32aea87..93abe85 100644 --- a/backend/agent-socket-handlers/docker-socket-handler.ts +++ b/backend/agent-socket-handlers/docker-socket-handler.ts @@ -112,10 +112,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName); await stack.start(socket); - callback({ + callbackResult({ ok: true, msg: "Started" - }); + }, callback); server.sendStackList(); stack.joinCombinedTerminal(socket); @@ -136,10 +136,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName); await stack.stop(socket); - callback({ + callbackResult({ ok: true, msg: "Stopped" - }); + }, callback); server.sendStackList(); } catch (e) { callbackError(e, callback); @@ -157,10 +157,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName); await stack.restart(socket); - callback({ + callbackResult({ ok: true, msg: "Restarted" - }); + }, callback); server.sendStackList(); } catch (e) { callbackError(e, callback); @@ -178,10 +178,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName); await stack.update(socket); - callback({ + callbackResult({ ok: true, msg: "Updated" - }); + }, callback); server.sendStackList(); } catch (e) { callbackError(e, callback); @@ -199,10 +199,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName); await stack.down(socket); - callback({ + callbackResult({ ok: true, msg: "Downed" - }); + }, callback); server.sendStackList(); } catch (e) { callbackError(e, callback); @@ -220,10 +220,10 @@ export class DockerSocketHandler extends AgentSocketHandler { const stack = await Stack.getStack(server, stackName, true); const serviceStatusList = Object.fromEntries(await stack.getServiceStatusList()); - callback({ + callbackResult({ ok: true, serviceStatusList, - }); + }, callback); } catch (e) { callbackError(e, callback); } @@ -234,10 +234,10 @@ export class DockerSocketHandler extends AgentSocketHandler { try { checkLogin(socket); const dockerNetworkList = await server.getDockerNetworkList(); - callback({ + callbackResult({ ok: true, dockerNetworkList, - }); + }, callback); } catch (e) { callbackError(e, callback); } diff --git a/backend/socket-handlers/manage-agent-socket-handler.ts b/backend/socket-handlers/manage-agent-socket-handler.ts index a20235f..6f8fef4 100644 --- a/backend/socket-handlers/manage-agent-socket-handler.ts +++ b/backend/socket-handlers/manage-agent-socket-handler.ts @@ -1,16 +1,23 @@ import { SocketHandler } from "../socket-handler.js"; import { DockgeServer } from "../dockge-server"; import { log } from "../log"; -import { callbackError, checkLogin, DockgeSocket } from "../util-server"; +import { callbackError, callbackResult, checkLogin, DockgeSocket } from "../util-server"; +import { LooseObject } from "../../common/util-common"; export class ManageAgentSocketHandler extends SocketHandler { create(socket : DockgeSocket, server : DockgeServer) { // addAgent - socket.on("addAgent", async (data : unknown, callback : unknown) => { + socket.on("addAgent", async (requestData : unknown, callback : unknown) => { try { log.debug("manage-agent-socket-handler", "addAgent"); checkLogin(socket); + + if (typeof(requestData) !== "object") { + throw new Error("Data must be an object"); + } + + let data = requestData as LooseObject; let manager = socket.instanceManager; await manager.test(data.url, data.username, data.password); await manager.add(data.url, data.username, data.password); @@ -23,11 +30,11 @@ export class ManageAgentSocketHandler extends SocketHandler { server.disconnectAllSocketClients(undefined, socket.id); manager.sendAgentList(); - callback({ + callbackResult({ ok: true, msg: "agentAddedSuccessfully", msgi18n: true, - }); + }, callback); } catch (e) { callbackError(e, callback); @@ -39,17 +46,22 @@ export class ManageAgentSocketHandler extends SocketHandler { try { log.debug("manage-agent-socket-handler", "removeAgent"); checkLogin(socket); + + if (typeof(url) !== "string") { + throw new Error("URL must be a string"); + } + let manager = socket.instanceManager; await manager.remove(url); server.disconnectAllSocketClients(undefined, socket.id); manager.sendAgentList(); - callback({ + callbackResult({ ok: true, msg: "agentRemovedSuccessfully", msgi18n: true, - }); + }, callback); } catch (e) { callbackError(e, callback); } diff --git a/package.json b/package.json index d75f858..149a47a 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,11 @@ "dev:backend": "cross-env NODE_ENV=development tsx watch --inspect ./backend/index.ts", "dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts", "release-final": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && pnpm run build:frontend && npm run build:docker", + "release-beta": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && pnpm run build:frontend && npm run build:docker-beta", "build:frontend": "vite build --config ./frontend/vite.config.ts", "build:docker-base": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:base -f ./docker/Base.Dockerfile . --push", "build:docker": "node ./extra/env2arg.js docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -t louislam/dockge:1 -t louislam/dockge:$VERSION --target release -f ./docker/Dockerfile . --push", + "build:docker-beta": "node ./extra/env2arg.js docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:beta -t louislam/dockge:$VERSION --target release -f ./docker/Dockerfile . --push", "build:docker-nightly": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:nightly --target nightly -f ./docker/Dockerfile . --push", "build:healthcheck": "docker buildx build -f docker/BuildHealthCheck.Dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:build-healthcheck . --push", "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest",