mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 14:37:17 +03:00
Add verification where new users start with lower votes
This commit is contained in:
@@ -12,12 +12,14 @@ describe("getBranding", () => {
|
||||
const videoID2ShadowHide = "videoID3";
|
||||
const videoIDEmpty = "videoID4";
|
||||
const videoIDRandomTime = "videoID5";
|
||||
const videoIDUnverified = "videoID6";
|
||||
|
||||
const videoID1Hash = getHash(videoID1, 1).slice(0, 4);
|
||||
const videoID2LockedHash = getHash(videoID2Locked, 1).slice(0, 4);
|
||||
const videoID2ShadowHideHash = getHash(videoID2ShadowHide, 1).slice(0, 4);
|
||||
const videoIDEmptyHash = "aaaa";
|
||||
const videoIDRandomTimeHash = getHash(videoIDRandomTime, 1).slice(0, 4);
|
||||
const videoIDUnverifiedHash = getHash(videoIDUnverified, 1).slice(0, 4);
|
||||
|
||||
const endpoint = "/api/branding";
|
||||
const getBranding = (params: Record<string, any>) => client({
|
||||
@@ -34,7 +36,7 @@ describe("getBranding", () => {
|
||||
|
||||
before(async () => {
|
||||
const titleQuery = `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`;
|
||||
const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?)`;
|
||||
const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`;
|
||||
const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`;
|
||||
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`;
|
||||
@@ -49,9 +51,9 @@ describe("getBranding", () => {
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID1", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID2", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID3", 1, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID1", 3, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID2", 2, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID3", 1, 0, 0, 0]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID1T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID3T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0]),
|
||||
@@ -69,9 +71,9 @@ describe("getBranding", () => {
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID11", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID21", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID31", 1, 1, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID11", 3, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID21", 2, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID31", 1, 1, 0, 0]),
|
||||
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID11T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID31T", 3]),
|
||||
@@ -90,9 +92,9 @@ describe("getBranding", () => {
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID12", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID22", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID12", 3, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID22", 2, 0, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1, 0]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID12T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID32T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0]),
|
||||
@@ -103,6 +105,26 @@ describe("getBranding", () => {
|
||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", query, [videoIDRandomTime, 1, 11, 1, 0, "uuidbranding1", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash]);
|
||||
await db.prepare("run", query, [videoIDRandomTime, 20, 33, 2, 0, "uuidbranding2", "testman", 0, 50, "intro", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleQuery, [videoIDUnverified, "title1", 0, "userID1", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-1"]),
|
||||
db.prepare("run", titleQuery, [videoIDUnverified, "title2", 0, "userID2", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-2"]),
|
||||
db.prepare("run", titleQuery, [videoIDUnverified, "title3", 1, "userID3", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-3"]),
|
||||
db.prepare("run", thumbnailQuery, [videoIDUnverified, 0, "userID1", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-1T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoIDUnverified, 1, "userID2", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-2T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoIDUnverified, 0, "userID3", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-3T"]),
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID-uv-1", 3, 0, 0, -1]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID-uv-2", 2, 0, 0, -1]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID-uv-3", 0, 0, 0, -1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-1T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-3T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-2T", 2, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-3T", 1, 0, 0])
|
||||
]);
|
||||
});
|
||||
|
||||
it("should get top titles and thumbnails", async () => {
|
||||
@@ -243,6 +265,48 @@ describe("getBranding", () => {
|
||||
assert.strictEqual(result1.data.videoDuration, 100);
|
||||
});
|
||||
|
||||
it("should get top titles and thumbnails that are unverified", async () => {
|
||||
await checkVideo(videoIDUnverified, videoIDUnverifiedHash, {
|
||||
titles: [{
|
||||
title: "title1",
|
||||
original: false,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-1" as BrandingUUID
|
||||
}, {
|
||||
title: "title2",
|
||||
original: false,
|
||||
votes: 1,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-2" as BrandingUUID
|
||||
}, {
|
||||
title: "title3",
|
||||
original: true,
|
||||
votes: -1,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-3" as BrandingUUID
|
||||
}],
|
||||
thumbnails: [{
|
||||
timestamp: 1,
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-1T" as BrandingUUID
|
||||
}, {
|
||||
original: true,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-2T" as BrandingUUID
|
||||
}, {
|
||||
timestamp: 3,
|
||||
original: false,
|
||||
votes: 1,
|
||||
locked: false,
|
||||
UUID: "UUID-uv-3T" as BrandingUUID
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
async function checkVideo(videoID: string, videoIDHash: string, expected: {
|
||||
titles: TitleResult[],
|
||||
thumbnails: ThumbnailResult[]
|
||||
|
||||
@@ -12,7 +12,11 @@ describe("postBranding", () => {
|
||||
const userID2 = `PostBrandingUser2${".".repeat(16)}`;
|
||||
const userID3 = `PostBrandingUser3${".".repeat(16)}`;
|
||||
const userID4 = `PostBrandingUser4${".".repeat(16)}`;
|
||||
const userID5 = `PostBrandingUser4${".".repeat(16)}`;
|
||||
const userID5 = `PostBrandingUser5${".".repeat(16)}`;
|
||||
const userID6 = `PostBrandingUser6${".".repeat(16)}`;
|
||||
const userID7 = `PostBrandingUser7${".".repeat(16)}`;
|
||||
const userID8 = `PostBrandingUser8${".".repeat(16)}`;
|
||||
|
||||
|
||||
const endpoint = "/api/branding";
|
||||
const postBranding = (data: Record<string, any>) => client({
|
||||
@@ -35,9 +39,9 @@ describe("postBranding", () => {
|
||||
const insertTitleQuery = 'INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertTitleQuery, ["postBrandLocked1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]);
|
||||
await db.prepare("run", insertTitleQuery, ["postBrandLocked2", "Some title", 1, getHash(userID2), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]);
|
||||
const insertTitleVotesQuery = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);';
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked1", 0, 1, 0]);
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked2", 0, 1, 0]);
|
||||
const insertTitleVotesQuery = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?);';
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked1", 0, 1, 0, 0]);
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked2", 0, 1, 0, 0]);
|
||||
|
||||
const insertThumbnailQuery = 'INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertThumbnailQuery, ["postBrandLocked1", 0, getHash(userID3), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]);
|
||||
@@ -45,6 +49,18 @@ describe("postBranding", () => {
|
||||
const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);';
|
||||
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0]);
|
||||
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0]);
|
||||
|
||||
// Verified through title submissions
|
||||
await db.prepare("run", insertTitleQuery, ["postBrandVerified1", "Some title", 0, getHash(userID7), Service.YouTube, getHash("postBrandVerified1"), Date.now(), "postBrandVerified1"]);
|
||||
await db.prepare("run", insertTitleQuery, ["postBrandVerified2", "Some title", 1, getHash(userID7), Service.YouTube, getHash("postBrandVerified2"), Date.now(), "postBrandVerified2"]);
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified1", 5, 0, 0, -1]);
|
||||
await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified2", -1, 0, 0, -1]);
|
||||
|
||||
// Verified through SponsorBlock submissions
|
||||
const insertSegment = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSegment, ["postBrandVerified3", 1, 11, 1, 0, "postBrandVerified3", getHash(userID8), 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, ""]);
|
||||
await db.prepare("run", insertSegment, ["postBrandVerified3", 11, 21, 1, 0, "postBrandVerified32", getHash(userID8), 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, ""]);
|
||||
await db.prepare("run", insertSegment, ["postBrandVerified3", 21, 31, 1, 0, "postBrandVerified33", getHash(userID8), 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, ""]);
|
||||
});
|
||||
|
||||
it("Submit only title", async () => {
|
||||
@@ -431,4 +447,76 @@ describe("postBranding", () => {
|
||||
assert.strictEqual(oldDBVotes.locked, 0);
|
||||
assert.strictEqual(oldDBVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit from unverified user", async () => {
|
||||
const videoID = "postBrandUnverified";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID6,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.verification, -1);
|
||||
});
|
||||
|
||||
it("Submit from verified user from title submissions", async () => {
|
||||
const videoID = "postBrandVerified";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID7,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.verification, 0);
|
||||
});
|
||||
|
||||
it("Submit from verified user from SponsorBlock submissions", async () => {
|
||||
const videoID = "postBrandVerified2-2";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID8,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.verification, 0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user