From 18f5d656de8610eeb25c64c989e29b28bb548113 Mon Sep 17 00:00:00 2001 From: Joe Dowd Date: Mon, 27 Jul 2020 05:51:49 +0100 Subject: [PATCH] Aded option to proxy submisissions to another server to persist. --- index.js | 2 +- src/routes/postSkipSegments.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5e4b977..61acd0c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ var config = require('./src/config.js'); var createServer = require('./src/app.js'); var server = createServer(() => { - console.log("Server started."); + console.log("Server started on port "+config.port+"."); }); \ No newline at end of file diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index ffbe767..01e6ee9 100644 --- a/src/routes/postSkipSegments.js +++ b/src/routes/postSkipSegments.js @@ -69,9 +69,13 @@ function sendDiscordNotification(userID, videoID, UUID, segmentInfo) { // submission: {videoID, startTime, endTime} // callback: function(reject: "String containing reason the submission was rejected") // returns: string when an error, false otherwise + +// Looks like this was broken for no defined youtube key - fixed but IMO we shouldn't return +// false for a pass - it was confusing and lead to this bug - any use of this function in +// the furute could have the same problem. async function autoModerateSubmission(submission, callback) { // Get the video information from the youtube API - if (config.youtubeAPI !== null) { + if (config.youtubeAPIKey !== null) { let {err, data} = await new Promise((resolve, reject) => { YouTubeAPI.videos.list({ part: "contentDetails", @@ -101,15 +105,30 @@ async function autoModerateSubmission(submission, callback) { } } else { - console.log("Skipped YouTube API"); + (config.mode === 'development') && console.log("Skipped YouTube API"); // Can't moderate the submission without calling the youtube API // so allow by default. - return; + return false; } } +function proxySubmission(req) { + console.log(req.body); + request.post(config.proxySubmission + '/api/skipSegments?userID='+req.query.userID+'&videoID='+req.query.videoID, {json: req.body}, (err, result) => { + if (!err) { + console.log('Proxy Sunmission: ' + result.statusCode + ' ('+result.body+')'); + } else { + console.log("Proxy Submission: Failed to make call"); + } + }); +} + module.exports = async function postSkipSegments(req, res) { + if (config.proxySubmission) { + proxySubmission(req); + } + let videoID = req.query.videoID || req.body.videoID; let userID = req.query.userID || req.body.userID;