From 9fc087beebbebcd7fe88233a1c7dd90ce85ed25f Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 1 Jan 2024 17:08:36 +0000 Subject: [PATCH] add favicons --- src/index.ts | 10 +++++++++- src/server/server.ts | 15 +++++++++++++++ src/utils/timeUtils.ts | 10 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index f50f9c5..76f32b8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import Database from "./database/database"; import Scanner from "./scanner/scanner"; import ServerManager from "./server/serverManager"; +import { formatTimestamp } from "./utils/timeUtils"; /** * The database instance. @@ -17,5 +18,12 @@ new Scanner(); serverManager.getServers().forEach((server) => { const record = database.getRecord(server.getID()); - console.log(`Record for "${server.getName()}": ${record?.playerCount}`); + if (!record) { + return; + } + console.log( + `Record for "${server.getName()}": ${record.playerCount} (${formatTimestamp( + record.timestamp + )})` + ); }); diff --git a/src/server/server.ts b/src/server/server.ts index 1336a0b..d144a46 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -63,6 +63,11 @@ export default class Server { */ private type: ServerType; + /** + * The favicon of the server. + */ + private favicon: string | undefined; + /** * The resolved server information from * DNS records for a PC server. @@ -142,6 +147,7 @@ export default class Server { return reject(err); } + this.favicon = res.favicon; // Set the favicon resolve({ timestamp: Date.now(), ip: ip, @@ -229,4 +235,13 @@ export default class Server { public getType(): ServerType { return this.type; } + + /** + * Returns the favicon of the server. + * + * @returns the favicon + */ + public getFavicon(): string | undefined { + return this.favicon; + } } diff --git a/src/utils/timeUtils.ts b/src/utils/timeUtils.ts index 938ecad..3fc11f8 100644 --- a/src/utils/timeUtils.ts +++ b/src/utils/timeUtils.ts @@ -6,3 +6,13 @@ export function getFormattedDate() { return new Date().toISOString().slice(0, 10); } + +/** + * Formats a timestamp as YYYY-MM-DD. + * + * @param timestamp the timestamp + * @returns the formatted timestamp + */ +export function formatTimestamp(timestamp: number) { + return new Date(timestamp).toISOString().slice(0, 10); +}