mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 23:17:02 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into fix-eslint
This commit is contained in:
@@ -266,6 +266,34 @@ async function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promi
|
||||
}
|
||||
}
|
||||
|
||||
async function checkUserActiveWarning(userID: string): Promise<{ pass: boolean; errorMessage: string; }> {
|
||||
const MILLISECONDS_IN_HOUR = 3600000;
|
||||
const now = Date.now();
|
||||
const warnings = await db.prepare('all',
|
||||
`SELECT "reason"
|
||||
FROM warnings
|
||||
WHERE "userID" = ? AND "issueTime" > ? AND enabled = 1
|
||||
ORDER BY "issueTime" DESC
|
||||
LIMIT ?`,
|
||||
[
|
||||
userID,
|
||||
Math.floor(now - (config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR)),
|
||||
config.maxNumberOfActiveWarnings
|
||||
],
|
||||
) as {reason: string}[];
|
||||
|
||||
if (warnings?.length >= config.maxNumberOfActiveWarnings) {
|
||||
const defaultMessage = 'Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes that are not malicious, and we just want to clarify the rules. Could you please send a message in Discord or Matrix so we can further help you?';
|
||||
|
||||
return {
|
||||
pass: false,
|
||||
errorMessage: warnings[0]?.reason?.length > 0 ? warnings[0].reason : defaultMessage
|
||||
};
|
||||
}
|
||||
|
||||
return {pass: true, errorMessage: ''};
|
||||
}
|
||||
|
||||
function proxySubmission(req: Request) {
|
||||
fetch(config.proxySubmission + '/api/skipSegments?userID=' + req.query.userID + '&videoID=' + req.query.videoID, {
|
||||
method: 'POST',
|
||||
@@ -321,17 +349,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
//hash the userID
|
||||
userID = getHash(userID);
|
||||
|
||||
//hash the ip 5000 times so no one can get it from the database
|
||||
const hashedIP = getHash(getIP(req) + config.globalSalt);
|
||||
|
||||
const MILLISECONDS_IN_HOUR = 3600000;
|
||||
const now = Date.now();
|
||||
const warningsCount = (await db.prepare('get', `SELECT count(*) as count FROM warnings WHERE "userID" = ? AND "issueTime" > ? AND enabled = 1`,
|
||||
[userID, Math.floor(now - (config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR))],
|
||||
)).count;
|
||||
|
||||
if (warningsCount >= config.maxNumberOfActiveWarnings) {
|
||||
return res.status(403).send('Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes that are not malicious, and we just want to clarify the rules. Could you please send a message in Discord or Matrix so we can further help you?');
|
||||
const warningResult: {pass: boolean, errorMessage: string} = await checkUserActiveWarning(userID);
|
||||
if (!warningResult.pass) {
|
||||
return res.status(403).send(warningResult.errorMessage);
|
||||
}
|
||||
|
||||
let lockedCategoryList = (await db.prepare('all', 'SELECT category from "lockCategories" where "videoID" = ?', [videoID])).map((list: any) => list.category );
|
||||
@@ -341,9 +361,15 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
|
||||
const decreaseVotes = 0;
|
||||
|
||||
const previousSubmissions = await db.prepare('all', `SELECT "videoDuration", "UUID" FROM "sponsorTimes" WHERE "videoID" = ? AND "service" = ? AND "hidden" = 0
|
||||
AND "shadowHidden" = 0 AND "votes" >= 0 AND "videoDuration" != 0`, [videoID, service]) as
|
||||
{videoDuration: VideoDuration, UUID: SegmentUUID}[];
|
||||
const previousSubmissions = await db.prepare('all',
|
||||
`SELECT "videoDuration", "UUID"
|
||||
FROM "sponsorTimes"
|
||||
WHERE "videoID" = ? AND "service" = ? AND
|
||||
"hidden" = 0 AND "shadowHidden" = 0 AND
|
||||
"votes" >= 0 AND "videoDuration" != 0`,
|
||||
[videoID, service]
|
||||
) as {videoDuration: VideoDuration, UUID: SegmentUUID}[];
|
||||
|
||||
// If the video's duration is changed, then the video should be unlocked and old submissions should be hidden
|
||||
const videoDurationChanged = (videoDuration: number) => videoDuration != 0 && previousSubmissions.length > 0 && !previousSubmissions.some((e) => Math.abs(videoDuration - e.videoDuration) < 2);
|
||||
|
||||
@@ -436,6 +462,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
const UUIDs = [];
|
||||
const newSegments = [];
|
||||
|
||||
//hash the ip 5000 times so no one can get it from the database
|
||||
const hashedIP = getHash(getIP(req) + config.globalSalt);
|
||||
|
||||
try {
|
||||
//get current time
|
||||
const timeSubmitted = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user