diff --git a/config.json.example b/config.json.example index c548ffc..ea5bfc6 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] + "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", diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index 7a52bc3..d48737e 100644 --- a/src/routes/postSkipSegments.js +++ b/src/routes/postSkipSegments.js @@ -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(); diff --git a/test.json b/test.json index 28373a1..86ba466 100644 --- a/test.json +++ b/test.json @@ -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", diff --git a/test/cases/postSkipSegments.js b/test/cases/postSkipSegments.js index b5fae77..c3559be 100644 --- a/test/cases/postSkipSegments.js +++ b/test/cases/postSkipSegments.js @@ -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() diff --git a/test/mocks.js b/test/mocks.js index b58a47f..4e2ad92 100644 --- a/test/mocks.js +++ b/test/mocks.js @@ -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); } \ No newline at end of file