mirror of
https://github.com/louislam/dockge.git
synced 2025-08-13 23:08:46 +02:00
wip
This commit is contained in:
@ -1,7 +1,27 @@
|
||||
import { Socket } from "socket.io";
|
||||
import { Terminal } from "./terminal";
|
||||
import { randomBytes } from "crypto";
|
||||
import { log } from "./log";
|
||||
import { ERROR_TYPE_VALIDATION } from "./util-common";
|
||||
|
||||
export interface DockgeSocket extends Socket {
|
||||
userID: number;
|
||||
consoleTerminal? : Terminal;
|
||||
}
|
||||
|
||||
// For command line arguments, so they are nullable
|
||||
export interface Arguments {
|
||||
sslKey? : string;
|
||||
sslCert? : string;
|
||||
sslKeyPassphrase? : string;
|
||||
port? : number;
|
||||
hostname? : string;
|
||||
dataDir? : string;
|
||||
}
|
||||
|
||||
// Some config values are required
|
||||
export interface Config extends Arguments {
|
||||
dataDir : string;
|
||||
}
|
||||
|
||||
export function checkLogin(socket : DockgeSocket) {
|
||||
@ -9,3 +29,31 @@ export function checkLogin(socket : DockgeSocket) {
|
||||
throw new Error("You are not logged in.");
|
||||
}
|
||||
}
|
||||
|
||||
export class ValidationError extends Error {
|
||||
constructor(message : string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function callbackError(error : unknown, callback : unknown) {
|
||||
if (typeof(callback) !== "function") {
|
||||
log.error("console", "Callback is not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
callback({
|
||||
ok: false,
|
||||
msg: error.message,
|
||||
});
|
||||
} else if (error instanceof ValidationError) {
|
||||
callback({
|
||||
ok: false,
|
||||
type: ERROR_TYPE_VALIDATION,
|
||||
msg: error.message,
|
||||
});
|
||||
} else {
|
||||
log.debug("console", "Unknown error: " + error);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user