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

@ -1,6 +1,7 @@
import Database from "./database/database"; import Database from "./database/database";
import Scanner from "./scanner/scanner"; import Scanner from "./scanner/scanner";
import ServerManager from "./server/serverManager"; import ServerManager from "./server/serverManager";
import { formatTimestamp } from "./utils/timeUtils";
/** /**
* The database instance. * The database instance.
@ -17,5 +18,12 @@ new Scanner();
serverManager.getServers().forEach((server) => { serverManager.getServers().forEach((server) => {
const record = database.getRecord(server.getID()); 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
)})`
);
}); });

@ -63,6 +63,11 @@ export default class Server {
*/ */
private type: ServerType; private type: ServerType;
/**
* The favicon of the server.
*/
private favicon: string | undefined;
/** /**
* The resolved server information from * The resolved server information from
* DNS records for a PC server. * DNS records for a PC server.
@ -142,6 +147,7 @@ export default class Server {
return reject(err); return reject(err);
} }
this.favicon = res.favicon; // Set the favicon
resolve({ resolve({
timestamp: Date.now(), timestamp: Date.now(),
ip: ip, ip: ip,
@ -229,4 +235,13 @@ export default class Server {
public getType(): ServerType { public getType(): ServerType {
return this.type; return this.type;
} }
/**
* Returns the favicon of the server.
*
* @returns the favicon
*/
public getFavicon(): string | undefined {
return this.favicon;
}
} }

@ -6,3 +6,13 @@
export function getFormattedDate() { export function getFormattedDate() {
return new Date().toISOString().slice(0, 10); 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);
}