mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
@@ -22,10 +22,17 @@ export function postWarning(req: Request, res: Response) {
|
|||||||
let resultStatus = "";
|
let resultStatus = "";
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
let previousWarning = db.prepare('get', 'SELECT * FROM warnings WHERE userID = ? AND issuerUserID = ?', [userID, issuerUserID]);
|
||||||
|
|
||||||
|
if (!previousWarning) {
|
||||||
db.prepare('run', 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES (?, ?, ?, 1)', [userID, issueTime, issuerUserID]);
|
db.prepare('run', 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES (?, ?, ?, 1)', [userID, issueTime, issuerUserID]);
|
||||||
resultStatus = "issued to";
|
resultStatus = "issued to";
|
||||||
} else {
|
} else {
|
||||||
db.prepare('run', 'UPDATE warnings SET enabled = 0', []);
|
res.status(409).send();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
db.prepare('run', 'UPDATE warnings SET enabled = 0 WHERE userID = ? AND issuerUserID = ?', [userID, issuerUserID]);
|
||||||
resultStatus = "removed from";
|
resultStatus = "removed from";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,30 @@ describe('postWarning', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
|
||||||
|
let json = {
|
||||||
|
issuerUserID: 'warning-vip',
|
||||||
|
userID: 'warning-0',
|
||||||
|
};
|
||||||
|
|
||||||
|
request.post(getbaseURL()
|
||||||
|
+ "/api/warnUser", {json},
|
||||||
|
(err, res, body) => {
|
||||||
|
if (err) done(err);
|
||||||
|
else if (res.statusCode === 409) {
|
||||||
|
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
|
||||||
|
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
done("Warning missing from database");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(body);
|
||||||
|
done("Status code was " + res.statusCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Should be able to remove warning if vip', (done: Done) => {
|
it('Should be able to remove warning if vip', (done: Done) => {
|
||||||
let json = {
|
let json = {
|
||||||
issuerUserID: 'warning-vip',
|
issuerUserID: 'warning-vip',
|
||||||
|
|||||||
Reference in New Issue
Block a user