Don't ratelimit VIPs

This commit is contained in:
Ajay Ramachandran
2021-02-18 20:47:26 -05:00
parent 57adcd3c65
commit e21ebd18a6
3 changed files with 24 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import {getFormattedTime} from '../utils/getFormattedTime';
import {getIP} from '../utils/getIP';
import {getHash} from '../utils/getHash';
import {config} from '../config';
import { UserID } from '../types/user.model';
const voteTypes = {
normal: 0,
@@ -214,21 +215,25 @@ function categoryVote(UUID: string, userID: string, isVIP: boolean, isOwnSubmiss
res.sendStatus(200);
}
async function voteOnSponsorTime(req: Request, res: Response) {
export function getUserID(req: Request): UserID {
return req.query.userID as UserID;
}
export async function voteOnSponsorTime(req: Request, res: Response) {
const UUID = req.query.UUID as string;
let userID = req.query.userID as string;
const paramUserID = getUserID(req);
let type = req.query.type !== undefined ? parseInt(req.query.type as string) : undefined;
const category = req.query.category as string;
if (UUID === undefined || userID === undefined || (type === undefined && category === undefined)) {
if (UUID === undefined || paramUserID === undefined || (type === undefined && category === undefined)) {
//invalid request
res.sendStatus(400);
return;
}
//hash the userID
const nonAnonUserID = getHash(userID);
userID = getHash(userID + UUID);
const nonAnonUserID = getHash(paramUserID);
const userID = getHash(paramUserID + UUID);
//x-forwarded-for if this server is behind a proxy
const ip = getIP(req);
@@ -421,8 +426,4 @@ async function voteOnSponsorTime(req: Request, res: Response) {
res.status(500).json({error: 'Internal error creating segment vote'});
}
}
export {
voteOnSponsorTime,
};
}