Merge branch 'testing' of https://github.com/ajayyy/SponsorBlockServer into nb-mod-fetch

# Conflicts:
#	src/routes/postSkipSegments.js
#	test/cases/postSkipSegments.js
This commit is contained in:
Ajay Ramachandran
2020-04-30 18:44:49 -04:00
9 changed files with 66 additions and 22 deletions

View File

@@ -26,7 +26,6 @@ var getDaysSavedFormatted = require('./routes/getDaysSavedFormatted.js');
var oldGetVideoSponsorTimes = require('./routes/oldGetVideoSponsorTimes.js');
var oldSubmitSponsorTimes = require('./routes/oldSubmitSponsorTimes.js');
//setup CORS correctly
app.use(corsMiddleware);
app.use(loggerMiddleware);
@@ -35,6 +34,9 @@ app.use(express.json())
// Setup pretty JSON
if (config.mode === "development") app.set('json spaces', 2);
// Set production mode
app.set('env', config.mode || 'production');
//add the get function
app.get('/api/getVideoSponsorTimes', oldGetVideoSponsorTimes);
@@ -82,10 +84,10 @@ app.get('/api/getTopUsers', getTopUsers);
app.get('/api/getTotalStats', getTotalStats);
//send out a formatted time saved total
app.get('/api/getdayssavedformatted', getDaysSavedFormatted);
app.get('/api/getDaysSavedFormatted', getDaysSavedFormatted);
app.get('/database.db', function (req, res) {
res.sendfile("./databases/sponsortimes.db", { root: __dirname });
res.sendFile("./databases/sponsorTimes.db", { root: "./" });
});
// Create an HTTP service.

View File

@@ -1,12 +1,12 @@
var db = require('../databases/databases.js');
var db = require('../databases/databases.js').db;
module.exports = function getDaysSavedFormatted (req, res) {
let row = db.prepare("select sum((endtime - starttime) / 60 / 60 / 24 * views) as dayssaved from sponsortimes where shadowhidden != 1").get();
let row = db.prepare("SELECT SUM((endTime - startTime) / 60 / 60 / 24 * views) as daysSaved from sponsorTimes where shadowHidden != 1").get();
if (row !== undefined) {
//send this result
res.send({
dayssaved: row.dayssaved.tofixed(2)
daysSaved: row.daysSaved.toFixed(2)
});
}
}
}

View File

@@ -102,13 +102,16 @@ async function autoModerateSubmission(submission, callback) {
} else {
// Check to see if video exists
if (data.pageInfo.totalResults === 0) {
callback("No video exists with id " + submission.videoID);
return "No video exists with id " + submission.videoID;
} else {
let duration = data.items[0].contentDetails.duration;
duration = isoDurations.toSeconds(isoDurations.parse(duration));
// Reject submission if over 80% of the video
if ((submission.endTime - submission.startTime) > (duration/100) * 80) {
if (duration == 0) {
// Allow submission if the duration is 0 (bug in youtube api)
return false;
} else if ((submission.endTime - submission.startTime) > (duration / 100) * 80) {
// Reject submission if over 80% of the video
return "Sponsor segment is over 80% of the video.";
} else {
let overlap = false;

View File

@@ -86,7 +86,11 @@ module.exports = async function voteOnSponsorTime(req, res) {
// Send discord message
if (type != 1) {
// Get video ID
let submissionInfoRow = db.prepare("SELECT videoID, userID, startTime, endTime FROM sponsorTimes WHERE UUID = ?").get(UUID);
let submissionInfoRow = db.prepare("SELECT s.videoID, s.userID, s.startTime, s.endTime, u.userName, "+
"(select count(1) from sponsorTimes where userID = s.userID) count, "+
"(select count(1) from sponsorTimes where userID = s.userID and votes <= -2) disregarded "+
"FROM sponsorTimes s inner join userNames u on s.userID = u.userID where s.UUID=?"
).get(UUID);
let userSubmissionCountRow = db.prepare("SELECT count(*) as submissionCount FROM sponsorTimes WHERE userID = ?").get(nonAnonUserID);
@@ -104,11 +108,14 @@ module.exports = async function voteOnSponsorTime(req, res) {
json: {
"embeds": [{
"title": data.items[0].snippet.title,
"url": "https://www.youtube.com/watch?v=" + submissionInfoRow.videoID +
"&t=" + (submissionInfoRow.startTime.toFixed(0) - 2),
"description": "**" + row.votes + " Votes Prior | " + (row.votes + incrementAmount - oldIncrementAmount) + " Votes Now | " + row.views +
" Views**\n\nSubmission ID: " + UUID +
"\n\nSubmitted by: " + submissionInfoRow.userID + "\n\nTimestamp: " +
"url": "https://www.youtube.com/watch?v=" + submissionInfoRow.videoID
+ "&t=" + (submissionInfoRow.startTime.toFixed(0) - 2),
"description": "**" + row.votes + " Votes Prior | " + (row.votes + incrementAmount - oldIncrementAmount) + " Votes Now | " + row.views
+ " Views**\n\n**Submission ID:** " + UUID
+ "\n\n**Submitted by:** "+submissionInfoRow.userName+"\n " + submissionInfoRow.userID
+ "\n\n**Total User Submissions:** "+submissionInfoRow.count
+ "\n**Ignored User Submissions:** "+submissionInfoRow.disregarded
+"\n\n**Timestamp:** " +
getFormattedTime(submissionInfoRow.startTime) + " to " + getFormattedTime(submissionInfoRow.endTime),
"color": 10813440,
"author": {
@@ -167,5 +174,6 @@ module.exports = async function voteOnSponsorTime(req, res) {
res.sendStatus(200);
} catch (err) {
console.error(err);
res.status(500).json({error: 'Internal error creating segment vote'});
}
}