Serve count of IPs as well

This commit is contained in:
Mia 2024-09-30 13:33:57 -05:00
parent c8aed44d69
commit 76394e23b6
2 changed files with 6 additions and 5 deletions

View File

@ -187,7 +187,7 @@ exports.standings = {
};
/**
* @type {null | ((userid: string) => Promise<{[k: string]: {min: number, max: number}}>)}
* Get IPs (Map<ip, timestamp used>) of a given userid.
* @type {null | ((userid: string) => Promise<{[k: string]: {min: number, max: number, count: number}}>)}
* Get IPs of a given userid.
*/
exports.getuserips = null;

View File

@ -106,7 +106,7 @@ export function escapeHTML(str: string | number) {
}
export class TimeSorter {
private data: Record<string, {min: number, max: number}> = {};
private data: Record<string, {min: number, max: number, count: number}> = {};
add(key: string, timestamp: number) {
if (this.data[key]) {
if (this.data[key].min > timestamp) {
@ -115,11 +115,12 @@ export class TimeSorter {
if (timestamp > this.data[key].max) {
this.data[key].max = timestamp;
}
this.data[key].count++;
} else {
this.data[key] = {min: timestamp, max: timestamp};
this.data[key] = {min: timestamp, max: timestamp, count: 1};
}
}
toJSON() {
toJSON(): TimeSorter['data'] {
return this.data;
}
merge(other: TimeSorter | TimeSorter['data']) {