Merge pull request #105 from Joe-Dowd/proxy-submission

Proxy submission
This commit is contained in:
Ajay Ramachandran
2020-07-27 21:09:32 -04:00
committed by GitHub
3 changed files with 26 additions and 5 deletions

View File

@@ -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",

View File

@@ -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 + ".");
});

View File

@@ -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;