mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-31 06:40:56 +03:00
Fix no segments votes being allowed
This commit is contained in:
@@ -175,7 +175,9 @@ async function categoryVote(UUID: string, userID: string, isVIP: boolean, isOwnS
|
|||||||
const timeSubmitted = Date.now();
|
const timeSubmitted = Date.now();
|
||||||
|
|
||||||
const voteAmount = isVIP ? 500 : 1;
|
const voteAmount = isVIP ? 500 : 1;
|
||||||
|
const ableToVote = isVIP || finalResponse.finalStatus === 200 || true;
|
||||||
|
|
||||||
|
if (ableToVote) {
|
||||||
// Add the vote
|
// Add the vote
|
||||||
if ((await db.prepare('get', `select count(*) as count from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category])).count > 0) {
|
if ((await db.prepare('get', `select count(*) as count from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category])).count > 0) {
|
||||||
// Update the already existing db entry
|
// Update the already existing db entry
|
||||||
@@ -221,6 +223,7 @@ async function categoryVote(UUID: string, userID: string, isVIP: boolean, isOwnS
|
|||||||
// Replace the category
|
// Replace the category
|
||||||
await db.prepare('run', `update "sponsorTimes" set "category" = ? where "UUID" = ?`, [category, UUID]);
|
await db.prepare('run', `update "sponsorTimes" set "category" = ? where "UUID" = ?`, [category, UUID]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.sendStatus(finalResponse.finalStatus);
|
res.sendStatus(finalResponse.finalStatus);
|
||||||
}
|
}
|
||||||
@@ -371,7 +374,8 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
|
|||||||
const ableToVote = isVIP
|
const ableToVote = isVIP
|
||||||
|| ((await db.prepare("get", `SELECT "userID" FROM "sponsorTimes" WHERE "userID" = ?`, [nonAnonUserID])) !== undefined
|
|| ((await db.prepare("get", `SELECT "userID" FROM "sponsorTimes" WHERE "userID" = ?`, [nonAnonUserID])) !== undefined
|
||||||
&& (await privateDB.prepare("get", `SELECT "userID" FROM "shadowBannedUsers" WHERE "userID" = ?`, [nonAnonUserID])) === undefined
|
&& (await privateDB.prepare("get", `SELECT "userID" FROM "shadowBannedUsers" WHERE "userID" = ?`, [nonAnonUserID])) === undefined
|
||||||
&& (await privateDB.prepare("get", `SELECT "UUID" FROM "votes" WHERE "UUID" = ? AND "hashedIP" = ? AND "userID" != ?`, [UUID, hashedIP, userID])) === undefined);
|
&& (await privateDB.prepare("get", `SELECT "UUID" FROM "votes" WHERE "UUID" = ? AND "hashedIP" = ? AND "userID" != ?`, [UUID, hashedIP, userID])) === undefined)
|
||||||
|
&& finalResponse.finalStatus === 200;
|
||||||
|
|
||||||
if (ableToVote) {
|
if (ableToVote) {
|
||||||
//update the votes table
|
//update the votes table
|
||||||
|
|||||||
@@ -410,12 +410,13 @@ describe('voteOnSponsorTime', () => {
|
|||||||
|
|
||||||
it('Non-VIP should not be able to downvote on a segment with no-segments category', (done: Done) => {
|
it('Non-VIP should not be able to downvote on a segment with no-segments category', (done: Done) => {
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=0")
|
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=0")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (res.status === 403) {
|
let row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||||
|
if (res.status === 403 && row.votes === 2) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.status + " instead of 403");
|
done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
@@ -423,12 +424,13 @@ describe('voteOnSponsorTime', () => {
|
|||||||
|
|
||||||
it('Non-VIP should be able to upvote on a segment with no-segments category', (done: Done) => {
|
it('Non-VIP should be able to upvote on a segment with no-segments category', (done: Done) => {
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1")
|
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=1")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (res.status === 200) {
|
let row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||||
|
if (res.status === 200 && row.votes === 3) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.status + " instead of 200");
|
done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
@@ -436,12 +438,13 @@ describe('voteOnSponsorTime', () => {
|
|||||||
|
|
||||||
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
|
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro")
|
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&category=outro")
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (res.status === 403) {
|
let row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||||
|
if (res.status === 403 && row.category === "sponsor") {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
done("Status code was " + res.status + " instead of 403");
|
done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
|
|||||||
Reference in New Issue
Block a user