mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 07:27:01 +03:00
Made it so that VIP users start with votes after a submission.
This commit is contained in:
19
index.js
19
index.js
@@ -103,7 +103,7 @@ function getIP(req) {
|
||||
}
|
||||
|
||||
//add the post function
|
||||
app.get('/api/postVideoSponsorTimes', function (req, res) {
|
||||
app.get('/api/postVideoSponsorTimes', async function (req, res) {
|
||||
let videoID = req.query.videoID;
|
||||
let startTime = req.query.startTime;
|
||||
let endTime = req.query.endTime;
|
||||
@@ -138,6 +138,11 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
||||
return;
|
||||
}
|
||||
|
||||
//check if this user is on the vip list
|
||||
let vipResult = await new Promise((resolve, reject) => {
|
||||
db.prepare("SELECT count(*) as userCount FROM vipUsers WHERE userID = ?").get(userID, (err, row) => resolve({err, row}));
|
||||
});
|
||||
|
||||
//this can just be a hash of the data
|
||||
//it's better than generating an actual UUID like what was used before
|
||||
//also better for duplication checking
|
||||
@@ -172,9 +177,15 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
||||
|
||||
let shadowBanned = result.row.userCount;
|
||||
|
||||
let startingVotes = 0;
|
||||
if (vipResult.row.userCount > 0) {
|
||||
//this user is a vip, start them at a higher approval rating
|
||||
startingVotes = 10;
|
||||
}
|
||||
|
||||
if (row == null) {
|
||||
//not a duplicate, execute query
|
||||
db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, 0, UUID, userID, timeSubmitted, 0, shadowBanned);
|
||||
db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, startingVotes, UUID, userID, timeSubmitted, 0, shadowBanned);
|
||||
|
||||
//add to private db as well
|
||||
privateDB.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?)").run(videoID, hashedIP, timeSubmitted);
|
||||
@@ -254,13 +265,13 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
|
||||
}
|
||||
|
||||
//check if this user is on the vip list
|
||||
let result = await new Promise((resolve, reject) => {
|
||||
let vipResult = await new Promise((resolve, reject) => {
|
||||
db.prepare("SELECT count(*) as userCount FROM vipUsers WHERE userID = ?").get(nonAnonUserID, (err, row) => resolve({err, row}));
|
||||
});
|
||||
|
||||
//check if the increment amount should be multiplied (downvotes have more power if there have been many views)
|
||||
db.prepare("SELECT votes, views FROM sponsorTimes WHERE UUID = ?").get(UUID, function(err, row) {
|
||||
if (result.row.userCount != 0 && incrementAmount < 0) {
|
||||
if (vipResult.row.userCount != 0 && incrementAmount < 0) {
|
||||
//this user is a vip and a downvote
|
||||
//their vote should be -25 or -80%
|
||||
incrementAmount = -Math.max(25, Math.floor(row.votes * 0.8));
|
||||
|
||||
Reference in New Issue
Block a user