Skip to content

Commit d08c423

Browse files
committed
Verify old submissions when adding dearrow feature
1 parent 8361f60 commit d08c423

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/routes/addFeature.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { isUserVIP } from "../utils/isUserVIP";
66
import { Feature, HashedUserID, UserID } from "../types/user.model";
77
import { Logger } from "../utils/logger";
88
import { QueryCacher } from "../utils/queryCacher";
9+
import { getVerificationValue, verifyOldSubmissions } from "./postBranding";
910

1011
interface AddFeatureRequest extends Request {
1112
body: {
@@ -58,6 +59,10 @@ export async function addFeature(req: AddFeatureRequest, res: Response): Promise
5859
await db.prepare("run", 'INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)'
5960
, [userID, feature, adminUserID, Date.now()]);
6061
}
62+
63+
if (feature === Feature.DeArrowTitleSubmitter) {
64+
await verifyOldSubmissions(userID, await getVerificationValue(userID, false));
65+
}
6166
} else {
6267
await db.prepare("run", 'DELETE FROM "userFeatures" WHERE "userID" = ? AND "feature" = ?', [userID, feature]);
6368
}

src/routes/postBranding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async function updateVoteTotals(type: BrandingType, existingVote: ExistingVote,
173173
}
174174
}
175175

176-
async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise<number> {
176+
export async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): Promise<number> {
177177
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]);
178178
const sbSubmissions = () => db.prepare("get", `SELECT COUNT(*) as count FROM "sponsorTimes" WHERE "userID" = ? AND "votes" > 0 LIMIT 3`, [hashedUserID]);
179179

@@ -184,7 +184,7 @@ async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean):
184184
}
185185
}
186186

187-
async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise<void> {
187+
export async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise<void> {
188188
if (verification >= 0) {
189189
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]);
190190

0 commit comments

Comments
 (0)