From a213d2be020b4076207133af737ba4250aef9fc3 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 17 Jul 2019 17:13:43 -0400 Subject: [PATCH 1/2] Fixed it not checking if there are more than 4 choices to choose from. --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 5c62dad..efe540a 100644 --- a/index.js +++ b/index.js @@ -241,7 +241,9 @@ function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) { } //if there are too many indexes, find the best 4 - finalSponsorTimeIndexes = getWeightedRandomChoice(finalSponsorTimeIndexes, votes, 4).finalChoices; + if (finalSponsorTimeIndexes.length > 4) { + finalSponsorTimeIndexes = getWeightedRandomChoice(finalSponsorTimeIndexes, votes, 4).finalChoices; + } //convert this to a final array to return let finalSponsorTimes = []; From 03fcda5e3b476020d3c983f43ed332a8ead87ae7 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 17 Jul 2019 19:09:45 -0400 Subject: [PATCH 2/2] Fixed post method not setting a default for votes. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index efe540a..1d66337 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,7 @@ app.get('/api/postVideoSponsorTimes', function (req, res) { if (row == null) { //not a duplicate, execute query - db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, UUID, userID, hashedIP, timeSubmitted); + db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, 0, UUID, userID, hashedIP, timeSubmitted); res.sendStatus(200); } else {