Merge pull request #438 from mchangrh/tempVIP

channel-specific VIP
This commit is contained in:
Ajay Ramachandran
2021-12-31 14:02:05 -05:00
committed by GitHub
11 changed files with 308 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ interface RedisSB {
getAsync?(key: string): Promise<{err: Error | null, reply: string | null}>;
set(key: string, value: string, callback?: Callback<string | null>): void;
setAsync?(key: string, value: string): Promise<{err: Error | null, reply: string | null}>;
setAsyncEx?(key: string, value: string, seconds: number): Promise<{err: Error | null, reply: string | null}>;
delAsync?(...keys: [string]): Promise<Error | null>;
close?(flush?: boolean): void;
increment?(key: string): Promise<{err: Error| null, replies: any[] | null}>;
@@ -19,6 +20,8 @@ let exportObject: RedisSB = {
set: (key, value, callback) => callback(null, undefined),
setAsync: () =>
new Promise((resolve) => resolve({ err: null, reply: undefined })),
setAsyncEx: () =>
new Promise((resolve) => resolve({ err: null, reply: undefined })),
delAsync: () =>
new Promise((resolve) => resolve(null)),
increment: () =>
@@ -32,6 +35,7 @@ if (config.redis) {
exportObject.getAsync = (key) => new Promise((resolve) => client.get(key, (err, reply) => resolve({ err, reply })));
exportObject.setAsync = (key, value) => new Promise((resolve) => client.set(key, value, (err, reply) => resolve({ err, reply })));
exportObject.setAsyncEx = (key, value, seconds) => new Promise((resolve) => client.setex(key, seconds, value, (err, reply) => resolve({ err, reply })));
exportObject.delAsync = (...keys) => new Promise((resolve) => client.del(keys, (err) => resolve(err)));
exportObject.close = (flush) => client.end(flush);
exportObject.increment = (key) => new Promise((resolve) =>

View File

@@ -1,15 +1,13 @@
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
import { UserID } from "../types/user.model";
import { HashedUserID, UserID } from "../types/user.model";
import { HashedValue } from "../types/hash.model";
import { Logger } from "./logger";
export function skipSegmentsKey(videoID: VideoID, service: Service): string {
return `segments.v3.${service}.videoID.${videoID}`;
}
export const skipSegmentsKey = (videoID: VideoID, service: Service): string =>
`segments.v3.${service}.videoID.${videoID}`;
export function skipSegmentGroupsKey(videoID: VideoID, service: Service): string {
return `segments.groups.v2.${service}.videoID.${videoID}`;
}
export const skipSegmentGroupsKey = (videoID: VideoID, service: Service): string =>
`segments.groups.v2.${service}.videoID.${videoID}`;
export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
@@ -18,9 +16,8 @@ export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: S
return `segments.v3.${service}.${hashedVideoIDPrefix}`;
}
export function reputationKey(userID: UserID): string {
return `reputation.user.${userID}`;
}
export const reputationKey = (userID: UserID): string =>
`reputation.user.${userID}`;
export function ratingHashKey(hashPrefix: VideoIDHash, service: Service): string {
hashPrefix = hashPrefix.substring(0, 4) as VideoIDHash;
@@ -33,4 +30,7 @@ export function shaHashKey(singleIter: HashedValue): string {
if (singleIter.length !== 64) Logger.warn(`Redis sha.hash key is not length 64! ${singleIter}`);
return `sha.hash.${singleIter}`;
}
}
export const tempVIPKey = (userID: HashedUserID): string =>
`vip.temp.${userID}`;

View File

@@ -2,9 +2,11 @@ import { config } from "../config";
import { Logger } from "../utils/logger";
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) {
return "self";
} else if (isTempVIP) {
return "temp vip";
} else if (isVIP) {
return "vip";
} 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) {
return "Report by New User";
} else if (isOwnSubmission) {
return "Report by Submitter";
} else if (isTempVIP) {
return "Report by Temp VIP";
} else if (isVIP) {
return "Report by VIP User";
}