diff --git a/config.json.example b/config.json.example index c548ffc..22971d9 100644 --- a/config.json.example +++ b/config.json.example @@ -8,6 +8,7 @@ "discordReportChannelWebhookURL": null, //URL from discord if you would like notifications when someone makes a report [optional] "discordFirstTimeSubmissionsWebhookURL": null, //URL from discord if you would like notifications when someone makes a first time submission [optional] "discordCompletelyIncorrectReportWebhookURL": null, //URL from discord if you would like notifications when someone reports a submission as completely incorrect [optional] + "proxySubmission": null, // Base url to proxy submissions to persist // e.g. https://sponsor.ajay.app (no trailing slash) "behindProxy": "X-Forwarded-For", //Options: "X-Forwarded-For", "Cloudflare", "X-Real-IP", anything else will mean it is not behind a proxy. True defaults to "X-Forwarded-For" "db": "./databases/sponsorTimes.db", "privateDB": "./databases/private.db", diff --git a/index.js b/index.js index 5e4b977..508c089 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."); -}); \ No newline at end of file + console.log("Server started on port " + config.port + "."); +}); diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index f575e53..eb8d940 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 future 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,31 @@ async function autoModerateSubmission(submission, callback) { } } else { - console.log("Skipped YouTube API"); + if (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) { + request.post(config.proxySubmission + '/api/skipSegments?userID='+req.query.userID+'&videoID='+req.query.videoID, {json: req.body}, (err, result) => { + if (config.mode === 'development') { + if (!err) { + console.log('Proxy Submission: ' + 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;