mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Limit mute action type to specific categories
This commit is contained in:
parent
6f29b807c5
commit
1823a91d54
3 changed files with 41 additions and 2 deletions
|
@ -20,6 +20,16 @@ addDefaults(config, {
|
|||
readOnly: false,
|
||||
webhooks: [],
|
||||
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,
|
||||
hoursAfterWarningExpires: 24,
|
||||
adminUserID: "",
|
||||
|
|
|
@ -348,8 +348,8 @@ function checkInvalidFields(videoID: any, userID: any, segments: Array<any>): Ch
|
|||
return CHECK_PASS;
|
||||
}
|
||||
|
||||
async function checkEachSegmentValid(userID: string, videoID: VideoID
|
||||
, segments: Array<any>, service: string, isVIP: boolean, lockedCategoryList: Array<any>): Promise<CheckResult> {
|
||||
async function checkEachSegmentValid(userID: string, videoID: VideoID,
|
||||
segments: Array<any>, service: string, isVIP: boolean, lockedCategoryList: Array<any>): Promise<CheckResult> {
|
||||
|
||||
for (let i = 0; i < segments.length; i++) {
|
||||
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 endTime = parseFloat(segments[i].segment[1]);
|
||||
|
||||
|
|
|
@ -137,6 +137,31 @@ describe("postSkipSegments", () => {
|
|||
.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) => {
|
||||
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
|
||||
method: "POST",
|
||||
|
|
Loading…
Reference in a new issue