From 11c099c3dc5db1f445bf91e3c111a1d35ca3388b Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 23 Jul 2019 17:59:19 -0400 Subject: [PATCH 1/3] Made server save and report viewCount. --- index.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/index.js b/index.js index 102e55bb..e5e5c864 100644 --- a/index.js +++ b/index.js @@ -207,6 +207,47 @@ app.get('/api/voteOnSponsorTime', function (req, res) { }); }); +//Endpoint when a sponsorTime is used up +app.get('/api/viewedVideoSponsorTime', function (req, res) { + let UUID = req.query.UUID; + + if (UUID == undefined) { + //invalid request + res.sendStatus(400); + return; + } + + //up the view count by one + db.prepare("UPDATE sponsorTimes SET views = views + 1 WHERE UUID = ?").run(UUID); + + res.sendStatus(200); +}); + +//Gets all the views added up for one userID +//Useful to see how much one user has contributed +app.get('/api/getViewsForUser', function (req, res) { + let userID = req.query.userID; + + if (userID == undefined) { + //invalid request + res.sendStatus(400); + return; + } + + //up the view count by one + db.prepare("SELECT SUM(views) as viewCount FROM sponsorTimes WHERE userID = ?").get(userID, function(err, row) { + if (err) console.log(err); + + if (row != null) { + res.send({ + viewCount: row.viewCount + }); + } else { + res.send(404); + } + }); +}); + app.get('/database.db', function (req, res) { res.sendFile("./databases/sponsorTimes.db", { root: __dirname }); }); From db8c2e76e5ab05ec1159f35815ada344ba9a1332 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 23 Jul 2019 18:31:42 -0400 Subject: [PATCH 2/3] Updated posting to work with extra database column. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e5e5c864..f41c9bcc 100644 --- a/index.js +++ b/index.js @@ -129,7 +129,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, 0, UUID, userID, hashedIP, timeSubmitted); + db.prepare("INSERT INTO sponsorTimes VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)").run(videoID, startTime, endTime, 0, UUID, userID, hashedIP, timeSubmitted, 0); res.sendStatus(200); } else { From ab0631ff63889e2ef4a735eb79f0cc1fd9d68bee Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 23 Jul 2019 19:06:43 -0400 Subject: [PATCH 3/3] Prevented sponsor segments less than 1 seconds from being submitted. --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f41c9bcc..8a9ddc2a 100644 --- a/index.js +++ b/index.js @@ -84,7 +84,9 @@ app.get('/api/postVideoSponsorTimes', function (req, res) { let endTime = req.query.endTime; let userID = req.query.userID; - if (videoID == undefined || startTime == undefined || endTime == undefined || userID == undefined) { + //check if all correct inputs are here and the length is 1 second or more + if (videoID == undefined || startTime == undefined || endTime == undefined || userID == undefined + || Math.abs(startTime - endTime) < 1) { //invalid request res.sendStatus(400); return;