mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-05-11 18:36:17 +02:00
Save casual mode status in db
This commit is contained in:
parent
07435b9af1
commit
4abf57b0ce
3 changed files with 59 additions and 5 deletions
8
databases/_upgrade_sponsorTimes_41.sql
Normal file
8
databases/_upgrade_sponsorTimes_41.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
BEGIN TRANSACTION;
|
||||
|
||||
ALTER TABLE "titles" ADD "casualMode" INTEGER default 0;
|
||||
ALTER TABLE "thumbnails" ADD "casualMode" INTEGER default 0;
|
||||
|
||||
UPDATE "config" SET value = 41 WHERE key = 'version';
|
||||
|
||||
COMMIT;
|
|
@ -36,7 +36,7 @@ interface ExistingVote {
|
|||
}
|
||||
|
||||
export async function postBranding(req: Request, res: Response) {
|
||||
const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned } = req.body as BrandingSubmission;
|
||||
const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned, casualMode } = req.body as BrandingSubmission;
|
||||
const service = getService(req.body.service);
|
||||
|
||||
if (!videoID || !userID || userID.length < 30 || !service
|
||||
|
@ -100,8 +100,8 @@ export async function postBranding(req: Request, res: Response) {
|
|||
throw new Error("Title submission doesn't exist");
|
||||
}
|
||||
|
||||
await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]);
|
||||
await db.prepare("run", `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0]);
|
||||
|
||||
const verificationValue = await getVerificationValue(hashedUserID, isVip);
|
||||
await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, 0, ?, ?, ?);`,
|
||||
|
@ -142,8 +142,8 @@ export async function postBranding(req: Request, res: Response) {
|
|||
throw new Error("Thumbnail submission doesn't exist");
|
||||
}
|
||||
|
||||
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]);
|
||||
await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID", "casualMode") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID, casualMode ? 1 : 0]);
|
||||
|
||||
await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, ?)`,
|
||||
[UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]);
|
||||
|
|
|
@ -15,6 +15,7 @@ describe("postBranding", () => {
|
|||
const userID5 = `PostBrandingUser5${".".repeat(16)}`;
|
||||
const userID6 = `PostBrandingUser6${".".repeat(16)}`;
|
||||
const userID7 = `PostBrandingUser7${".".repeat(16)}`;
|
||||
const userID8 = `PostBrandingUser8${".".repeat(16)}`;
|
||||
const bannedUser = `BannedPostBrandingUser${".".repeat(16)}`;
|
||||
|
||||
|
||||
|
@ -119,6 +120,7 @@ describe("postBranding", () => {
|
|||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
assert.strictEqual(dbTitle.casualMode, 0);
|
||||
|
||||
assert.strictEqual(dbVotes.votes, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
|
@ -1133,6 +1135,50 @@ describe("postBranding", () => {
|
|||
assert.strictEqual(dbVotes3.verification, 0);
|
||||
});
|
||||
|
||||
it("Submit title and thumbnail with casual mode", async () => {
|
||||
const videoID = "postBrandCasual1";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
const thumbnail = {
|
||||
timestamp: 12.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
thumbnail,
|
||||
userID: userID5,
|
||||
service: Service.YouTube,
|
||||
videoID,
|
||||
casualMode: true
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbTitleVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
const dbThumbnailTimestamps = await queryThumbnailTimestampsByUUID(dbThumbnail.UUID);
|
||||
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
assert.strictEqual(dbTitle.casualMode, 1);
|
||||
|
||||
assert.strictEqual(dbTitleVotes.votes, 0);
|
||||
assert.strictEqual(dbTitleVotes.locked, 0);
|
||||
assert.strictEqual(dbTitleVotes.shadowHidden, 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
assert.strictEqual(dbThumbnail.casualMode, 1);
|
||||
|
||||
assert.strictEqual(dbThumbnailVotes.votes, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.locked, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Banned users should not be able to vote (custom title)", async () => {
|
||||
const videoID = "postBrandBannedCustomVote";
|
||||
const title = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue