add favicons

This commit is contained in:
Lee 2024-01-01 17:08:36 +00:00
parent a3dbd9e689
commit 9fc087beeb
3 changed files with 34 additions and 1 deletions

View File

@ -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
)})`
);
});

View File

@ -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;
}
}

View File

@ -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);
}