mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 16:07:03 +03:00
Merge branch 'master' of github.com:mchangrh/SponsorBlockServer into poi-restriction
This commit is contained in:
@@ -324,6 +324,15 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array<any>): Ch
|
||||
if (!Array.isArray(segments) || segments.length < 1) {
|
||||
invalidFields.push("segments");
|
||||
}
|
||||
// validate start and end times (no : marks)
|
||||
for (const segmentPair of segments) {
|
||||
const startTime = segmentPair.segment[0];
|
||||
const endTime = segmentPair.segment[1];
|
||||
if ((typeof startTime === "string" && startTime.includes(":")) ||
|
||||
(typeof endTime === "string" && endTime.includes(":"))) {
|
||||
invalidFields.push("segment time");
|
||||
}
|
||||
}
|
||||
|
||||
if (invalidFields.length !== 0) {
|
||||
// invalid request
|
||||
@@ -362,7 +371,7 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID
|
||||
errorCode: 403,
|
||||
errorMessage:
|
||||
`New submissions are not allowed for the following category: ` +
|
||||
`'${segments[i].category}'. A moderator has decided that no new segments are needed and that all current segments of this category are timed perfectly.\n` +
|
||||
`'${segments[i].category}'. A moderator has decided that no new segments are needed on this video and that all current segments of this category are timed perfectly.\n` +
|
||||
`${lockedCategoryList[lockIndex].reason?.length !== 0 ? `\nLock reason: '${lockedCategoryList[lockIndex].reason}'` : ""}\n` +
|
||||
`${(segments[i].category === "sponsor" ? "\nMaybe the segment you are submitting is a different category that you have not enabled and is not a sponsor. " +
|
||||
"Categories that aren't sponsor, such as self-promotion can be enabled in the options.\n" : "")}` +
|
||||
|
||||
@@ -48,16 +48,7 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
|
||||
|
||||
//find all previous submissions and hide them
|
||||
if (unHideOldSubmissions) {
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
|
||||
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
|
||||
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
|
||||
|
||||
// clear cache for all old videos
|
||||
(await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service", "votes", "views" FROM "sponsorTimes" WHERE "userID" = ?`, [userID]))
|
||||
.forEach((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => {
|
||||
QueryCacher.clearVideoCache(videoInfo);
|
||||
}
|
||||
);
|
||||
await unHideSubmissions(categories, userID);
|
||||
}
|
||||
} else if (!enabled && row.userCount > 0) {
|
||||
//remove them from the shadow ban list
|
||||
@@ -84,6 +75,16 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
|
||||
return db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 0 WHERE "UUID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]);
|
||||
}));
|
||||
}
|
||||
// already shadowbanned
|
||||
} else if (enabled && row.userCount > 0) {
|
||||
// apply unHideOldSubmissions if applicable
|
||||
if (unHideOldSubmissions) {
|
||||
await unHideSubmissions(categories, userID);
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
// otherwise ban already exists, send 409
|
||||
return res.sendStatus(409);
|
||||
}
|
||||
} else if (hashedIP) {
|
||||
//check to see if this user is already shadowbanned
|
||||
@@ -115,3 +116,16 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
|
||||
}
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
async function unHideSubmissions(categories: string[], userID: UserID) {
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
|
||||
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
|
||||
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
|
||||
|
||||
// clear cache for all old videos
|
||||
(await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service", "votes", "views" FROM "sponsorTimes" WHERE "userID" = ?`, [userID]))
|
||||
.forEach((videoInfo: { category: Category; videoID: VideoID; hashedVideoID: VideoIDHash; service: Service; userID: UserID; }) => {
|
||||
QueryCacher.clearVideoCache(videoInfo);
|
||||
}
|
||||
); //eslint-disable-line
|
||||
}
|
||||
Reference in New Issue
Block a user