mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 21:47:02 +03:00
Limit mute action type to specific categories
This commit is contained in:
@@ -20,6 +20,16 @@ addDefaults(config, {
|
|||||||
readOnly: false,
|
readOnly: false,
|
||||||
webhooks: [],
|
webhooks: [],
|
||||||
categoryList: ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight"],
|
categoryList: ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "poi_highlight"],
|
||||||
|
categorySupport: {
|
||||||
|
sponsor: ["skip", "mute"],
|
||||||
|
selfpromo: ["skip", "mute"],
|
||||||
|
interaction: ["skip", "mute"],
|
||||||
|
intro: ["skip"],
|
||||||
|
outro: ["skip"],
|
||||||
|
preview: ["skip"],
|
||||||
|
music_offtopic: ["skip"],
|
||||||
|
poi_highlight: ["skip"],
|
||||||
|
},
|
||||||
maxNumberOfActiveWarnings: 1,
|
maxNumberOfActiveWarnings: 1,
|
||||||
hoursAfterWarningExpires: 24,
|
hoursAfterWarningExpires: 24,
|
||||||
adminUserID: "",
|
adminUserID: "",
|
||||||
|
|||||||
@@ -348,8 +348,8 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array<any>): Ch
|
|||||||
return CHECK_PASS;
|
return CHECK_PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkEachSegmentValid(userID: string, videoID: VideoID
|
async function checkEachSegmentValid(userID: string, videoID: VideoID,
|
||||||
, segments: Array<any>, service: string, isVIP: boolean, lockedCategoryList: Array<any>): Promise<CheckResult> {
|
segments: Array<any>, service: string, isVIP: boolean, lockedCategoryList: Array<any>): Promise<CheckResult> {
|
||||||
|
|
||||||
for (let i = 0; i < segments.length; i++) {
|
for (let i = 0; i < segments.length; i++) {
|
||||||
if (segments[i] === undefined || segments[i].segment === undefined || segments[i].category === undefined) {
|
if (segments[i] === undefined || segments[i].segment === undefined || segments[i].category === undefined) {
|
||||||
@@ -379,6 +379,10 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!config.categorySupport[segments[i].category]?.includes(segments[i].actionType)) {
|
||||||
|
return { pass: false, errorMessage: "ActionType is not supported with this category.", errorCode: 400 };
|
||||||
|
}
|
||||||
|
|
||||||
const startTime = parseFloat(segments[i].segment[0]);
|
const startTime = parseFloat(segments[i].segment[0]);
|
||||||
const endTime = parseFloat(segments[i].segment[1]);
|
const endTime = parseFloat(segments[i].segment[1]);
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,31 @@ describe("postSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should not be able to submit an intro with mute action type (JSON method)", (done: Done) => {
|
||||||
|
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
userID: "testtesttesttesttesttesttesttesttest",
|
||||||
|
videoID: "dQw4w9WgXpQ",
|
||||||
|
segments: [{
|
||||||
|
segment: [0, 10],
|
||||||
|
category: "intro",
|
||||||
|
actionType: "mute"
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 400);
|
||||||
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXpQ"]);
|
||||||
|
assert.strictEqual(row, undefined);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
|
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
|
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in New Issue
Block a user