mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 07:57:05 +03:00
add test for downvote videoDuration change
This commit is contained in:
@@ -92,25 +92,24 @@ async function checkVideoDuration(UUID: SegmentUUID) {
|
|||||||
}
|
}
|
||||||
const apiVideoDuration = apiVideoInfo?.data?.lengthSeconds as VideoDuration;
|
const apiVideoDuration = apiVideoInfo?.data?.lengthSeconds as VideoDuration;
|
||||||
// if no videoDuration return early
|
// if no videoDuration return early
|
||||||
if (!apiVideoDuration && apiVideoDuration != 0) return;
|
if (isNaN(apiVideoDuration)) return;
|
||||||
// fetch latest submission
|
// fetch latest submission
|
||||||
const latestSubmission = await db.prepare("get", `SELECT "videoDuration, UUID, submissionTime
|
const latestSubmission = await db.prepare("get", `SELECT "videoDuration", "UUID", "timeSubmitted"
|
||||||
FROM "sponsorTimes
|
FROM "sponsorTimes"
|
||||||
WHERE "videoID" = ? AND "service" = ? AND
|
WHERE "videoID" = ? AND "service" = ? AND
|
||||||
"hidden" = 0 AND "shadowHidden" = 0 AND
|
"hidden" = 0 AND "shadowHidden" = 0 AND
|
||||||
"actionType" != 'full' AND
|
"actionType" != 'full' AND
|
||||||
"votes" > -2 AND "videoDuration" != 0
|
"votes" > -2 AND "videoDuration" != 0
|
||||||
ORDER BY "submissionTime" DESC
|
ORDER BY "timeSubmitted" DESC LIMIT 1`,
|
||||||
TOP 1`,
|
[videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, timeSubmitted: number};
|
||||||
[videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, submissionTime: number};
|
|
||||||
|
|
||||||
if (videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) {
|
if (videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) {
|
||||||
Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`);
|
Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`);
|
||||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1
|
await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1
|
||||||
WHERE videoID = ? AND service = ? AND submissionTime < ?
|
WHERE videoID = ? AND service = ? AND timeSubmitted <= ?
|
||||||
hidden" = 0 AND "shadowHidden" = 0 AND
|
AND "hidden" = 0 AND "shadowHidden" = 0 AND
|
||||||
"actionType" != 'full' AND "votes" > -2`,
|
"actionType" != 'full' AND "votes" > -2`,
|
||||||
[videoID, service, latestSubmission.submissionTime]);
|
[videoID, service, latestSubmission.timeSubmitted]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +420,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
|
|||||||
|
|
||||||
// no restrictions on checkDuration
|
// no restrictions on checkDuration
|
||||||
// check duration of all submissions on this video
|
// check duration of all submissions on this video
|
||||||
if (type < 0) {
|
if (type <= 0) {
|
||||||
checkVideoDuration(UUID);
|
checkVideoDuration(UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,11 +486,8 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
|
|||||||
&& !finalResponse.blockVote
|
&& !finalResponse.blockVote
|
||||||
&& finalResponse.finalStatus === 200;
|
&& finalResponse.finalStatus === 200;
|
||||||
|
|
||||||
const tempVIPAbleToVote = isTempVIP
|
|
||||||
&& (await db.prepare("get", `SELECT COUNT(*) FROM "sponsorTimes" WHERE "userID" = ?`, [nonAnonUserID])) >= 5
|
|
||||||
&& userAbleToVote;
|
|
||||||
|
|
||||||
const ableToVote = isVIP || userAbleToVote || tempVIPAbleToVote;
|
const ableToVote = isVIP || isTempVIP || userAbleToVote;
|
||||||
|
|
||||||
if (ableToVote) {
|
if (ableToVote) {
|
||||||
//update the votes table
|
//update the votes table
|
||||||
@@ -504,16 +500,20 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
|
|||||||
// update the vote count on this sponsorTime
|
// update the vote count on this sponsorTime
|
||||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]);
|
await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]);
|
||||||
|
|
||||||
// additional procesing for VIP
|
// tempVIP can bring back hidden segments
|
||||||
|
if (isTempVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
|
||||||
|
await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0 WHERE "UUID" = ?`, [UUID]);
|
||||||
|
}
|
||||||
|
// additional processing for VIP
|
||||||
// on VIP upvote
|
// on VIP upvote
|
||||||
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
|
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
|
||||||
// Update video duration in case that caused it to be hidden
|
// Update video duration in case that caused it to be hidden
|
||||||
await updateSegmentVideoDuration(UUID);
|
await updateSegmentVideoDuration(UUID);
|
||||||
// unhide & unlock
|
// unhide & unlock
|
||||||
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
|
await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
|
||||||
// on VIP downvote/ undovote, also unlock submission
|
// on VIP downvote/ undovote, also unlock submission
|
||||||
} else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) {
|
} else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) {
|
||||||
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 0 WHERE "UUID" = ?', [UUID]);
|
await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0 WHERE "UUID" = ?', [UUID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryCacher.clearSegmentCache(segmentInfo);
|
QueryCacher.clearSegmentCache(segmentInfo);
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ describe("tempVIP test", function() {
|
|||||||
await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]);
|
||||||
|
|
||||||
|
|
||||||
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP1]);
|
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP1]);
|
||||||
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP2]);
|
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP2]);
|
||||||
// clear redis if running consecutive tests
|
// clear redis if running consecutive tests
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ describe("voteOnSponsorTime", () => {
|
|||||||
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", "skip", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", "skip", 0, 0]);
|
||||||
await db.prepare("run", insertSponsorTimeQuery, ["full-video", 1, 10, 0, 0, "full-video-uuid-1", "testman", 0, 0, "sponsor", "full", 0, 0]);
|
await db.prepare("run", insertSponsorTimeQuery, ["full-video", 1, 10, 0, 0, "full-video-uuid-1", "testman", 0, 0, "sponsor", "full", 0, 0]);
|
||||||
|
// videoDuration change
|
||||||
|
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 10, 0, 0, "duration-changed-uuid-1", "testman", 1, 0, "sponsor", "skip", 0, 0]);
|
||||||
|
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 11, 0, 0, "duration-changed-uuid-2", "testman", 10, 0, "sponsor", "skip", 0, 0]);
|
||||||
|
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 12, 0, 0, "duration-changed-uuid-3", "testman", 20, 0, "sponsor", "skip", 0, 0]);
|
||||||
|
// add videoDuration to duration-changed-uuid-2
|
||||||
|
await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = 150 WHERE "UUID" = 'duration-changed-uuid-2'`);
|
||||||
|
|
||||||
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
|
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
|
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
|
||||||
@@ -585,4 +591,18 @@ describe("voteOnSponsorTime", () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should hide changed submission on any downvote", (done) => {
|
||||||
|
const UUID = "duration-changed-uuid-3";
|
||||||
|
const videoID = "duration-changed";
|
||||||
|
postVote(randomID2, UUID, 0)
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const hiddenSegments = await db.prepare("all", `SELECT "UUID" FROM "sponsorTimes" WHERE "videoID" = ? AND "hidden" = 1`, [videoID]);
|
||||||
|
assert.strictEqual(hiddenSegments.length, 2);
|
||||||
|
assert.strictEqual(hiddenSegments[0].UUID, "duration-changed-uuid-1");
|
||||||
|
assert.strictEqual(hiddenSegments[1].UUID, "duration-changed-uuid-2");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,6 +56,13 @@ export class YouTubeApiMock {
|
|||||||
authorId: "ChannelID"
|
authorId: "ChannelID"
|
||||||
} as APIVideoData
|
} as APIVideoData
|
||||||
};
|
};
|
||||||
|
} else if (obj.id === "duration-changed") {
|
||||||
|
return {
|
||||||
|
err: null,
|
||||||
|
data: {
|
||||||
|
lengthSeconds: 100,
|
||||||
|
} as APIVideoData
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
err: null,
|
err: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user