Multiple Dockge instances (#200)

This commit is contained in:
Louis Lam
2023-12-26 04:12:44 +08:00
committed by GitHub
parent 80e885e85d
commit de2de0573b
38 changed files with 1525 additions and 597 deletions

View File

@@ -2,10 +2,11 @@ import { Socket } from "socket.io";
import { Terminal } from "./terminal";
import { randomBytes } from "crypto";
import { log } from "./log";
import { ERROR_TYPE_VALIDATION } from "./util-common";
import { ERROR_TYPE_VALIDATION } from "../common/util-common";
import { R } from "redbean-node";
import { verifyPassword } from "./password-hash";
import fs from "fs";
import { AgentManager } from "./agent-manager";
export interface JWTDecoded {
username : string;
@@ -15,6 +16,9 @@ export interface JWTDecoded {
export interface DockgeSocket extends Socket {
userID: number;
consoleTerminal? : Terminal;
instanceManager : AgentManager;
endpoint : string;
emitAgent : (eventName : string, ...args : unknown[]) => void;
}
// For command line arguments, so they are nullable
@@ -56,18 +60,28 @@ export function callbackError(error : unknown, callback : unknown) {
callback({
ok: false,
msg: error.message,
msgi18n: true,
});
} else if (error instanceof ValidationError) {
callback({
ok: false,
type: ERROR_TYPE_VALIDATION,
msg: error.message,
msgi18n: true,
});
} else {
log.debug("console", "Unknown error: " + error);
}
}
export function callbackResult(result : unknown, callback : unknown) {
if (typeof(callback) !== "function") {
log.error("console", "Callback is not a function");
return;
}
callback(result);
}
export async function doubleCheckPassword(socket : DockgeSocket, currentPassword : unknown) {
if (typeof currentPassword !== "string") {
throw new Error("Wrong data type?");