mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Merge pull request #334 from HaiDang666/update-query
Add Limit 1 when check user as vip
This commit is contained in:
commit
56a36f34a9
3 changed files with 13 additions and 9 deletions
|
@ -2,9 +2,12 @@ import {getHash} from "../utils/getHash";
|
||||||
import {db} from "../databases/databases";
|
import {db} from "../databases/databases";
|
||||||
import {config} from "../config";
|
import {config} from "../config";
|
||||||
import {Request, Response} from "express";
|
import {Request, Response} from "express";
|
||||||
|
import { isUserVIP } from "../utils/isUserVIP";
|
||||||
|
import { HashedUserID } from "../types/user.model";
|
||||||
|
|
||||||
|
|
||||||
export async function addUserAsVIP(req: Request, res: Response): Promise<Response> {
|
export async function addUserAsVIP(req: Request, res: Response): Promise<Response> {
|
||||||
const userID = req.query.userID as string;
|
const userID = req.query.userID as HashedUserID;
|
||||||
let adminUserIDInput = req.query.adminUserID as string;
|
let adminUserIDInput = req.query.adminUserID as string;
|
||||||
|
|
||||||
const enabled = req.query.enabled === undefined
|
const enabled = req.query.enabled === undefined
|
||||||
|
@ -25,12 +28,12 @@ export async function addUserAsVIP(req: Request, res: Response): Promise<Respons
|
||||||
}
|
}
|
||||||
|
|
||||||
//check to see if this user is already a vip
|
//check to see if this user is already a vip
|
||||||
const row = await db.prepare("get", 'SELECT count(*) as "userCount" FROM "vipUsers" WHERE "userID" = ?', [userID]);
|
const userIsVIP = await isUserVIP(userID);
|
||||||
|
|
||||||
if (enabled && row.userCount == 0) {
|
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 && row.userCount > 0) {
|
} else 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]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@ import { config } from "../config";
|
||||||
import { Category, Service, VideoID, VideoIDHash } from "../types/segments.model";
|
import { Category, Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||||
import { UserID } from "../types/user.model";
|
import { UserID } from "../types/user.model";
|
||||||
import { QueryCacher } from "../utils/queryCacher";
|
import { QueryCacher } from "../utils/queryCacher";
|
||||||
|
import { isUserVIP } from "../utils/isUserVIP";
|
||||||
|
|
||||||
export async function shadowBanUser(req: Request, res: Response): Promise<Response> {
|
export async function shadowBanUser(req: Request, res: Response): Promise<Response> {
|
||||||
const userID = req.query.userID as string;
|
const userID = req.query.userID as UserID;
|
||||||
const hashedIP = req.query.hashedIP as string;
|
const hashedIP = req.query.hashedIP as string;
|
||||||
let adminUserIDInput = req.query.adminUserID as string;
|
const adminUserIDInput = req.query.adminUserID as UserID;
|
||||||
|
|
||||||
const enabled = req.query.enabled === undefined
|
const enabled = req.query.enabled === undefined
|
||||||
? true
|
? true
|
||||||
|
@ -27,9 +28,9 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
|
||||||
}
|
}
|
||||||
|
|
||||||
//hash the userID
|
//hash the userID
|
||||||
adminUserIDInput = getHash(adminUserIDInput);
|
const adminUserID = getHash(adminUserIDInput);
|
||||||
|
|
||||||
const isVIP = (await db.prepare("get", `SELECT count(*) as "userCount" FROM "vipUsers" WHERE "userID" = ?`, [adminUserIDInput])).userCount > 0;
|
const isVIP = await isUserVIP(adminUserID);
|
||||||
if (!isVIP) {
|
if (!isVIP) {
|
||||||
//not authorized
|
//not authorized
|
||||||
return res.sendStatus(403);
|
return res.sendStatus(403);
|
||||||
|
|
|
@ -281,7 +281,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
||||||
const hashedIP: HashedIP = getHash((ip + config.globalSalt) as IPAddress);
|
const hashedIP: HashedIP = getHash((ip + config.globalSalt) as IPAddress);
|
||||||
|
|
||||||
//check if this user is on the vip list
|
//check if this user is on the vip list
|
||||||
const isVIP = (await db.prepare("get", `SELECT count(*) as "userCount" FROM "vipUsers" WHERE "userID" = ?`, [nonAnonUserID])).userCount > 0;
|
const isVIP = await isUserVIP(nonAnonUserID);
|
||||||
|
|
||||||
//check if user voting on own submission
|
//check if user voting on own submission
|
||||||
const isOwnSubmission = (await db.prepare("get", `SELECT "UUID" as "submissionCount" FROM "sponsorTimes" where "userID" = ? AND "UUID" = ?`, [nonAnonUserID, UUID])) !== undefined;
|
const isOwnSubmission = (await db.prepare("get", `SELECT "UUID" as "submissionCount" FROM "sponsorTimes" where "userID" = ? AND "UUID" = ?`, [nonAnonUserID, UUID])) !== undefined;
|
||||||
|
|
Loading…
Reference in a new issue