Added neural block mock

This commit is contained in:
Ajay Ramachandran 2020-04-30 19:13:42 -04:00
parent 0cf84612e9
commit a278036f1d
5 changed files with 21 additions and 6 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]
"neuralBlockURL": "https://ai.neuralblock.app",
"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

@ -116,10 +116,12 @@ async function autoModerateSubmission(videoID, segments) {
return "One of your submitted segments is over 80% of the video.";
}
}
let neuralBlockURL = config.neuralBlockURL || "https://ai.neuralblock.app";
let overlap = false;
let response = await fetch("https://ai.neuralblock.app/api/getSponsorSegments?vid=" + videoID);
let response = await fetch(neuralBlockURL + "/api/getSponsorSegments?vid=" + videoID);
if (!response.ok) return false;
let nbPredictions = await response.json();

View file

@ -6,7 +6,8 @@
"youtubeAPIKey": "",
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
"behindProxy": true,
"db": "./test/databases/sponsorTimes.db",
"privateDB": "./test/databases/private.db",

View file

@ -108,7 +108,7 @@ describe('postSkipSegments', () => {
else if (res.statusCode === 403) done(); // pass
else done("non 403 status code: " + res.statusCode + " ("+body+")");
});
}).timeout(5000);
});
it("Should be accepted if only off by 5s", (done) => {
request.get(utils.getbaseURL()
@ -118,7 +118,7 @@ describe('postSkipSegments', () => {
else if (res.statusCode === 200) done(); // pass
else done("non 403 status code: " + res.statusCode + " ("+body+")");
});
}).timeout(5000);
});
it("Should be accepted if there's at least 65% overlap with NB" , (done) => {
request.get(utils.getbaseURL()
@ -128,7 +128,7 @@ describe('postSkipSegments', () => {
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " ("+body+")");
});
}).timeout(5000);
});
it('Should be allowed if youtube thinks duration is 0', (done) => {
request.get(utils.getbaseURL()
@ -138,7 +138,7 @@ describe('postSkipSegments', () => {
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " ("+body+")");
});
}).timeout(5000);
});
it('Should be rejected if not a valid videoID', (done) => {
request.get(utils.getbaseURL()

View file

@ -15,6 +15,17 @@ app.post('/CompletelyIncorrectReportWebhook', (req, res) => {
res.sendStatus(200);
});
app.get('/NeuralBlock/api/getSponsorSegments', (req, res) => {
if (req.query.vid === "LevkAjUE6d4") {
res.json({
sponsorSegments: [[0.47,7.549],[264.023,317.293]]
});
return;
}
res.sendStatus(500);
});
module.exports = function createMockServer(callback) {
return app.listen(config.mockPort, callback);
}