mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Add warning reason in postWarning
This commit is contained in:
parent
6f18a49ba0
commit
214ddc9807
3 changed files with 30 additions and 5 deletions
|
@ -104,6 +104,7 @@
|
|||
| issueTime | INTEGER | not null |
|
||||
| issuerUserID | TEXT | not null |
|
||||
| enabled | INTEGER | not null |
|
||||
| reason | TEXT | not null, default '' |
|
||||
|
||||
| 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) {
|
||||
// Collect user input data
|
||||
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;
|
||||
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||
const userID: UserID = req.body.userID;
|
||||
const issueTime = new Date().getTime();
|
||||
const enabled: boolean = req.body.enabled ?? true;
|
||||
const reason: string = req.body.reason ?? '';
|
||||
|
||||
// Ensure user is a VIP
|
||||
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]);
|
||||
|
||||
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";
|
||||
} else {
|
||||
res.status(409).send();
|
||||
|
|
Loading…
Reference in a new issue