mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
Merge pull request #21 from ajayyy/experimental
Fixed duplicate vote check being broken
This commit is contained in:
12
index.js
12
index.js
@@ -185,10 +185,10 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
|
|||||||
let hashedIP = getHash(ip + globalSalt);
|
let hashedIP = getHash(ip + globalSalt);
|
||||||
|
|
||||||
//check if vote has already happened
|
//check if vote has already happened
|
||||||
privateDB.prepare("SELECT type FROM votes WHERE userID = ? AND UUID = ?").get(userID, UUID, function(err, row) {
|
privateDB.prepare("SELECT type FROM votes WHERE userID = ? AND UUID = ?").get(userID, UUID, function(err, votesRow) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
|
|
||||||
if (row != undefined && row.type == type) {
|
if (votesRow != undefined && votesRow.type == type) {
|
||||||
//they have already done this exact vote
|
//they have already done this exact vote
|
||||||
res.status(405).send("Duplicate Vote");
|
res.status(405).send("Duplicate Vote");
|
||||||
return;
|
return;
|
||||||
@@ -209,11 +209,11 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
|
|||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (row != undefined) {
|
if (votesRow != undefined) {
|
||||||
if (row.type == 1) {
|
if (votesRow.type == 1) {
|
||||||
//upvote
|
//upvote
|
||||||
oldIncrementAmount = 1;
|
oldIncrementAmount = 1;
|
||||||
} else if (row.type == 0) {
|
} else if (votesRow.type == 0) {
|
||||||
//downvote
|
//downvote
|
||||||
oldIncrementAmount = -1;
|
oldIncrementAmount = -1;
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//update the votes table
|
//update the votes table
|
||||||
if (row != undefined) {
|
if (votesRow != undefined) {
|
||||||
privateDB.prepare("UPDATE votes SET type = ? WHERE userID = ? AND UUID = ?").run(type, userID, UUID);
|
privateDB.prepare("UPDATE votes SET type = ? WHERE userID = ? AND UUID = ?").run(type, userID, UUID);
|
||||||
} else {
|
} else {
|
||||||
privateDB.prepare("INSERT INTO votes VALUES(?, ?, ?, ?)").run(UUID, userID, hashedIP, type);
|
privateDB.prepare("INSERT INTO votes VALUES(?, ?, ?, ?)").run(UUID, userID, hashedIP, type);
|
||||||
|
|||||||
Reference in New Issue
Block a user