mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
routes/addUserAsVIP: fixed
This commit is contained in:
@@ -5,22 +5,26 @@ import { Request, Response } from "express";
|
|||||||
import { isUserVIP } from "../utils/isUserVIP";
|
import { isUserVIP } from "../utils/isUserVIP";
|
||||||
import { HashedUserID } from "../types/user.model";
|
import { HashedUserID } from "../types/user.model";
|
||||||
|
|
||||||
|
interface AddUserAsVIPRequest extends Request {
|
||||||
|
query: {
|
||||||
|
userID: HashedUserID;
|
||||||
|
adminUserID: string;
|
||||||
|
enabled: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function addUserAsVIP(req: Request, res: Response): Promise<Response> {
|
export async function addUserAsVIP(req: AddUserAsVIPRequest, res: Response): Promise<Response> {
|
||||||
const userID = req.query.userID as HashedUserID;
|
const { query: { userID, adminUserID } } = req;
|
||||||
let adminUserIDInput = req.query.adminUserID as string;
|
|
||||||
|
|
||||||
const enabled = req.query.enabled === undefined
|
const enabled = req.query?.enabled === "true";
|
||||||
? false
|
|
||||||
: req.query.enabled === "true";
|
|
||||||
|
|
||||||
if (userID == undefined || adminUserIDInput == undefined) {
|
if (!userID || !adminUserID) {
|
||||||
// invalid request
|
// invalid request
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash the userID
|
// hash the userID
|
||||||
adminUserIDInput = getHash(adminUserIDInput);
|
const adminUserIDInput = getHash(adminUserID);
|
||||||
|
|
||||||
if (adminUserIDInput !== config.adminUserID) {
|
if (adminUserIDInput !== config.adminUserID) {
|
||||||
// not authorized
|
// not authorized
|
||||||
@@ -33,7 +37,9 @@ export async function addUserAsVIP(req: Request, res: Response): Promise<Respons
|
|||||||
if (enabled && !userIsVIP) {
|
if (enabled && !userIsVIP) {
|
||||||
// add them to the vip list
|
// add them to the vip list
|
||||||
await db.prepare("run", 'INSERT INTO "vipUsers" VALUES(?)', [userID]);
|
await db.prepare("run", 'INSERT INTO "vipUsers" VALUES(?)', [userID]);
|
||||||
} else if (!enabled && userIsVIP) {
|
}
|
||||||
|
|
||||||
|
if (!enabled && userIsVIP) {
|
||||||
//remove them from the shadow ban list
|
//remove them from the shadow ban list
|
||||||
await db.prepare("run", 'DELETE FROM "vipUsers" WHERE "userID" = ?', [userID]);
|
await db.prepare("run", 'DELETE FROM "vipUsers" WHERE "userID" = ?', [userID]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user