diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 6c1b7d1..268c776 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -354,12 +354,14 @@ async function checkEachSegmentValid(userID: string, videoID: VideoID } // Reject segment if it's in the locked categories list - if (!isVIP && lockedCategoryList.indexOf(segments[i].category) !== -1) { + const lockIndex = lockedCategoryList.findIndex(c => segments[i].category === c.category); + if (!isVIP && lockIndex !== -1) { // TODO: Do something about the fradulent submission Logger.warn(`Caught a submission for a locked category. userID: '${userID}', videoID: '${videoID}', category: '${segments[i].category}', times: ${segments[i].segment}`); return { pass: false, 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\n\ + ${lockedCategoryList[lockIndex].reason?.length !== 0 ? `Lock reason: '${lockedCategoryList[lockIndex].reason}'` : ""}\n ${(segments[i].category === "sponsor" ? "Maybe 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\n" : "")}\ If you believe this is incorrect, please contact someone on discord.gg/SponsorBlock or matrix.to/#/+sponsor:ajay.app` @@ -421,7 +423,7 @@ async function checkByAutoModerator(videoID: any, userID: any, segments: Array list.category ); + let lockedCategoryList = await db.prepare("all", 'SELECT category, reason from "lockCategories" where "videoID" = ?', [videoID]); const previousSubmissions = await db.prepare("all", `SELECT "videoDuration", "UUID" diff --git a/test/cases/postSkipSegments.ts b/test/cases/postSkipSegments.ts index 7ab933d..11ffd34 100644 --- a/test/cases/postSkipSegments.ts +++ b/test/cases/postSkipSegments.ts @@ -217,7 +217,7 @@ describe("postSkipSegments", () => { }); it("Should be able to submit with a new duration, and hide old submissions and remove segment locks", async () => { - await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") + await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), "noDuration", "sponsor"]); try { @@ -238,10 +238,10 @@ describe("postSkipSegments", () => { }); assert.strictEqual(res.status, 200); const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, ["noDuration"]); - const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" + const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, ["noDuration"]); const videoRow = videoRows[0]; - const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" + const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, ["noDuration"]); assert.ok(!lockCategoriesRow); assert.strictEqual(videoRows.length, 1); @@ -789,4 +789,60 @@ describe("postSkipSegments", () => { }) .catch(err => done(err)); }); + + it("Should return 403 and custom reason for submiting in lockedCategory", async () => { + await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") + VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), "lockedVideo", "sponsor", "Custom Reason"]); + + try { + const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userID: "testtesttesttesttesttesttesttesttest", + videoID: "lockedVideo", + segments: [{ + segment: [1, 10], + category: "sponsor", + }], + }), + }); + + assert.strictEqual(res.status, 403); + assert.match(await res.text(), /Lock reason: /); + assert.match(await res.text(), /Custom Reason/); + } catch (e) { + return e; + } + }); + + it("Should return 403 for submiting in lockedCategory", async () => { + await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") + VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), "lockedVideo1", "intro", ""]); + + try { + const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + userID: "testtesttesttesttesttesttesttesttest", + videoID: "lockedVideo1", + segments: [{ + segment: [1, 10], + category: "intro", + }], + }), + }); + + assert.strictEqual(res.status, 403); + assert.doesNotMatch(await res.text(), /Lock reason: /); + assert.doesNotMatch(await res.text(), /Custom Reason/); + } catch (e) { + return e; + } + }).timeout(5000); });