Added vip addition endpoint.

This commit is contained in:
Ajay Ramachandran 2019-09-04 14:44:55 -04:00
parent ff0b661f26
commit 83c3a35ce4
2 changed files with 44 additions and 5 deletions

View file

@ -10,8 +10,4 @@ CREATE TABLE IF NOT EXISTS "sponsorTimes" (
"views" INTEGER NOT NULL,
"shadowHidden" INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS "userNames" (
"userID" TEXT NOT NULL,
"userName" TEXT NOT NULL
);
COMMIT;

View file

@ -384,7 +384,7 @@ app.get('/api/shadowBanUser', async function (req, res) {
return;
}
//hash the userIDs
//hash the userID
userID = getHash(userID);
if (userID !== adminUserID) {
@ -419,6 +419,49 @@ app.get('/api/shadowBanUser', async function (req, res) {
res.sendStatus(200);
});
//Endpoint used to make a user a VIP user with special privileges
app.post('/api/addUserAsVIP', async function (req, res) {
let userID = req.query.userID;
let adminUserIDInput = req.query.adminUserID;
let enabled = req.query.enabled;
if (enabled === undefined){
enabled = true;
} else {
enabled = enabled === "true";
}
if (userID == undefined || adminUserIDInput == undefined) {
//invalid request
res.sendStatus(400);
return;
}
//hash the userID
adminUserIDInput = getHash(adminUserIDInput);
if (adminUserIDInput !== adminUserID) {
//not authorized
res.sendStatus(403);
return;
}
//check to see if this user is already a vip
let result = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as userCount FROM vipUsers WHERE userID = ?").get(userID, (err, row) => resolve({err, row}));
});
if (enabled && result.row.userCount == 0) {
//add them to the vip list
db.prepare("INSERT INTO vipUsers VALUES(?)").run(userID);
} else if (!enabled && result.row.userCount > 0) {
//remove them from the shadow ban list
db.prepare("DELETE FROM vipUsers WHERE userID = ?").run(userID);
}
res.sendStatus(200);
});
//Gets all the views added up for one userID
//Useful to see how much one user has contributed
app.get('/api/getViewsForUser', function (req, res) {