add version number to audit

This commit is contained in:
marlon-erler
2024-07-07 18:20:37 +02:00
parent 9a42fc047f
commit 9a9b8f1ee5
2 changed files with 25 additions and 11 deletions
+10 -4
View File
@@ -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]
];
}
@@ -87,7 +91,9 @@ async function main() {
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());
+13 -5
View File
@@ -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`);