mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 21:17:15 +03:00
Merge pull request #20 from ajayyy/experimental
Made downvote more powerful if there are some views or votes already
This commit is contained in:
30
index.js
30
index.js
@@ -219,19 +219,27 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the votes table
|
//check if the increment amount should be multiplied (downvotes have more power if there have been many views)
|
||||||
if (row != undefined) {
|
db.prepare("SELECT votes, views FROM sponsorTimes WHERE UUID = ?").get(UUID, function(err, row) {
|
||||||
privateDB.prepare("UPDATE votes SET type = ? WHERE userID = ? AND UUID = ?").run(type, userID, UUID);
|
if (row != null && (row.votes > 3 || row.views > 4) && incrementAmount < 0) {
|
||||||
} else {
|
//multiply the power of this downvote
|
||||||
privateDB.prepare("INSERT INTO votes VALUES(?, ?, ?, ?)").run(UUID, userID, hashedIP, type);
|
incrementAmount *= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the vote count on this sponsorTime
|
//update the votes table
|
||||||
//oldIncrementAmount will be zero is row is null
|
if (row != undefined) {
|
||||||
db.prepare("UPDATE sponsorTimes SET votes = votes + ? WHERE UUID = ?").run(incrementAmount - oldIncrementAmount, UUID);
|
privateDB.prepare("UPDATE votes SET type = ? WHERE userID = ? AND UUID = ?").run(type, userID, UUID);
|
||||||
|
} else {
|
||||||
|
privateDB.prepare("INSERT INTO votes VALUES(?, ?, ?, ?)").run(UUID, userID, hashedIP, type);
|
||||||
|
}
|
||||||
|
|
||||||
//added to db
|
//update the vote count on this sponsorTime
|
||||||
res.sendStatus(200);
|
//oldIncrementAmount will be zero is row is null
|
||||||
|
db.prepare("UPDATE sponsorTimes SET votes = votes + ? WHERE UUID = ?").run(incrementAmount - oldIncrementAmount, UUID);
|
||||||
|
|
||||||
|
//added to db
|
||||||
|
res.sendStatus(200);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user