diff --git a/src/routes/shadowBanUser.js b/src/routes/shadowBanUser.js index 4029885..ba5052e 100644 --- a/src/routes/shadowBanUser.js +++ b/src/routes/shadowBanUser.js @@ -8,6 +8,7 @@ var getHash = require('../utils/getHash.js'); module.exports = async function shadowBanUser(req, res) { let userID = req.query.userID; + let hashedIP = req.query.hashedIP; let adminUserIDInput = req.query.adminUserID; let enabled = req.query.enabled; @@ -20,7 +21,7 @@ module.exports = async function shadowBanUser(req, res) { //if enabled is false and the old submissions should be made visible again let unHideOldSubmissions = req.query.unHideOldSubmissions !== "false"; - if (adminUserIDInput == undefined || userID == undefined) { + if (adminUserIDInput == undefined || (userID == undefined && hashedIP == undefined)) { //invalid request res.sendStatus(400); return; @@ -35,27 +36,57 @@ module.exports = async function shadowBanUser(req, res) { return; } - //check to see if this user is already shadowbanned - let row = privateDB.prepare('get', "SELECT count(*) as userCount FROM shadowBannedUsers WHERE userID = ?", [userID]); + if (userID) { + //check to see if this user is already shadowbanned + let row = privateDB.prepare('get', "SELECT count(*) as userCount FROM shadowBannedUsers WHERE userID = ?", [userID]); - if (enabled && row.userCount == 0) { - //add them to the shadow ban list + if (enabled && row.userCount == 0) { + //add them to the shadow ban list - //add it to the table - privateDB.prepare('run', "INSERT INTO shadowBannedUsers VALUES(?)", [userID]); + //add it to the table + privateDB.prepare('run', "INSERT INTO shadowBannedUsers VALUES(?)", [userID]); - //find all previous submissions and hide them - if (unHideOldSubmissions) { + //find all previous submissions and hide them + if (unHideOldSubmissions) { db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?", [userID]); - } - } else if (!enabled && row.userCount > 0) { - //remove them from the shadow ban list - privateDB.prepare('run', "DELETE FROM shadowBannedUsers WHERE userID = ?", [userID]); + } + } else if (!enabled && row.userCount > 0) { + //remove them from the shadow ban list + privateDB.prepare('run', "DELETE FROM shadowBannedUsers WHERE userID = ?", [userID]); - //find all previous submissions and unhide them - if (unHideOldSubmissions) { - db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]); - } + //find all previous submissions and unhide them + if (unHideOldSubmissions) { + db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]); + } + } + } else if (hashedIP) { + //check to see if this user is already shadowbanned + // let row = privateDB.prepare('get', "SELECT count(*) as userCount FROM shadowBannedIPs WHERE hashedIP = ?", [hashedIP]); + + // if (enabled && row.userCount == 0) { + if (enabled) { + //add them to the shadow ban list + + //add it to the table + // privateDB.prepare('run', "INSERT INTO shadowBannedIPs VALUES(?)", [hashedIP]); + + + + //find all previous submissions and hide them + if (unHideOldSubmissions) { + db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE timeSubmitted IN " + + "(SELECT privateDB.timeSubmitted FROM sponsorTimes LEFT JOIN privateDB.sponsorTimes as privateDB ON sponsorTimes.timeSubmitted=privateDB.timeSubmitted " + + "WHERE privateDB.hashedIP = ?)", [hashedIP]); + } + } else if (!enabled && row.userCount > 0) { + // //remove them from the shadow ban list + // privateDB.prepare('run', "DELETE FROM shadowBannedUsers WHERE userID = ?", [userID]); + + // //find all previous submissions and unhide them + // if (unHideOldSubmissions) { + // db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]); + // } + } } res.sendStatus(200);