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