mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 12:37:00 +03:00
Add warning reason in postWarning
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user