diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 56f0047..63c93f2 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -70,8 +70,11 @@ export async function postBranding(req: Request, res: Response) { await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]); + const verificationValue = await getVerificationValue(hashedUserID, isVip); await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, 0, ?, 0, ?);`, - [UUID, isVip ? 1 : 0, await getVerificationValue(hashedUserID, isVip)]); + [UUID, isVip ? 1 : 0, verificationValue]); + + await verifyOldSubmissions(hashedUserID, verificationValue); } if (isVip) { @@ -168,4 +171,22 @@ async function getVerificationValue(hashedUserID: HashedUserID, isVip: boolean): } else { return -1; } +} + +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"`, [hashedUserID, verification]); + + if (unverifiedSubmissions.length > 0) { + for (const submission of unverifiedSubmissions) { + QueryCacher.clearBrandingCache({ + videoID: submission.videoID, + hashedVideoID: submission.hashedVideoID, + service: submission.service + }); + } + + await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, hashedUserID, verification]); + } + } } \ No newline at end of file diff --git a/test/cases/postBranding.ts b/test/cases/postBranding.ts index 95eff6a..5119b4c 100644 --- a/test/cases/postBranding.ts +++ b/test/cases/postBranding.ts @@ -547,6 +547,13 @@ describe("postBranding", () => { assert.strictEqual(dbTitle.original, title.original ? 1 : 0); assert.strictEqual(dbVotes.verification, 0); + + // Other segments now verified too + const dbVotes2 = await queryTitleVotesByUUID("postBrandVerified1"); + assert.strictEqual(dbVotes2.verification, 0); + + const dbVotes3 = await queryTitleVotesByUUID("postBrandVerified2"); + assert.strictEqual(dbVotes3.verification, 0); }); it("Submit from verified user from SponsorBlock submissions", async () => {