diff --git a/src/routes/addFeature.ts b/src/routes/addFeature.ts index 28fe3da..376141a 100644 --- a/src/routes/addFeature.ts +++ b/src/routes/addFeature.ts @@ -6,6 +6,7 @@ import { isUserVIP } from "../utils/isUserVIP"; import { Feature, HashedUserID, UserID } from "../types/user.model"; import { Logger } from "../utils/logger"; import { QueryCacher } from "../utils/queryCacher"; +import { getVerificationValue, verifyOldSubmissions } from "./postBranding"; interface AddFeatureRequest extends Request { body: { @@ -58,6 +59,10 @@ export async function addFeature(req: AddFeatureRequest, res: Response): Promise await db.prepare("run", 'INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)' , [userID, feature, adminUserID, Date.now()]); } + + if (feature === Feature.DeArrowTitleSubmitter) { + await verifyOldSubmissions(userID, await getVerificationValue(userID, false)); + } } else { await db.prepare("run", 'DELETE FROM "userFeatures" WHERE "userID" = ? AND "feature" = ?', [userID, feature]); } diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 486e915..d0eca74 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -173,7 +173,7 @@ async function updateVoteTotals(type: BrandingType, existingVote: ExistingVote, } } -async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise { +export async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise { 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]); @@ -184,7 +184,7 @@ async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): } } -async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise { +export async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise { if (verification >= 0) { const unverifiedSubmissions = await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? AND "titleVotes"."verification" < ? GROUP BY "videoID", "hashedVideoID", "service"`, [hashedUserID, verification]);