add version number to audit
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
processMessage,
|
||||
trackConnection,
|
||||
} from "./websocket-handler";
|
||||
import { writeStatNumber, writeStatString, writeSuccess } from "./utility";
|
||||
import { getVersionNumber, writeStatNumber, writeStatString, writeSuccess } from "./utility";
|
||||
|
||||
import Colors from "colors";
|
||||
import IP from "ip";
|
||||
@@ -16,8 +16,10 @@ import { ServerWebSocket } from "bun";
|
||||
import { getConfig } from "./config-handler";
|
||||
|
||||
// CONFIG
|
||||
const STATIC_DIR = Path.join(Path.dirname(import.meta.path), "static/dist");
|
||||
const DEFAULT_PAGE = "index.html";
|
||||
export const CODE_DIR = Path.dirname(import.meta.path);
|
||||
export const STATIC_DIR = Path.join(CODE_DIR, "static/dist");
|
||||
export const PACKAGE_FILE = Path.join(CODE_DIR, "package.json");
|
||||
export const DEFAULT_PAGE = "index.html";
|
||||
|
||||
// TYPES
|
||||
export type WS = ServerWebSocket<unknown> | WebSocket;
|
||||
@@ -26,6 +28,7 @@ export type WS = ServerWebSocket<unknown> | WebSocket;
|
||||
async function main() {
|
||||
// CONFIG
|
||||
const config = await getConfig();
|
||||
const versionNumber = await getVersionNumber();
|
||||
|
||||
// SERVER
|
||||
const server = Bun.serve({
|
||||
@@ -73,6 +76,7 @@ async function main() {
|
||||
return [
|
||||
["server url", server.url.toString()],
|
||||
["server ip address", IP.address()],
|
||||
["server version", versionNumber]
|
||||
];
|
||||
}
|
||||
|
||||
@@ -85,9 +89,11 @@ async function main() {
|
||||
|
||||
function updateCLI() {
|
||||
console.clear();
|
||||
|
||||
|
||||
console.log(Colors.bold.bgWhite("UNIVERSAL DECENTRALIZED NETWORK"));
|
||||
console.log(Colors.yellow("relevant output is available in the 'logs' file"));
|
||||
console.log(
|
||||
Colors.yellow("relevant output is available in the 'logs' file")
|
||||
);
|
||||
console.log();
|
||||
|
||||
console.log(new Date().toLocaleString());
|
||||
@@ -95,7 +101,7 @@ async function main() {
|
||||
|
||||
getServerStats().forEach((entry) => writeStatString(...entry));
|
||||
console.log();
|
||||
|
||||
|
||||
getWebSocketStats().forEach((entry) => writeStatNumber(...entry));
|
||||
console.log();
|
||||
}
|
||||
|
||||
+13
-5
@@ -1,19 +1,27 @@
|
||||
import Colors from "colors";
|
||||
import Fs from "fs/promises";
|
||||
import { PACKAGE_FILE } from ".";
|
||||
import { WebSocketMessage } from "./websocket-handler";
|
||||
|
||||
// CONFIG
|
||||
const STAT_INDENT = 25;
|
||||
|
||||
// SAFETY
|
||||
export function doIfIsString(
|
||||
data: any,
|
||||
cb: (data: string) => void
|
||||
): void {
|
||||
// MISC
|
||||
export function doIfIsString(data: any, cb: (data: string) => void): void {
|
||||
if (typeof data != "string" || data == "") return;
|
||||
cb(data);
|
||||
}
|
||||
|
||||
export async function getVersionNumber(): Promise<string> {
|
||||
try {
|
||||
const packageString = await Bun.file(PACKAGE_FILE).text();
|
||||
const packageObject = JSON.parse(packageString);
|
||||
return packageObject.version;
|
||||
} catch {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// OUTPUT
|
||||
async function writeToLogFile(message: string): Promise<void> {
|
||||
await Fs.appendFile("logs", `${message}\n`);
|
||||
|
||||
Reference in New Issue
Block a user