Fix ts issues

This commit is contained in:
Louis Lam 2023-12-26 04:01:58 +08:00
parent fa0a4f8ccf
commit cacee2221e
4 changed files with 35 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import { DockgeServer } from "./dockge-server"; import { DockgeServer } from "./dockge-server";
import { AgentSocket } from "../../common/agent-socket"; import { AgentSocket } from "../common/agent-socket";
import { DockgeSocket } from "./util-server"; import { DockgeSocket } from "./util-server";
export abstract class AgentSocketHandler { export abstract class AgentSocketHandler {

View file

@ -112,10 +112,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName); const stack = await Stack.getStack(server, stackName);
await stack.start(socket); await stack.start(socket);
callback({ callbackResult({
ok: true, ok: true,
msg: "Started" msg: "Started"
}); }, callback);
server.sendStackList(); server.sendStackList();
stack.joinCombinedTerminal(socket); stack.joinCombinedTerminal(socket);
@ -136,10 +136,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName); const stack = await Stack.getStack(server, stackName);
await stack.stop(socket); await stack.stop(socket);
callback({ callbackResult({
ok: true, ok: true,
msg: "Stopped" msg: "Stopped"
}); }, callback);
server.sendStackList(); server.sendStackList();
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
@ -157,10 +157,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName); const stack = await Stack.getStack(server, stackName);
await stack.restart(socket); await stack.restart(socket);
callback({ callbackResult({
ok: true, ok: true,
msg: "Restarted" msg: "Restarted"
}); }, callback);
server.sendStackList(); server.sendStackList();
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
@ -178,10 +178,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName); const stack = await Stack.getStack(server, stackName);
await stack.update(socket); await stack.update(socket);
callback({ callbackResult({
ok: true, ok: true,
msg: "Updated" msg: "Updated"
}); }, callback);
server.sendStackList(); server.sendStackList();
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
@ -199,10 +199,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName); const stack = await Stack.getStack(server, stackName);
await stack.down(socket); await stack.down(socket);
callback({ callbackResult({
ok: true, ok: true,
msg: "Downed" msg: "Downed"
}); }, callback);
server.sendStackList(); server.sendStackList();
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
@ -220,10 +220,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
const stack = await Stack.getStack(server, stackName, true); const stack = await Stack.getStack(server, stackName, true);
const serviceStatusList = Object.fromEntries(await stack.getServiceStatusList()); const serviceStatusList = Object.fromEntries(await stack.getServiceStatusList());
callback({ callbackResult({
ok: true, ok: true,
serviceStatusList, serviceStatusList,
}); }, callback);
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
} }
@ -234,10 +234,10 @@ export class DockerSocketHandler extends AgentSocketHandler {
try { try {
checkLogin(socket); checkLogin(socket);
const dockerNetworkList = await server.getDockerNetworkList(); const dockerNetworkList = await server.getDockerNetworkList();
callback({ callbackResult({
ok: true, ok: true,
dockerNetworkList, dockerNetworkList,
}); }, callback);
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
} }

View file

@ -1,16 +1,23 @@
import { SocketHandler } from "../socket-handler.js"; import { SocketHandler } from "../socket-handler.js";
import { DockgeServer } from "../dockge-server"; import { DockgeServer } from "../dockge-server";
import { log } from "../log"; 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 { export class ManageAgentSocketHandler extends SocketHandler {
create(socket : DockgeSocket, server : DockgeServer) { create(socket : DockgeSocket, server : DockgeServer) {
// addAgent // addAgent
socket.on("addAgent", async (data : unknown, callback : unknown) => { socket.on("addAgent", async (requestData : unknown, callback : unknown) => {
try { try {
log.debug("manage-agent-socket-handler", "addAgent"); log.debug("manage-agent-socket-handler", "addAgent");
checkLogin(socket); checkLogin(socket);
if (typeof(requestData) !== "object") {
throw new Error("Data must be an object");
}
let data = requestData as LooseObject;
let manager = socket.instanceManager; let manager = socket.instanceManager;
await manager.test(data.url, data.username, data.password); await manager.test(data.url, data.username, data.password);
await manager.add(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); server.disconnectAllSocketClients(undefined, socket.id);
manager.sendAgentList(); manager.sendAgentList();
callback({ callbackResult({
ok: true, ok: true,
msg: "agentAddedSuccessfully", msg: "agentAddedSuccessfully",
msgi18n: true, msgi18n: true,
}); }, callback);
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
@ -39,17 +46,22 @@ export class ManageAgentSocketHandler extends SocketHandler {
try { try {
log.debug("manage-agent-socket-handler", "removeAgent"); log.debug("manage-agent-socket-handler", "removeAgent");
checkLogin(socket); checkLogin(socket);
if (typeof(url) !== "string") {
throw new Error("URL must be a string");
}
let manager = socket.instanceManager; let manager = socket.instanceManager;
await manager.remove(url); await manager.remove(url);
server.disconnectAllSocketClients(undefined, socket.id); server.disconnectAllSocketClients(undefined, socket.id);
manager.sendAgentList(); manager.sendAgentList();
callback({ callbackResult({
ok: true, ok: true,
msg: "agentRemovedSuccessfully", msg: "agentRemovedSuccessfully",
msgi18n: true, msgi18n: true,
}); }, callback);
} catch (e) { } catch (e) {
callbackError(e, callback); callbackError(e, callback);
} }

View file

@ -14,9 +14,11 @@
"dev:backend": "cross-env NODE_ENV=development tsx watch --inspect ./backend/index.ts", "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", "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-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: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-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": "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: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", "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", "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest",