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