migrate to typescript

This commit is contained in:
Dainius Daukševičius
2020-10-17 21:56:54 +03:00
committed by Dainius Dauksevicius
parent c462323dd5
commit 08d27265fc
120 changed files with 5002 additions and 4711 deletions

View File

@@ -0,0 +1,41 @@
import {getHash} from '../utils/getHash';
import {db} from '../databases/databases';
import {config} from '../config';
import {Request, Response} from 'express';
export async function addUserAsVIP(req: Request, res: Response) {
const userID = req.query.userID as string;
let adminUserIDInput = req.query.adminUserID as string;
const enabled = req.query.enabled === undefined
? false
: req.query.enabled === 'true';
if (userID == undefined || adminUserIDInput == undefined) {
//invalid request
res.sendStatus(400);
return;
}
//hash the userID
adminUserIDInput = getHash(adminUserIDInput);
if (adminUserIDInput !== config.adminUserID) {
//not authorized
res.sendStatus(403);
return;
}
//check to see if this user is already a vip
const row = db.prepare('get', "SELECT count(*) as userCount FROM vipUsers WHERE userID = ?", [userID]);
if (enabled && row.userCount == 0) {
//add them to the vip list
db.prepare('run', "INSERT INTO vipUsers VALUES(?)", [userID]);
} else if (!enabled && row.userCount > 0) {
//remove them from the shadow ban list
db.prepare('run', "DELETE FROM vipUsers WHERE userID = ?", [userID]);
}
res.sendStatus(200);
}