Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into Dainius14/master

# Conflicts:
#	src/routes/shadowBanUser.js
#	src/routes/voteOnSponsorTime.ts
#	test/cases/getSkipSegments.js
#	test/cases/voteOnSponsorTime.js
This commit is contained in:
Ajay Ramachandran
2020-12-07 17:35:15 -05:00
8 changed files with 107 additions and 16 deletions

View File

@@ -132,7 +132,7 @@ function chooseSegments(segments: any[]) {
});
//if there are too many groups, find the best 8
return getWeightedRandomChoice(similarSegmentsGroups, 8).map(
return getWeightedRandomChoice(similarSegmentsGroups, 32).map(
//randomly choose 1 good segment per group and return them
group => getWeightedRandomChoice(group.segments, 1)[0],
);

View File

@@ -2,7 +2,6 @@ import {db, privateDB} from '../databases/databases';
import {getHash} from '../utils/getHash';
import {Request, Response} from 'express';
export async function shadowBanUser(req: Request, res: Response) {
const userID = req.query.userID as string;
const hashedIP = req.query.hashedIP as string;
@@ -51,7 +50,17 @@ export async function shadowBanUser(req: Request, res: Response) {
//find all previous submissions and unhide them
if (unHideOldSubmissions) {
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE userID = ?", [userID]);
let segmentsToIgnore = db.prepare('all', "SELECT UUID FROM sponsorTimes st "
+ "JOIN noSegments ns on st.videoID = ns.videoID AND st.category = ns.category WHERE st.userID = ?"
, [userID]).map((item: {UUID: string}) => item.UUID);
let allSegments = db.prepare('all', "SELECT UUID FROM sponsorTimes st WHERE st.userID = ?", [userID])
.map((item: {UUID: string}) => item.UUID);
allSegments.filter((item: {uuid: string}) => {
return segmentsToIgnore.indexOf(item) === -1;
}).forEach((UUID: string) => {
db.prepare('run', "UPDATE sponsorTimes SET shadowHidden = 0 WHERE UUID = ?", [UUID]);
});
}
}
}

View File

@@ -179,7 +179,7 @@ function categoryVote(UUID: string, userID: string, isVIP: boolean, category: an
// See if the submissions category is ready to change
const currentCategoryInfo = db.prepare("get", "select votes from categoryVotes where UUID = ? and category = ?", [UUID, currentCategory.category]);
const submissionInfo = db.prepare("get", "SELECT userID, timeSubmitted FROM sponsorTimes WHERE UUID = ?", [UUID]);
const submissionInfo = db.prepare("get", "SELECT userID, timeSubmitted, votes FROM sponsorTimes WHERE UUID = ?", [UUID]);
const isSubmissionVIP = submissionInfo && isUserVIP(submissionInfo.userID);
const startingVotes = isSubmissionVIP ? 10000 : 1;
@@ -198,7 +198,7 @@ function categoryVote(UUID: string, userID: string, isVIP: boolean, category: an
//TODO: In the future, raise this number from zero to make it harder to change categories
// VIPs change it every time
if (nextCategoryCount - currentCategoryCount >= 0 || isVIP) {
if (nextCategoryCount - currentCategoryCount >= (submissionInfo ? Math.max(Math.ceil(submissionInfo.votes / 2), 1) : 1) || isVIP) {
// Replace the category
db.prepare('run', "update sponsorTimes set category = ? where UUID = ?", [category, UUID]);
}