From 8fef35dbbc1f025a7a8aeb9c8e89696daf3fabd3 Mon Sep 17 00:00:00 2001 From: Ajay Date: Sun, 2 Jan 2022 22:38:06 -0500 Subject: [PATCH] Allow submitting full sponsors and selfpromo --- src/config.ts | 4 ++-- src/routes/postSkipSegments.ts | 9 ++++++--- src/types/segments.model.ts | 3 ++- test/cases/postSkipSegments.ts | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/config.ts b/src/config.ts index c666a90..65b9b10 100644 --- a/src/config.ts +++ b/src/config.ts @@ -21,8 +21,8 @@ addDefaults(config, { webhooks: [], categoryList: ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "filler", "poi_highlight", "chapter"], categorySupport: { - sponsor: ["skip", "mute"], - selfpromo: ["skip", "mute"], + sponsor: ["skip", "mute", "full"], + selfpromo: ["skip", "mute", "full"], interaction: ["skip", "mute"], intro: ["skip", "mute"], outro: ["skip", "mute"], diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 6655236..88bc9af 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -383,8 +383,10 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID, if (isNaN(startTime) || isNaN(endTime) || startTime === Infinity || endTime === Infinity || startTime < 0 || startTime > endTime - || (getCategoryActionType(segments[i].category) === CategoryActionType.Skippable && startTime === endTime) - || (getCategoryActionType(segments[i].category) === CategoryActionType.POI && startTime !== endTime)) { + || (getCategoryActionType(segments[i].category) === CategoryActionType.Skippable + && segments[i].actionType !== ActionType.Full && startTime === endTime) + || (getCategoryActionType(segments[i].category) === CategoryActionType.POI && startTime !== endTime) + || (segments[i].actionType === ActionType.Full && (startTime !== 0 || endTime !== 0))) { //invalid request return { pass: false, errorMessage: "One of your segments times are invalid (too short, startTime before endTime, etc.)", errorCode: 400 }; } @@ -394,7 +396,8 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID, return { pass: false, errorMessage: `POI cannot be that early`, errorCode: 400 }; } - if (!isVIP && segments[i].category === "sponsor" && Math.abs(startTime - endTime) < 1) { + if (!isVIP && segments[i].category === "sponsor" + && segments[i].actionType !== ActionType.Full && Math.abs(startTime - endTime) < 1) { // Too short return { pass: false, errorMessage: "Sponsors must be longer than 1 second long", errorCode: 400 }; } diff --git a/src/types/segments.model.ts b/src/types/segments.model.ts index ba613c4..4bb28d7 100644 --- a/src/types/segments.model.ts +++ b/src/types/segments.model.ts @@ -13,7 +13,8 @@ export type HashedIP = IPAddress & HashedValue; export enum ActionType { Skip = "skip", Mute = "mute", - Chapter = "chapter" + Chapter = "chapter", + Full = "full" } // Uncomment as needed diff --git a/test/cases/postSkipSegments.ts b/test/cases/postSkipSegments.ts index 8bad132..bf89dd0 100644 --- a/test/cases/postSkipSegments.ts +++ b/test/cases/postSkipSegments.ts @@ -1064,6 +1064,40 @@ describe("postSkipSegments", () => { .catch(err => done(err)); }); + it("Should allow submitting full video sponsor", (done) => { + const videoID = "qqwerth"; + postSkipSegmentParam({ + videoID, + startTime: 0, + endTime: 0, + category: "sponsor", + actionType: "full", + userID: submitUserTwo + }) + .then(res => { + assert.strictEqual(res.status, 200); + done(); + }) + .catch(err => done(err)); + }); + + it("Should not allow submitting full video sponsor not at zero seconds", (done) => { + const videoID = "qqwerth"; + postSkipSegmentParam({ + videoID, + startTime: 0, + endTime: 1, + category: "sponsor", + actionType: "full", + userID: submitUserTwo + }) + .then(res => { + assert.strictEqual(res.status, 400); + done(); + }) + .catch(err => done(err)); + }); + it("Should not be able to submit with colons in timestamps", (done) => { const videoID = "colon-1"; postSkipSegmentJSON({