mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 07:27:01 +03:00
Changed shadow ban user endpoint to use new naming scheme
This commit is contained in:
18
index.js
18
index.js
@@ -390,7 +390,7 @@ app.get('/api/getUsername', function (req, res) {
|
|||||||
//Endpoint used to hide a certain user's data
|
//Endpoint used to hide a certain user's data
|
||||||
app.get('/api/shadowBanUser', async function (req, res) {
|
app.get('/api/shadowBanUser', async function (req, res) {
|
||||||
let userID = req.query.userID;
|
let userID = req.query.userID;
|
||||||
let shadowUserID = req.query.shadowUserID;
|
let adminUserIDInput = req.query.adminUserID;
|
||||||
|
|
||||||
let enabled = req.query.enabled;
|
let enabled = req.query.enabled;
|
||||||
if (enabled === undefined){
|
if (enabled === undefined){
|
||||||
@@ -407,16 +407,16 @@ app.get('/api/shadowBanUser', async function (req, res) {
|
|||||||
unHideOldSubmissions = unHideOldSubmissions === "true";
|
unHideOldSubmissions = unHideOldSubmissions === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userID == undefined || shadowUserID == undefined) {
|
if (adminUserIDInput == undefined || userID == undefined) {
|
||||||
//invalid request
|
//invalid request
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//hash the userID
|
//hash the userID
|
||||||
userID = getHash(userID);
|
adminUserIDInput = getHash(adminUserIDInput);
|
||||||
|
|
||||||
if (userID !== adminUserID) {
|
if (adminUserIDInput !== adminUserID) {
|
||||||
//not authorized
|
//not authorized
|
||||||
res.sendStatus(403);
|
res.sendStatus(403);
|
||||||
return;
|
return;
|
||||||
@@ -424,24 +424,24 @@ app.get('/api/shadowBanUser', async function (req, res) {
|
|||||||
|
|
||||||
//check to see if this user is already shadowbanned
|
//check to see if this user is already shadowbanned
|
||||||
let result = await new Promise((resolve, reject) => {
|
let result = await new Promise((resolve, reject) => {
|
||||||
privateDB.prepare("SELECT count(*) as userCount FROM shadowBannedUsers WHERE userID = ?").get(shadowUserID, (err, row) => resolve({err, row}));
|
privateDB.prepare("SELECT count(*) as userCount FROM shadowBannedUsers WHERE userID = ?").get(userID, (err, row) => resolve({err, row}));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (enabled && result.row.userCount == 0) {
|
if (enabled && result.row.userCount == 0) {
|
||||||
//add them to the shadow ban list
|
//add them to the shadow ban list
|
||||||
|
|
||||||
//add it to the table
|
//add it to the table
|
||||||
privateDB.prepare("INSERT INTO shadowBannedUsers VALUES(?)").run(shadowUserID);
|
privateDB.prepare("INSERT INTO shadowBannedUsers VALUES(?)").run(userID);
|
||||||
|
|
||||||
//find all previous submissions and hide them
|
//find all previous submissions and hide them
|
||||||
db.prepare("UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?").run(shadowUserID);
|
db.prepare("UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?").run(userID);
|
||||||
} else if (!enabled && result.row.userCount > 0) {
|
} else if (!enabled && result.row.userCount > 0) {
|
||||||
//remove them from the shadow ban list
|
//remove them from the shadow ban list
|
||||||
privateDB.prepare("DELETE FROM shadowBannedUsers WHERE userID = ?").run(shadowUserID);
|
privateDB.prepare("DELETE FROM shadowBannedUsers WHERE userID = ?").run(userID);
|
||||||
|
|
||||||
//find all previous submissions and unhide them
|
//find all previous submissions and unhide them
|
||||||
if (unHideOldSubmissions) {
|
if (unHideOldSubmissions) {
|
||||||
db.prepare("UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?").run(shadowUserID);
|
db.prepare("UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?").run(userID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user