Aded option to proxy submisissions to another server to persist.

This commit is contained in:
Joe Dowd 2020-07-27 05:51:49 +01:00
parent b965e5bf56
commit 18f5d656de
2 changed files with 23 additions and 4 deletions

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