mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Change dearrow permission requirements
This commit is contained in:
@@ -18,7 +18,7 @@ import { checkBanStatus } from "../utils/checkBan";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getMaxResThumbnail } from "../utils/youtubeApi";
|
import { getMaxResThumbnail } from "../utils/youtubeApi";
|
||||||
import { getVideoDetails } from "../utils/getVideoDetails";
|
import { getVideoDetails } from "../utils/getVideoDetails";
|
||||||
import { canSubmitGlobal } from "../utils/permissions";
|
import { canSubmitDeArrow } from "../utils/permissions";
|
||||||
|
|
||||||
enum BrandingType {
|
enum BrandingType {
|
||||||
Title,
|
Title,
|
||||||
@@ -56,7 +56,7 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
const hashedIP = await getHashCache(getIP(req) + config.globalSalt as IPAddress);
|
const hashedIP = await getHashCache(getIP(req) + config.globalSalt as IPAddress);
|
||||||
const isBanned = await checkBanStatus(hashedUserID, hashedIP);
|
const isBanned = await checkBanStatus(hashedUserID, hashedIP);
|
||||||
|
|
||||||
const permission = await canSubmitGlobal(hashedUserID);
|
const permission = await canSubmitDeArrow(hashedUserID);
|
||||||
if (!permission.canSubmit) {
|
if (!permission.canSubmit) {
|
||||||
res.status(403).send(permission.reason);
|
res.status(403).send(permission.reason);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import crypto from "crypto";
|
|||||||
import { QueryCacher } from "../utils/queryCacher";
|
import { QueryCacher } from "../utils/queryCacher";
|
||||||
import { acquireLock } from "../utils/redisLock";
|
import { acquireLock } from "../utils/redisLock";
|
||||||
import { checkBanStatus } from "../utils/checkBan";
|
import { checkBanStatus } from "../utils/checkBan";
|
||||||
import { canSubmitGlobal } from "../utils/permissions";
|
import { canSubmitDeArrow } from "../utils/permissions";
|
||||||
|
|
||||||
interface ExistingVote {
|
interface ExistingVote {
|
||||||
UUID: BrandingUUID;
|
UUID: BrandingUUID;
|
||||||
@@ -42,7 +42,7 @@ export async function postCasual(req: Request, res: Response) {
|
|||||||
const hashedIP = await getHashCache(getIP(req) + config.globalSalt as IPAddress);
|
const hashedIP = await getHashCache(getIP(req) + config.globalSalt as IPAddress);
|
||||||
const isBanned = await checkBanStatus(hashedUserID, hashedIP);
|
const isBanned = await checkBanStatus(hashedUserID, hashedIP);
|
||||||
|
|
||||||
const permission = await canSubmitGlobal(hashedUserID);
|
const permission = await canSubmitDeArrow(hashedUserID);
|
||||||
if (!permission.canSubmit) {
|
if (!permission.canSubmit) {
|
||||||
res.status(403).send(permission.reason);
|
res.status(403).send(permission.reason);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { getVideoDetails, videoDetails } from "../utils/getVideoDetails";
|
|||||||
import { deleteLockCategories } from "./deleteLockCategories";
|
import { deleteLockCategories } from "./deleteLockCategories";
|
||||||
import { acquireLock } from "../utils/redisLock";
|
import { acquireLock } from "../utils/redisLock";
|
||||||
import { checkBanStatus } from "../utils/checkBan";
|
import { checkBanStatus } from "../utils/checkBan";
|
||||||
import { canSubmitGlobal } from "../utils/permissions";
|
import { canVote } from "../utils/permissions";
|
||||||
|
|
||||||
const voteTypes = {
|
const voteTypes = {
|
||||||
normal: 0,
|
normal: 0,
|
||||||
@@ -343,7 +343,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
|
|||||||
const nonAnonUserID = await getHashCache(paramUserID);
|
const nonAnonUserID = await getHashCache(paramUserID);
|
||||||
const userID = await getHashCache(paramUserID + UUID);
|
const userID = await getHashCache(paramUserID + UUID);
|
||||||
|
|
||||||
const permission = await canSubmitGlobal(nonAnonUserID);
|
const permission = await canVote(nonAnonUserID);
|
||||||
if (!permission.canSubmit) {
|
if (!permission.canSubmit) {
|
||||||
return {
|
return {
|
||||||
status: 403,
|
status: 403,
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ async function oldSubmitter(userID: HashedUserID): Promise<boolean> {
|
|||||||
return result.submissionCount > 1;
|
return result.submissionCount > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function oldDeArrowSubmitter(userID: HashedUserID): Promise<boolean> {
|
||||||
|
const result = await db.prepare("get", `SELECT count(*) as "submissionCount" FROM "titles" WHERE "userID" = ? AND "timeSubmitted" < 1743827196000`
|
||||||
|
, [userID], { useReplica: true });
|
||||||
|
|
||||||
|
return result.submissionCount > 1;
|
||||||
|
}
|
||||||
|
|
||||||
export async function canSubmit(userID: HashedUserID, category: Category): Promise<CanSubmitResult> {
|
export async function canSubmit(userID: HashedUserID, category: Category): Promise<CanSubmitResult> {
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case "chapter":
|
case "chapter":
|
||||||
@@ -42,16 +49,25 @@ export async function canSubmit(userID: HashedUserID, category: Category): Promi
|
|||||||
canSubmit: await oneOf([isUserVIP(userID),
|
canSubmit: await oneOf([isUserVIP(userID),
|
||||||
oldSubmitter(userID)
|
oldSubmitter(userID)
|
||||||
]),
|
]),
|
||||||
reason: "We are currently experiencing a mass spam attack"
|
reason: "We are currently experiencing a mass spam attack, we are restricting submissions for now"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function canSubmitGlobal(userID: HashedUserID): Promise<CanSubmitResult> {
|
export async function canVote(userID: HashedUserID): Promise<CanSubmitResult> {
|
||||||
return {
|
return {
|
||||||
canSubmit: await oneOf([isUserVIP(userID),
|
canSubmit: await oneOf([isUserVIP(userID),
|
||||||
oldSubmitter(userID)
|
oldSubmitter(userID)
|
||||||
]),
|
]),
|
||||||
reason: "We are currently experiencing a mass spam attack"
|
reason: "We are currently experiencing a mass spam attack, we are restricting submissions for now"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function canSubmitDeArrow(userID: HashedUserID): Promise<CanSubmitResult> {
|
||||||
|
return {
|
||||||
|
canSubmit: await oneOf([isUserVIP(userID),
|
||||||
|
oldDeArrowSubmitter(userID)
|
||||||
|
]),
|
||||||
|
reason: "We are currently experiencing a mass spam attack, we are restricting submissions for now"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user