diff --git a/databases/_sponsorTimes.db.sql b/databases/_sponsorTimes.db.sql index ec45877..d0b6977 100644 --- a/databases/_sponsorTimes.db.sql +++ b/databases/_sponsorTimes.db.sql @@ -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; diff --git a/index.js b/index.js index e1ed7ff..6ae3deb 100644 --- a/index.js +++ b/index.js @@ -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) {