mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Merge pull request #282 from HaiDang666/276_warn-reason
User warning reason
This commit is contained in:
commit
7a877a9653
4 changed files with 33 additions and 7 deletions
|
@ -104,6 +104,7 @@
|
||||||
| issueTime | INTEGER | not null |
|
| issueTime | INTEGER | not null |
|
||||||
| issuerUserID | TEXT | not null |
|
| issuerUserID | TEXT | not null |
|
||||||
| enabled | INTEGER | not null |
|
| enabled | INTEGER | not null |
|
||||||
|
| reason | TEXT | not null, default '' |
|
||||||
|
|
||||||
| index | field |
|
| index | field |
|
||||||
| -- | :--: |
|
| -- | :--: |
|
||||||
|
|
19
databases/_upgrade_sponsorTimes_17.sql
Normal file
19
databases/_upgrade_sponsorTimes_17.sql
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
/* Add reason field */
|
||||||
|
CREATE TABLE "sqlb_temp_table_17" (
|
||||||
|
"userID" TEXT NOT NULL,
|
||||||
|
"issueTime" INTEGER NOT NULL,
|
||||||
|
"issuerUserID" TEXT NOT NULL,
|
||||||
|
enabled INTEGER NOT NULL,
|
||||||
|
"reason" TEXT NOT NULL default ''
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO sqlb_temp_table_17 SELECT "userID","issueTime","issuerUserID","enabled", '' FROM "warnings";
|
||||||
|
|
||||||
|
DROP TABLE warnings;
|
||||||
|
ALTER TABLE sqlb_temp_table_17 RENAME TO "warnings";
|
||||||
|
|
||||||
|
UPDATE "config" SET value = 17 WHERE key = 'version';
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -7,10 +7,11 @@ import { HashedUserID, UserID } from '../types/user.model';
|
||||||
|
|
||||||
export async function postWarning(req: Request, res: Response) {
|
export async function postWarning(req: Request, res: Response) {
|
||||||
// Collect user input data
|
// Collect user input data
|
||||||
let issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||||
let userID: UserID = req.body.userID;
|
const userID: UserID = req.body.userID;
|
||||||
let issueTime = new Date().getTime();
|
const issueTime = new Date().getTime();
|
||||||
let enabled: boolean = req.body.enabled ?? true;
|
const enabled: boolean = req.body.enabled ?? true;
|
||||||
|
const reason: string = req.body.reason ?? '';
|
||||||
|
|
||||||
// Ensure user is a VIP
|
// Ensure user is a VIP
|
||||||
if (!await isUserVIP(issuerUserID)) {
|
if (!await isUserVIP(issuerUserID)) {
|
||||||
|
@ -25,7 +26,11 @@ export async function postWarning(req: Request, res: Response) {
|
||||||
let previousWarning = await db.prepare('get', 'SELECT * FROM "warnings" WHERE "userID" = ? AND "issuerUserID" = ?', [userID, issuerUserID]);
|
let previousWarning = await db.prepare('get', 'SELECT * FROM "warnings" WHERE "userID" = ? AND "issuerUserID" = ?', [userID, issuerUserID]);
|
||||||
|
|
||||||
if (!previousWarning) {
|
if (!previousWarning) {
|
||||||
await db.prepare('run', 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES (?, ?, ?, 1)', [userID, issueTime, issuerUserID]);
|
await db.prepare(
|
||||||
|
'run',
|
||||||
|
'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, 1, ?)',
|
||||||
|
[userID, issueTime, issuerUserID, reason]
|
||||||
|
);
|
||||||
resultStatus = "issued to";
|
resultStatus = "issued to";
|
||||||
} else {
|
} else {
|
||||||
res.status(409).send();
|
res.status(409).send();
|
||||||
|
|
|
@ -12,6 +12,7 @@ describe('postWarning', () => {
|
||||||
let json = {
|
let json = {
|
||||||
issuerUserID: 'warning-vip',
|
issuerUserID: 'warning-vip',
|
||||||
userID: 'warning-0',
|
userID: 'warning-0',
|
||||||
|
reason: 'warning-reason-0'
|
||||||
};
|
};
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/warnUser", {
|
+ "/api/warnUser", {
|
||||||
|
@ -23,8 +24,8 @@ describe('postWarning', () => {
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
let row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
let row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||||
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
|
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID) && row?.reason === json.reason) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Warning missing from database");
|
done("Warning missing from database");
|
||||||
|
|
Loading…
Reference in a new issue