mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 08:58:23 +03:00
@@ -48,6 +48,16 @@ function dbGetViewsForUser (userID) {
|
||||
}
|
||||
}
|
||||
|
||||
function dbGetWarningsForUser (userID) {
|
||||
try {
|
||||
let rows = db.prepare('all', "SELECT * FROM warnings WHERE userID = ?", [userID]);
|
||||
return rows.length;
|
||||
} catch (err) {
|
||||
logger.error('Couldn\'t get warnings for user ' + userID + '. returning 0') ;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function getUserInfo (req, res) {
|
||||
let userID = req.query.userID;
|
||||
|
||||
@@ -67,5 +77,6 @@ module.exports = function getUserInfo (req, res) {
|
||||
minutesSaved: segmentsSummary.minutesSaved,
|
||||
segmentCount: segmentsSummary.segmentCount,
|
||||
viewCount: dbGetViewsForUser(userID),
|
||||
warnings: dbGetWarningsForUser(userID)
|
||||
});
|
||||
}
|
||||
|
||||
24
src/routes/postWarning.js
Normal file
24
src/routes/postWarning.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const db = require('../databases/databases.js').db;
|
||||
const getHash = require('../utils/getHash.js');
|
||||
const isUserVIP = require('../utils/isUserVIP.js');
|
||||
const logger = require('../utils/logger.js');
|
||||
|
||||
module.exports = (req, res) => {
|
||||
// Collect user input data
|
||||
let issuerUserID = getHash(req.body.issuerUserID);
|
||||
let userID = getHash(req.body.userID);
|
||||
let issueTime = new Date().getTime();
|
||||
|
||||
// Ensure user is a VIP
|
||||
if (!isUserVIP(issuerUserID)) {
|
||||
logger.debug("Permission violation: User " + issuerUserID + " attempted to warn user " + userID + "."); // maybe warn?
|
||||
res.status(403).json({"message": "Not a VIP"});
|
||||
return;
|
||||
}
|
||||
|
||||
db.prepare('run', 'INSERT INTO warnings (userID, issueTime, issuerUserID) VALUES (?, ?, ?)', [userID, issueTime, issuerUserID]);
|
||||
res.status(200).json({
|
||||
message: "Warning issued to user '" + userID + "'."
|
||||
});
|
||||
|
||||
};
|
||||
@@ -270,6 +270,9 @@ async function voteOnSponsorTime(req, res) {
|
||||
} else if (votesRow.type === 2) {
|
||||
//extra downvote
|
||||
oldIncrementAmount = -4;
|
||||
} else if (votesRow.type === 20) {
|
||||
//undo/cancel vote
|
||||
oldIncrementAmount = 0;
|
||||
} else if (votesRow.type < 0) {
|
||||
//vip downvote
|
||||
oldIncrementAmount = votesRow.type;
|
||||
|
||||
Reference in New Issue
Block a user