first changes and timeout on 2nd test

This commit is contained in:
FlorianZahn
2021-10-02 04:39:54 +02:00
parent 99d72b92e4
commit bb2a007ed1
2 changed files with 190 additions and 33 deletions

View File

@@ -162,8 +162,8 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i
return res.sendStatus(finalResponse.finalStatus);
}
const videoInfo = (await db.prepare("get", `SELECT "category", "videoID", "hashedVideoID", "service", "userID" FROM "sponsorTimes" WHERE "UUID" = ?`,
[UUID])) as {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID};
const videoInfo = (await db.prepare("get", `SELECT "category", "videoID", "hashedVideoID", "service", "userID", "locked" FROM "sponsorTimes" WHERE "UUID" = ?`,
[UUID])) as {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID, locked: number};
if (!videoInfo) {
// Submission doesn't exist
return res.status(400).send("Submission doesn't exist.");
@@ -176,6 +176,20 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i
return res.status(400).send("Cannot vote for this category");
}
// Ignore vote if the next category is locked
const nextCategoryLocked = await db.prepare("get", `SELECT "videoID", "category" FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?`, [videoInfo.videoID, category]);
if (nextCategoryLocked) {
if (!isVIP) {
return res.status(200);
} // In an else statement, add a warning in the future for VIPs, that the next category is locked
}
// Ignore vote if the segment is locked
if (!isVIP && videoInfo.locked === 1) {
console.log("dalfäkjsdöfbsdfoöjasdökjb");
return res.status(200);
}
const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category]);
const timeSubmitted = Date.now();
@@ -424,7 +438,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
//oldIncrementAmount will be zero is row is null
await db.prepare("run", `UPDATE "sponsorTimes" SET "${columnName}" = "${columnName}" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]);
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
// Unide and Lock this submission
// Unhide and Lock this submission
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
// Reset video duration in case that caused it to be hidden