Skip to content

Commit 47c109f

Browse files
committed
Fix act as vip unlocking segments
1 parent a921085 commit 47c109f

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/routes/postBranding.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,9 @@ export async function postBranding(req: Request, res: Response) {
104104
await verifyOldSubmissions(hashedUserID, verificationValue);
105105
}
106106

107-
if (isVip && !downvote) {
107+
if (isVip && !downvote && shouldLock) {
108108
// unlock all other titles
109-
if (shouldLock) {
110-
await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
111-
} else {
112-
await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND t."videoID" = ?`, [videoID]);
113-
}
109+
await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
114110
}
115111

116112
sendWebhooks(videoID, UUID).catch((e) => Logger.error(e));
@@ -152,13 +148,9 @@ export async function postBranding(req: Request, res: Response) {
152148
}
153149
}
154150

155-
if (isVip && !downvote) {
151+
if (isVip && !downvote && shouldLock) {
156152
// unlock all other titles
157-
if (shouldLock) {
158-
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
159-
} else {
160-
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."videoID" = ?`, [videoID]);
161-
}
153+
await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
162154
}
163155
}
164156
})()]);

test/cases/postBranding.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,21 @@ describe("postBranding", () => {
614614
});
615615

616616
assert.strictEqual(res.status, 200);
617-
const dbTitle = await queryTitleByVideo(videoID);
618-
const dbTitleVotes = await queryTitleVotesByUUID(dbTitle.UUID);
619-
const dbThumbnail = await queryThumbnailByVideo(videoID);
620-
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
617+
const dbTitles = await queryTitleByVideo(videoID, true);
618+
for (const dbTitle of dbTitles) {
619+
if (dbTitle.title === title.title) {
620+
const dbTitleVotes = await queryTitleVotesByUUID(dbTitle.UUID);
621+
assert.strictEqual(dbTitleVotes.locked, 0);
622+
}
623+
}
621624

622-
assert.strictEqual(dbTitleVotes.locked, 0);
623-
assert.strictEqual(dbThumbnailVotes.locked, 0);
625+
const dbThumbnails = await queryThumbnailByVideo(videoID, true);
626+
for (const dbThumbnail of dbThumbnails) {
627+
if (dbThumbnail.timestamp === thumbnail.timestamp) {
628+
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
629+
assert.strictEqual(dbThumbnailVotes.locked, 0);
630+
}
631+
}
624632
});
625633

626634
it("Downvote title and thumbnail as VIP", async () => {

0 commit comments

Comments
 (0)