mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 00:17:01 +03:00
Replace VIP starting with 1000 votes with locked submissions
This commit is contained in:
@@ -50,7 +50,7 @@ function getSegmentsByVideoID(req: Request, videoID: string, categories: Categor
|
||||
const segmentsByCategory: SBRecord<Category, DBSegment[]> = db
|
||||
.prepare(
|
||||
'all',
|
||||
`SELECT startTime, endTime, votes, UUID, category, shadowHidden FROM sponsorTimes WHERE videoID = ? AND category IN (${Array(categories.length).fill('?').join()}) ORDER BY startTime`,
|
||||
`SELECT startTime, endTime, votes, locked, UUID, category, shadowHidden FROM sponsorTimes WHERE videoID = ? AND category IN (${Array(categories.length).fill('?').join()}) ORDER BY startTime`,
|
||||
[videoID, categories]
|
||||
).reduce((acc: SBRecord<Category, DBSegment[]>, segment: DBSegment) => {
|
||||
acc[segment.category] = acc[segment.category] || [];
|
||||
@@ -82,7 +82,7 @@ function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, categ
|
||||
const segmentPerVideoID: SegmentWithHashPerVideoID = db
|
||||
.prepare(
|
||||
'all',
|
||||
`SELECT videoID, startTime, endTime, votes, UUID, category, shadowHidden, hashedVideoID FROM sponsorTimes WHERE hashedVideoID LIKE ? AND category IN (${Array(categories.length).fill('?').join()}) ORDER BY startTime`,
|
||||
`SELECT videoID, startTime, endTime, votes, locked, UUID, category, shadowHidden, hashedVideoID FROM sponsorTimes WHERE hashedVideoID LIKE ? AND category IN (${Array(categories.length).fill('?').join()}) ORDER BY startTime`,
|
||||
[hashedVideoIDPrefix + '%', categories]
|
||||
).reduce((acc: SegmentWithHashPerVideoID, segment: DBSegment) => {
|
||||
acc[segment.videoID] = acc[segment.videoID] || {
|
||||
@@ -176,7 +176,7 @@ function chooseSegments(segments: DBSegment[]): DBSegment[] {
|
||||
let cursor = -1; //-1 to make sure that, even if the 1st segment starts at 0, a new group is created
|
||||
segments.forEach(segment => {
|
||||
if (segment.startTime > cursor) {
|
||||
currentGroup = {segments: [], votes: 0};
|
||||
currentGroup = {segments: [], votes: 0, locked: false};
|
||||
overlappingSegmentsGroups.push(currentGroup);
|
||||
}
|
||||
|
||||
@@ -186,9 +186,19 @@ function chooseSegments(segments: DBSegment[]): DBSegment[] {
|
||||
currentGroup.votes += segment.votes;
|
||||
}
|
||||
|
||||
if (segment.locked) {
|
||||
currentGroup.locked = true;
|
||||
}
|
||||
|
||||
cursor = Math.max(cursor, segment.endTime);
|
||||
});
|
||||
|
||||
overlappingSegmentsGroups.forEach((group) => {
|
||||
if (group.locked) {
|
||||
group.segments = group.segments.filter((segment) => segment.locked);
|
||||
}
|
||||
});
|
||||
|
||||
//if there are too many groups, find the best 8
|
||||
return getWeightedRandomChoice(overlappingSegmentsGroups, 32).map(
|
||||
//randomly choose 1 good segment per group and return them
|
||||
|
||||
@@ -433,10 +433,6 @@ export async function postSkipSegments(req: Request, res: Response) {
|
||||
}
|
||||
|
||||
let startingVotes = 0 + decreaseVotes;
|
||||
if (isVIP) {
|
||||
//this user is a vip, start them at a higher approval rating
|
||||
startingVotes = 10000;
|
||||
}
|
||||
|
||||
if (config.youtubeAPIKey !== null) {
|
||||
let {err, data} = await new Promise((resolve) => {
|
||||
@@ -489,11 +485,12 @@ export async function postSkipSegments(req: Request, res: Response) {
|
||||
//also better for duplication checking
|
||||
const UUID = getSubmissionUUID(videoID, segmentInfo.category, userID, segmentInfo.segment[0], segmentInfo.segment[1]);
|
||||
|
||||
const startingLocked = isVIP ? 1 : 0;
|
||||
try {
|
||||
db.prepare('run', "INSERT INTO sponsorTimes " +
|
||||
"(videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID)" +
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
||||
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, UUID, userID, timeSubmitted, 0, segmentInfo.category, shadowBanned, getHash(videoID, 1),
|
||||
"(videoID, startTime, endTime, votes, locked, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID)" +
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
||||
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0, segmentInfo.category, shadowBanned, getHash(videoID, 1),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface DBSegment {
|
||||
endTime: number;
|
||||
UUID: SegmentUUID;
|
||||
votes: number;
|
||||
locked: boolean;
|
||||
shadowHidden: Visibility;
|
||||
videoID: VideoID;
|
||||
hashedVideoID: VideoIDHash;
|
||||
@@ -33,6 +34,7 @@ export interface DBSegment {
|
||||
export interface OverlappingSegmentGroup {
|
||||
segments: DBSegment[],
|
||||
votes: number;
|
||||
locked: boolean; // Contains a locked segment
|
||||
}
|
||||
|
||||
export interface VotableObject {
|
||||
|
||||
Reference in New Issue
Block a user