Skip to content

Commit

Permalink
Serve count of IPs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Sep 30, 2024
1 parent c8aed44 commit 76394e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']) {
Expand Down

0 comments on commit 76394e2

Please sign in to comment.