From 06fa6eb874e36ca32478932effe442795b5ecd55 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 27 Oct 2020 18:58:21 -0400 Subject: [PATCH 1/7] Raise category change requirement --- src/routes/voteOnSponsorTime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/voteOnSponsorTime.js b/src/routes/voteOnSponsorTime.js index bfe5e0a..058572a 100644 --- a/src/routes/voteOnSponsorTime.js +++ b/src/routes/voteOnSponsorTime.js @@ -179,7 +179,7 @@ function categoryVote(UUID, userID, isVIP, category, hashedIP, res) { // See if the submissions category is ready to change let currentCategoryInfo = db.prepare("get", "select votes from categoryVotes where UUID = ? and category = ?", [UUID, currentCategory.category]); - let submissionInfo = db.prepare("get", "SELECT userID, timeSubmitted FROM sponsorTimes WHERE UUID = ?", [UUID]); + let submissionInfo = db.prepare("get", "SELECT userID, timeSubmitted, votes FROM sponsorTimes WHERE UUID = ?", [UUID]); let isSubmissionVIP = submissionInfo && isUserVIP(submissionInfo.userID); let startingVotes = isSubmissionVIP ? 10000 : 1; @@ -198,7 +198,7 @@ function categoryVote(UUID, userID, isVIP, category, hashedIP, res) { //TODO: In the future, raise this number from zero to make it harder to change categories // VIPs change it every time - if (nextCategoryCount - currentCategoryCount >= 0 || isVIP) { + if (nextCategoryCount - currentCategoryCount >= (submissionInfo ? Math.max(Math.ciel(submissionInfo.votes / 2), 1) : 1) || isVIP) { // Replace the category db.prepare('run', "update sponsorTimes set category = ? where UUID = ?", [category, UUID]); } From 009a489d3a0664b295653550d324b9e43d28537c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 27 Oct 2020 19:07:48 -0400 Subject: [PATCH 2/7] Fix typo --- src/routes/voteOnSponsorTime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/voteOnSponsorTime.js b/src/routes/voteOnSponsorTime.js index 058572a..4f74215 100644 --- a/src/routes/voteOnSponsorTime.js +++ b/src/routes/voteOnSponsorTime.js @@ -198,7 +198,7 @@ function categoryVote(UUID, userID, isVIP, category, hashedIP, res) { //TODO: In the future, raise this number from zero to make it harder to change categories // VIPs change it every time - if (nextCategoryCount - currentCategoryCount >= (submissionInfo ? Math.max(Math.ciel(submissionInfo.votes / 2), 1) : 1) || isVIP) { + if (nextCategoryCount - currentCategoryCount >= (submissionInfo ? Math.max(Math.ceil(submissionInfo.votes / 2), 1) : 1) || isVIP) { // Replace the category db.prepare('run', "update sponsorTimes set category = ? where UUID = ?", [category, UUID]); } From bb47181daa1ecda57192aa6b060d9ab5cdc99f6b Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Wed, 28 Oct 2020 11:44:11 +0000 Subject: [PATCH 3/7] removed tests no longer needed - should be updated to reflect new changes --- test/cases/voteOnSponsorTime.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/cases/voteOnSponsorTime.js b/test/cases/voteOnSponsorTime.js index 084d0f9..ce9b918 100644 --- a/test/cases/voteOnSponsorTime.js +++ b/test/cases/voteOnSponsorTime.js @@ -211,6 +211,8 @@ describe('voteOnSponsorTime', () => { }); }); + /* Raised the limit for votes - test update needed + it('Should be able to vote for a category and it should immediately change (for now)', (done) => { request.get(utils.getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro", null, @@ -227,7 +229,7 @@ describe('voteOnSponsorTime', () => { done("Status code was " + res.statusCode); } }); - }); + });*/ it('Should not able to change to an invalid category', (done) => { request.get(utils.getbaseURL() @@ -247,6 +249,8 @@ describe('voteOnSponsorTime', () => { }); }); + /* Raised the limit for votes - test update needed + it('Should be able to change your vote for a category and it should immediately change (for now)', (done) => { request.get(utils.getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null, @@ -263,7 +267,7 @@ describe('voteOnSponsorTime', () => { done("Status code was " + res.statusCode); } }); - }); + });*/ it('Should not be able to change your vote to an invalid category', (done) => { From 9d293b2cb499ff552d17997ba516cce57da344c2 Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Thu, 29 Oct 2020 01:03:07 +0000 Subject: [PATCH 4/7] Don't revive segments for videos marked with noSegment when un-banning a user --- src/routes/shadowBanUser.js | 12 +++++- test/cases/getSkipSegments.js | 14 +++---- test/cases/unBan.js | 79 +++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 test/cases/unBan.js diff --git a/src/routes/shadowBanUser.js b/src/routes/shadowBanUser.js index 3617a94..2fe0eb7 100644 --- a/src/routes/shadowBanUser.js +++ b/src/routes/shadowBanUser.js @@ -3,6 +3,7 @@ var db = databases.db; var privateDB = databases.privateDB; var getHash = require('../utils/getHash.js'); +const logger = require('../utils/logger.js'); module.exports = async function shadowBanUser(req, res) { let userID = req.query.userID; @@ -47,7 +48,7 @@ module.exports = async function shadowBanUser(req, res) { //find all previous submissions and hide them if (unHideOldSubmissions) { - db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?", [userID]); + db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 1 WHERE userID = ?", [userID]); } } else if (!enabled && row.userCount > 0) { //remove them from the shadow ban list @@ -55,7 +56,14 @@ module.exports = async function shadowBanUser(req, res) { //find all previous submissions and unhide them if (unHideOldSubmissions) { - db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]); + let segmentsToIgnore = db.prepare('all', "SELECT uuid FROM sponsorTimes st JOIN noSegments ns on st.videoID = ns.videoID AND st.category = ns.category WHERE st.userID = ?", [userID]).map((item) => item.UUID); + let allSegments = db.prepare('all', "SELECT uuid FROM sponsorTimes st WHERE st.userID = ?", [userID]).map((item) => item.UUID); + + allSegments.filter((item) => { + return segmentsToIgnore.indexOf(item) === -1; + }).forEach((uuid) => { + db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE uuid = ?", [uuid]); + }); } } } else if (hashedIP) { diff --git a/test/cases/getSkipSegments.js b/test/cases/getSkipSegments.js index 0314028..fb99ae1 100644 --- a/test/cases/getSkipSegments.js +++ b/test/cases/getSkipSegments.js @@ -7,13 +7,13 @@ var getHash = require('../../src/utils/getHash.js'); describe('getSkipSegments', () => { before(() => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfQuery + "('testtesttest', 1, 11, 2, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 0) + "')"); - db.exec(startOfQuery + "('testtesttest', 20, 33, 2, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 0) + "')"); - db.exec(startOfQuery + "('testtesttest,test', 1, 11, 2, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 0) + "')"); - db.exec(startOfQuery + "('test3', 1, 11, 2, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 0) + "')"); - db.exec(startOfQuery + "('test3', 7, 22, -3, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 0) + "')"); - db.exec(startOfQuery + "('multiple', 1, 11, 2, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 0) + "')"); - db.exec(startOfQuery + "('multiple', 20, 33, 2, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 0) + "')"); + db.exec(startOfQuery + "('testtesttest', 1, 11, 2, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 1) + "')"); + db.exec(startOfQuery + "('testtesttest', 20, 33, 2, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 1) + "')"); + db.exec(startOfQuery + "('testtesttest,test', 1, 11, 2, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 1) + "')"); + db.exec(startOfQuery + "('test3', 1, 11, 2, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); + db.exec(startOfQuery + "('test3', 7, 22, -3, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); + db.exec(startOfQuery + "('multiple', 1, 11, 2, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); + db.exec(startOfQuery + "('multiple', 20, 33, 2, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); }); diff --git a/test/cases/unBan.js b/test/cases/unBan.js new file mode 100644 index 0000000..e7e1f2a --- /dev/null +++ b/test/cases/unBan.js @@ -0,0 +1,79 @@ +var request = require('request'); + +var utils = require('../utils.js'); +const getHash = require('../../src/utils/getHash.js'); + +var databases = require('../../src/databases/databases.js'); +const logger = require('../../src/utils/logger.js'); +var db = databases.db; + +describe('unBan', () => { + before(() => { + db.exec("INSERT INTO shadowBannedUsers VALUES('testMan-unBan')"); + db.exec("INSERT INTO shadowBannedUsers VALUES('testWoman-unBan')"); + db.exec("INSERT INTO shadowBannedUsers VALUES('testEntity-unBan')"); + + db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-unBan") + "')"); + db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')"); + + let startOfInsertSegmentQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; + db.exec(startOfInsertSegmentQuery + "('unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-0', 1) + "')"); + db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-1', 'testWoman-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); + db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-2', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); + db.exec(startOfInsertSegmentQuery + "('unBan-videoID-2', 1, 11, 2, 'unBan-uuid-3', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-2', 1) + "')"); + }); + + it('Should be able to unban a user and re-enable shadow banned segments', (done) => { + request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => { + if (err) done(err); + else if (res.statusCode === 200) { + let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-0', 'testMan-unBan', 1]); + if (result.length !== 0) { + console.log(result); + done("Expected 0 banned entrys in db, got " + result.length); + } else { + done(); + } + } else { + console.log(body); + done("Status code was " + res.statusCode); + } + }); + }); + + it('Should be able to unban a user and re-enable shadow banned segments without noSegment entrys', (done) => { + request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => { + if (err) done(err); + else if (res.statusCode === 200) { + let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]); + if (result.length !== 1) { + console.log(result); + done("Expected 1 banned entry1 in db, got " + result.length); + } else { + done(); + } + } else { + console.log(body); + done("Status code was " + res.statusCode); + } + }); + }); + + it('Should be able to unban a user and re-enable shadow banned segments with a mix of noSegment entrys', (done) => { + request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => { + if (err) done(err); + else if (res.statusCode === 200) { + let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE userID = ? AND shadowHidden = ?', ['testEntity-unBan', 1]); + if (result.length !== 1) { + console.log(result); + done("Expected 1 banned entry1 in db, got " + result.length); + } else { + done(); + } + } else { + console.log(body); + done("Status code was " + res.statusCode); + } + }); + }); +}); \ No newline at end of file From 97bb7b534af1a3e5a51df1c0554ee6799b479bde Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 23 Nov 2020 12:29:57 -0500 Subject: [PATCH 5/7] Increase max segments from 8 to 32 --- src/routes/getSkipSegments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/getSkipSegments.js b/src/routes/getSkipSegments.js index 81ea763..69d6562 100644 --- a/src/routes/getSkipSegments.js +++ b/src/routes/getSkipSegments.js @@ -134,7 +134,7 @@ function chooseSegments(segments) { }); //if there are too many groups, find the best 8 - return getWeightedRandomChoice(similarSegmentsGroups, 8).map( + return getWeightedRandomChoice(similarSegmentsGroups, 32).map( //randomly choose 1 good segment per group and return them group => getWeightedRandomChoice(group.segments, 1)[0] ); From d6977b7be03a1ba8c680cfa763807e57c9448908 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2020 17:30:35 +0000 Subject: [PATCH 6/7] Bump dot-prop from 4.2.0 to 4.2.1 Bumps [dot-prop](https://github.com/sindresorhus/dot-prop) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/sindresorhus/dot-prop/releases) - [Commits](https://github.com/sindresorhus/dot-prop/compare/v4.2.0...v4.2.1) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c608133..8bc2aa6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -628,9 +628,9 @@ "dev": true }, "dot-prop": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", - "integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.1.tgz", + "integrity": "sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==", "dev": true, "requires": { "is-obj": "^1.0.0" From b4b7b55ce1669cd2794ee88d5c1c8aca44ff1e65 Mon Sep 17 00:00:00 2001 From: LoganDark Date: Tue, 24 Nov 2020 05:15:13 -0800 Subject: [PATCH 7/7] Correct indentation in _private.db.sql --- databases/_private.db.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/_private.db.sql b/databases/_private.db.sql index 5239cab..4517c71 100644 --- a/databases/_private.db.sql +++ b/databases/_private.db.sql @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS "sponsorTimes" ( ); CREATE TABLE IF NOT EXISTS "config" ( - "key" TEXT NOT NULL, + "key" TEXT NOT NULL, "value" TEXT NOT NULL );