mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 06:57:05 +03:00
Add remove feature to warnUser
This commit is contained in:
@@ -3,23 +3,33 @@ import {Logger} from '../utils/logger';
|
||||
import {db} from '../databases/databases';
|
||||
import {isUserVIP} from '../utils/isUserVIP';
|
||||
import {getHash} from '../utils/getHash';
|
||||
import { HashedUserID, UserID } from '../types/user.model';
|
||||
|
||||
export function postWarning(req: Request, res: Response) {
|
||||
// Collect user input data
|
||||
let issuerUserID = getHash(req.body.issuerUserID);
|
||||
let userID = req.body.userID;
|
||||
let issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||
let userID: UserID = req.body.userID;
|
||||
let issueTime = new Date().getTime();
|
||||
let enabled: boolean = req.body.enabled ?? true;
|
||||
|
||||
// Ensure user is a VIP
|
||||
if (!isUserVIP(issuerUserID)) {
|
||||
Logger.debug("Permission violation: User " + issuerUserID + " attempted to warn user " + userID + "."); // maybe warn?
|
||||
Logger.warn("Permission violation: User " + issuerUserID + " attempted to warn user " + userID + ".");
|
||||
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 + "'.",
|
||||
});
|
||||
let resultStatus = "";
|
||||
|
||||
if (enabled) {
|
||||
db.prepare('run', 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES (?, ?, ?, 1)', [userID, issueTime, issuerUserID]);
|
||||
resultStatus = "issued to";
|
||||
} else {
|
||||
db.prepare('run', 'UPDATE warnings SET enabled = 0', []);
|
||||
resultStatus = "removed from";
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
message: "Warning " + resultStatus + " user '" + userID + "'.",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user