mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-27 00:04:37 +08:00
parent
25b1ecbe15
commit
6c3cfe0ff4
3 changed files with 22 additions and 0 deletions
|
@ -371,6 +371,7 @@ export async function getUser(
|
|||
|
||||
const agentLog = buildAgentLog(req);
|
||||
Logger.logToDb("user_data_requested", agentLog, uid);
|
||||
UserDAL.logIpAddress(uid, agentLog.ip, userInfo);
|
||||
|
||||
let inboxUnreadSize = 0;
|
||||
if (req.ctx.configuration.users.inbox.enabled) {
|
||||
|
|
|
@ -1050,3 +1050,21 @@ export async function checkIfUserIsPremium(
|
|||
if (expirationDate === -1) return true; //lifetime
|
||||
return expirationDate > Date.now();
|
||||
}
|
||||
|
||||
export async function logIpAddress(
|
||||
uid: string,
|
||||
ip: string,
|
||||
userInfoOverride?: MonkeyTypes.User
|
||||
): Promise<void> {
|
||||
const user = userInfoOverride ?? (await getUser(uid, "logIpAddress"));
|
||||
const currentIps = user.ips ?? [];
|
||||
const ipIndex = currentIps.indexOf(ip);
|
||||
if (ipIndex !== -1) {
|
||||
currentIps.splice(ipIndex, 1);
|
||||
}
|
||||
currentIps.unshift(ip);
|
||||
if (currentIps.length > 10) {
|
||||
currentIps.pop();
|
||||
}
|
||||
await getUsersCollection().updateOne({ uid }, { $set: { ips: currentIps } });
|
||||
}
|
||||
|
|
3
backend/src/types/types.d.ts
vendored
3
backend/src/types/types.d.ts
vendored
|
@ -61,6 +61,8 @@ declare namespace MonkeyTypes {
|
|||
rewards: AllRewards[];
|
||||
}
|
||||
|
||||
type UserIpHistory = string[];
|
||||
|
||||
interface User {
|
||||
autoBanTimestamps?: number[];
|
||||
addedAt: number;
|
||||
|
@ -98,6 +100,7 @@ declare namespace MonkeyTypes {
|
|||
lastReultHashes?: string[];
|
||||
lbOptOut?: boolean;
|
||||
premium?: PremiumInfo;
|
||||
ips?: UserIpHistory;
|
||||
}
|
||||
|
||||
interface UserStreak {
|
||||
|
|
Loading…
Reference in a new issue