From 9ea98b2e2b74675b2b396fb4419816567e740b8a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 30 Aug 2020 11:33:44 -0400 Subject: [PATCH 1/5] Fix all submissions being sent to first time submissions channel --- src/routes/postSkipSegments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index f007b6f..1af0721 100644 --- a/src/routes/postSkipSegments.js +++ b/src/routes/postSkipSegments.js @@ -63,7 +63,7 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) { // If it is a first time submission // Then send a notification to discord - if (config.discordFirstTimeSubmissionsWebhookURL === null) return; + if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount <= 1) return; request.post(config.discordFirstTimeSubmissionsWebhookURL, { json: { "embeds": [{ From 168229e6020b1519c1c1ca892c1d2015d3f6aa56 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 30 Aug 2020 11:55:19 -0400 Subject: [PATCH 2/5] Fixed first time submissions webhook only sending for non first time submissions --- src/routes/postSkipSegments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index 1af0721..799711f 100644 --- a/src/routes/postSkipSegments.js +++ b/src/routes/postSkipSegments.js @@ -63,7 +63,7 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) { // If it is a first time submission // Then send a notification to discord - if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount <= 1) return; + if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount > 1) return; request.post(config.discordFirstTimeSubmissionsWebhookURL, { json: { "embeds": [{ From fd81096f6389622ec824d4638eb8d82c6d4a9db0 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 31 Aug 2020 14:03:12 -0400 Subject: [PATCH 3/5] Allow all VIP to ban --- src/routes/shadowBanUser.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/routes/shadowBanUser.js b/src/routes/shadowBanUser.js index ba5052e..3617a94 100644 --- a/src/routes/shadowBanUser.js +++ b/src/routes/shadowBanUser.js @@ -1,5 +1,3 @@ -var config = require('../config.js'); - var databases = require('../databases/databases.js'); var db = databases.db; var privateDB = databases.privateDB; @@ -30,7 +28,8 @@ module.exports = async function shadowBanUser(req, res) { //hash the userID adminUserIDInput = getHash(adminUserIDInput); - if (adminUserIDInput !== config.adminUserID) { + let isVIP = db.prepare("get", "SELECT count(*) as userCount FROM vipUsers WHERE userID = ?", [adminUserIDInput]).userCount > 0; + if (!isVIP) { //not authorized res.sendStatus(403); return; From b0dc79d071e7d0417ceb74db9a687c4b89bd5b8d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 31 Aug 2020 22:17:24 -0400 Subject: [PATCH 4/5] Send max of API users or extension users --- src/routes/getTotalStats.js | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/routes/getTotalStats.js b/src/routes/getTotalStats.js index d2be079..6d3841e 100644 --- a/src/routes/getTotalStats.js +++ b/src/routes/getTotalStats.js @@ -12,28 +12,30 @@ let apiUsersCache = null; let lastUserCountCheck = 0; module.exports = function getTotalStats (req, res) { - let row = db.prepare('get', "SELECT COUNT(DISTINCT userID) as userCount, COUNT(*) as totalSubmissions, " + + let row = db.prepare('get', "SELECT COUNT(DISTINCT userID) as userCount, COUNT(*) as totalSubmissions, " + "SUM(views) as viewCount, SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE shadowHidden != 1 AND votes >= 0", []); - if (row !== undefined) { - //send this result - res.send({ - userCount: row.userCount, - activeUsers: chromeUsersCache + firefoxUsersCache, - apiUsers: apiUsersCache, - viewCount: row.viewCount, - totalSubmissions: row.totalSubmissions, - minutesSaved: row.minutesSaved - }); + if (row !== undefined) { + let extensionUsers = chromeUsersCache + firefoxUsersCache; - // Check if the cache should be updated (every ~14 hours) - let now = Date.now(); - if (now - lastUserCountCheck > 5000000) { - lastUserCountCheck = now; + //send this result + res.send({ + userCount: row.userCount, + activeUsers: extensionUsers, + apiUsers: Math.max(apiUsersCache, extensionUsers), + viewCount: row.viewCount, + totalSubmissions: row.totalSubmissions, + minutesSaved: row.minutesSaved + }); - updateExtensionUsers(); - } - } + // Check if the cache should be updated (every ~14 hours) + let now = Date.now(); + if (now - lastUserCountCheck > 5000000) { + lastUserCountCheck = now; + + updateExtensionUsers(); + } + } } function updateExtensionUsers() { From a053d87bd2d43d2c45504375217e7505ecd24b42 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 3 Sep 2020 12:04:49 -0400 Subject: [PATCH 5/5] Catch user counter errors --- src/middleware/userCounter.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/middleware/userCounter.js b/src/middleware/userCounter.js index 183e1b4..85be545 100644 --- a/src/middleware/userCounter.js +++ b/src/middleware/userCounter.js @@ -1,11 +1,16 @@ var request = require('request'); -var config = require('../config.js'); -var getIP = require('../utils/getIP.js'); +const config = require('../config.js'); +const getIP = require('../utils/getIP.js'); const getHash = require('../utils/getHash.js'); +const logger = require('../utils/logger.js'); module.exports = function userCounter(req, res, next) { - request.post(config.userCounterURL + "/api/v1/addIP?hashedIP=" + getHash(getIP(req), 1)); + try { + request.post(config.userCounterURL + "/api/v1/addIP?hashedIP=" + getHash(getIP(req), 1)); + } catch(e) { + logger.debug("Failing to connect to user counter at: " + config.userCounterURL); + } next(); } \ No newline at end of file