mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 04:57:04 +03:00
Aded option to proxy submisissions to another server to persist.
This commit is contained in:
2
index.js
2
index.js
@@ -1,5 +1,5 @@
|
|||||||
var config = require('./src/config.js');
|
var config = require('./src/config.js');
|
||||||
var createServer = require('./src/app.js');
|
var createServer = require('./src/app.js');
|
||||||
var server = createServer(() => {
|
var server = createServer(() => {
|
||||||
console.log("Server started.");
|
console.log("Server started on port "+config.port+".");
|
||||||
});
|
});
|
||||||
@@ -69,9 +69,13 @@ function sendDiscordNotification(userID, videoID, UUID, segmentInfo) {
|
|||||||
// submission: {videoID, startTime, endTime}
|
// submission: {videoID, startTime, endTime}
|
||||||
// callback: function(reject: "String containing reason the submission was rejected")
|
// callback: function(reject: "String containing reason the submission was rejected")
|
||||||
// returns: string when an error, false otherwise
|
// 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) {
|
async function autoModerateSubmission(submission, callback) {
|
||||||
// Get the video information from the youtube API
|
// Get the video information from the youtube API
|
||||||
if (config.youtubeAPI !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let {err, data} = await new Promise((resolve, reject) => {
|
let {err, data} = await new Promise((resolve, reject) => {
|
||||||
YouTubeAPI.videos.list({
|
YouTubeAPI.videos.list({
|
||||||
part: "contentDetails",
|
part: "contentDetails",
|
||||||
@@ -101,15 +105,30 @@ async function autoModerateSubmission(submission, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("Skipped YouTube API");
|
(config.mode === 'development') && console.log("Skipped YouTube API");
|
||||||
|
|
||||||
// Can't moderate the submission without calling the youtube API
|
// Can't moderate the submission without calling the youtube API
|
||||||
// so allow by default.
|
// 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) {
|
module.exports = async function postSkipSegments(req, res) {
|
||||||
|
if (config.proxySubmission) {
|
||||||
|
proxySubmission(req);
|
||||||
|
}
|
||||||
|
|
||||||
let videoID = req.query.videoID || req.body.videoID;
|
let videoID = req.query.videoID || req.body.videoID;
|
||||||
let userID = req.query.userID || req.body.userID;
|
let userID = req.query.userID || req.body.userID;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user