mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 13:37:01 +03:00
add tempVIP check to vote
This commit is contained in:
@@ -9,11 +9,13 @@ import { getFormattedTime } from "../utils/getFormattedTime";
|
|||||||
import { getIP } from "../utils/getIP";
|
import { getIP } from "../utils/getIP";
|
||||||
import { getHashCache } from "../utils/getHashCache";
|
import { getHashCache } from "../utils/getHashCache";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
import { UserID } from "../types/user.model";
|
import { HashedUserID, UserID } from "../types/user.model";
|
||||||
import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility, VideoDuration } from "../types/segments.model";
|
import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility, VideoDuration } from "../types/segments.model";
|
||||||
import { getCategoryActionType } from "../utils/categoryInfo";
|
import { getCategoryActionType } from "../utils/categoryInfo";
|
||||||
import { QueryCacher } from "../utils/queryCacher";
|
import { QueryCacher } from "../utils/queryCacher";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import redis from "../utils/redis";
|
||||||
|
import { tempVIPKey } from "../utils/redisKeys";
|
||||||
|
|
||||||
const voteTypes = {
|
const voteTypes = {
|
||||||
normal: 0,
|
normal: 0,
|
||||||
@@ -37,6 +39,7 @@ interface VoteData {
|
|||||||
UUID: string;
|
UUID: string;
|
||||||
nonAnonUserID: string;
|
nonAnonUserID: string;
|
||||||
voteTypeEnum: number;
|
voteTypeEnum: number;
|
||||||
|
isTempVIP: boolean;
|
||||||
isVIP: boolean;
|
isVIP: boolean;
|
||||||
isOwnSubmission: boolean;
|
isOwnSubmission: boolean;
|
||||||
row: {
|
row: {
|
||||||
@@ -57,6 +60,13 @@ function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise<API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isUserTempVIP = async (nonAnonUserID: HashedUserID, videoID: VideoID): Promise<boolean> => {
|
||||||
|
const apiVideoInfo = await getYouTubeVideoInfo(videoID);
|
||||||
|
const channelID = apiVideoInfo?.data?.authorId;
|
||||||
|
const { err, reply } = await redis.getAsync(tempVIPKey(nonAnonUserID));
|
||||||
|
return err ? false : (reply == channelID);
|
||||||
|
};
|
||||||
|
|
||||||
const videoDurationChanged = (segmentDuration: number, APIDuration: number) => (APIDuration > 0 && Math.abs(segmentDuration - APIDuration) > 2);
|
const videoDurationChanged = (segmentDuration: number, APIDuration: number) => (APIDuration > 0 && Math.abs(segmentDuration - APIDuration) > 2);
|
||||||
|
|
||||||
async function checkVideoDurationChange(UUID: SegmentUUID) {
|
async function checkVideoDurationChange(UUID: SegmentUUID) {
|
||||||
@@ -105,7 +115,7 @@ async function sendWebhooks(voteData: VoteData) {
|
|||||||
// Send custom webhooks
|
// Send custom webhooks
|
||||||
dispatchEvent(isUpvote ? "vote.up" : "vote.down", {
|
dispatchEvent(isUpvote ? "vote.up" : "vote.down", {
|
||||||
"user": {
|
"user": {
|
||||||
"status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission),
|
"status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, voteData.isTempVIP, voteData.isVIP, voteData.isOwnSubmission),
|
||||||
},
|
},
|
||||||
"video": {
|
"video": {
|
||||||
"id": submissionInfoRow.videoID,
|
"id": submissionInfoRow.videoID,
|
||||||
@@ -153,7 +163,7 @@ async function sendWebhooks(voteData: VoteData) {
|
|||||||
"author": {
|
"author": {
|
||||||
"name": voteData.finalResponse?.webhookMessage ??
|
"name": voteData.finalResponse?.webhookMessage ??
|
||||||
voteData.finalResponse?.finalMessage ??
|
voteData.finalResponse?.finalMessage ??
|
||||||
getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission),
|
getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isTempVIP, voteData.isVIP, voteData.isOwnSubmission),
|
||||||
},
|
},
|
||||||
"thumbnail": {
|
"thumbnail": {
|
||||||
"url": getMaxResThumbnail(data) || "",
|
"url": getMaxResThumbnail(data) || "",
|
||||||
@@ -311,7 +321,9 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
|||||||
const hashedIP: HashedIP = await getHashCache((ip + config.globalSalt) as IPAddress);
|
const hashedIP: HashedIP = await getHashCache((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 isUserVIP(nonAnonUserID);
|
const videoID = await db.prepare("get", `select "videoID" from "sponsorTimes" where "UUID" = ?`, [UUID]);
|
||||||
|
const isTempVIP = await isUserTempVIP(nonAnonUserID, videoID);
|
||||||
|
const isVIP = await isUserVIP(nonAnonUserID) || isTempVIP;
|
||||||
|
|
||||||
//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;
|
||||||
@@ -480,6 +492,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
|||||||
UUID,
|
UUID,
|
||||||
nonAnonUserID,
|
nonAnonUserID,
|
||||||
voteTypeEnum,
|
voteTypeEnum,
|
||||||
|
isTempVIP,
|
||||||
isVIP,
|
isVIP,
|
||||||
isOwnSubmission,
|
isOwnSubmission,
|
||||||
row: videoInfo,
|
row: videoInfo,
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ import { UserID } from "../types/user.model";
|
|||||||
import { HashedValue } from "../types/hash.model";
|
import { HashedValue } from "../types/hash.model";
|
||||||
import { Logger } from "./logger";
|
import { Logger } from "./logger";
|
||||||
|
|
||||||
export function skipSegmentsKey(videoID: VideoID, service: Service): string {
|
export const skipSegmentsKey = (videoID: VideoID, service: Service): string =>
|
||||||
return `segments.v3.${service}.videoID.${videoID}`;
|
`segments.v3.${service}.videoID.${videoID}`;
|
||||||
}
|
|
||||||
|
|
||||||
export function skipSegmentGroupsKey(videoID: VideoID, service: Service): string {
|
export const skipSegmentGroupsKey = (videoID: VideoID, service: Service): string =>
|
||||||
return `segments.groups.v2.${service}.videoID.${videoID}`;
|
`segments.groups.v2.${service}.videoID.${videoID}`;
|
||||||
}
|
|
||||||
|
|
||||||
export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
|
export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
|
||||||
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
|
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
|
||||||
@@ -18,9 +16,8 @@ export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: S
|
|||||||
return `segments.v3.${service}.${hashedVideoIDPrefix}`;
|
return `segments.v3.${service}.${hashedVideoIDPrefix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reputationKey(userID: UserID): string {
|
export const reputationKey = (userID: UserID): string =>
|
||||||
return `reputation.user.${userID}`;
|
`reputation.user.${userID}`;
|
||||||
}
|
|
||||||
|
|
||||||
export function ratingHashKey(hashPrefix: VideoIDHash, service: Service): string {
|
export function ratingHashKey(hashPrefix: VideoIDHash, service: Service): string {
|
||||||
hashPrefix = hashPrefix.substring(0, 4) as VideoIDHash;
|
hashPrefix = hashPrefix.substring(0, 4) as VideoIDHash;
|
||||||
@@ -34,3 +31,6 @@ export function shaHashKey(singleIter: HashedValue): string {
|
|||||||
|
|
||||||
return `sha.hash.${singleIter}`;
|
return `sha.hash.${singleIter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const tempVIPKey = (userID: UserID): string =>
|
||||||
|
`vip.temp.${userID}`;
|
||||||
@@ -2,9 +2,11 @@ import { config } from "../config";
|
|||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
|
function getVoteAuthorRaw(submissionCount: number, isTempVIP: boolean, isVIP: boolean, isOwnSubmission: boolean): string {
|
||||||
if (isOwnSubmission) {
|
if (isOwnSubmission) {
|
||||||
return "self";
|
return "self";
|
||||||
|
} else if (isTempVIP) {
|
||||||
|
return "temp vip";
|
||||||
} else if (isVIP) {
|
} else if (isVIP) {
|
||||||
return "vip";
|
return "vip";
|
||||||
} else if (submissionCount === 0) {
|
} else if (submissionCount === 0) {
|
||||||
@@ -14,11 +16,13 @@ function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmissi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVoteAuthor(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
|
function getVoteAuthor(submissionCount: number, isTempVIP: boolean, isVIP: boolean, isOwnSubmission: boolean): string {
|
||||||
if (submissionCount === 0) {
|
if (submissionCount === 0) {
|
||||||
return "Report by New User";
|
return "Report by New User";
|
||||||
} else if (isOwnSubmission) {
|
} else if (isOwnSubmission) {
|
||||||
return "Report by Submitter";
|
return "Report by Submitter";
|
||||||
|
} else if (isTempVIP) {
|
||||||
|
return "Report by Temp VIP";
|
||||||
} else if (isVIP) {
|
} else if (isVIP) {
|
||||||
return "Report by VIP User";
|
return "Report by VIP User";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user