From 0723503a98d57dbaa20af50604767244f76f29db Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 4 Aug 2023 14:17:41 -0400 Subject: [PATCH] Add DeArrow submitter feature --- src/routes/addFeature.ts | 6 ++++-- src/routes/postBranding.ts | 5 +++-- src/types/user.model.ts | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/routes/addFeature.ts b/src/routes/addFeature.ts index e5e5519..28fe3da 100644 --- a/src/routes/addFeature.ts +++ b/src/routes/addFeature.ts @@ -19,11 +19,13 @@ interface AddFeatureRequest extends Request { const allowedFeatures = { vip: [ Feature.ChapterSubmitter, - Feature.FillerSubmitter + Feature.FillerSubmitter, + Feature.DeArrowTitleSubmitter, ], admin: [ Feature.ChapterSubmitter, - Feature.FillerSubmitter + Feature.FillerSubmitter, + Feature.DeArrowTitleSubmitter, ] }; diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 63c93f2..ddd9f11 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -4,7 +4,7 @@ import { db, privateDB } from "../databases/databases"; import { BrandingSubmission, BrandingUUID, TimeThumbnailSubmission } from "../types/branding.model"; import { HashedIP, IPAddress, VideoID } from "../types/segments.model"; -import { HashedUserID } from "../types/user.model"; +import { Feature, HashedUserID } from "../types/user.model"; import { getHashCache } from "../utils/getHashCache"; import { getIP } from "../utils/getIP"; import { getService } from "../utils/getService"; @@ -13,6 +13,7 @@ import { Logger } from "../utils/logger"; import crypto from "crypto"; import { QueryCacher } from "../utils/queryCacher"; import { acquireLock } from "../utils/redisLock"; +import { hasFeature } from "../utils/features"; enum BrandingType { Title, @@ -166,7 +167,7 @@ async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): const voteSum = await db.prepare("get", `SELECT SUM("maxVotes") as "voteSum" FROM (SELECT MAX("votes") as "maxVotes" from "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? GROUP BY "titles"."videoID") t`, [hashedUserID]); const sbSubmissions = () => db.prepare("get", `SELECT COUNT(*) as count FROM "sponsorTimes" WHERE "userID" = ? AND "votes" > 0 LIMIT 3`, [hashedUserID]); - if (voteSum.voteSum >= 1 || isVip || (await sbSubmissions()).count > 2) { + if (voteSum.voteSum >= 1 || isVip || (await sbSubmissions()).count > 2 || await hasFeature(hashedUserID, Feature.DeArrowTitleSubmitter)) { return 0; } else { return -1; diff --git a/src/types/user.model.ts b/src/types/user.model.ts index c3009df..65a6fe1 100644 --- a/src/types/user.model.ts +++ b/src/types/user.model.ts @@ -5,5 +5,6 @@ export type HashedUserID = UserID & HashedValue; export enum Feature { ChapterSubmitter = 0, - FillerSubmitter = 1 + FillerSubmitter = 1, + DeArrowTitleSubmitter = 2, } \ No newline at end of file