mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Merge pull request #229 from MRuy/fix/rename-no-segments
Rename noSegments to lockCategories
This commit is contained in:
commit
129cf8d02d
13 changed files with 95 additions and 85 deletions
|
@ -56,7 +56,7 @@
|
|||
"name": "categoryVotes"
|
||||
},
|
||||
{
|
||||
"name": "noSegments"
|
||||
"name": "lockCategories"
|
||||
},
|
||||
{
|
||||
"name": "warnings",
|
||||
|
|
8
databases/_upgrade_sponsorTimes_11.sql
Normal file
8
databases/_upgrade_sponsorTimes_11.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
BEGIN TRANSACTION;
|
||||
|
||||
/* Rename table: noSegments to lockCategories */
|
||||
ALTER TABLE "noSegments" RENAME TO "lockCategories";
|
||||
|
||||
UPDATE "config" SET value = 11 WHERE key = 'version';
|
||||
|
||||
COMMIT;
|
12
src/app.ts
12
src/app.ts
|
@ -5,8 +5,8 @@ import {oldGetVideoSponsorTimes} from './routes/oldGetVideoSponsorTimes';
|
|||
import {postSegmentShift} from './routes/postSegmentShift';
|
||||
import {postWarning} from './routes/postWarning';
|
||||
import {getIsUserVIP} from './routes/getIsUserVIP';
|
||||
import {deleteNoSegmentsEndpoint} from './routes/deleteNoSegments';
|
||||
import {postNoSegments} from './routes/postNoSegments';
|
||||
import {deleteLockCategoriesEndpoint} from './routes/deleteLockCategories';
|
||||
import {postLockCategories} from './routes/postLockCategories';
|
||||
import {getUserInfo} from './routes/getUserInfo';
|
||||
import {getDaysSavedFormatted} from './routes/getDaysSavedFormatted';
|
||||
import {getTotalStats} from './routes/getTotalStats';
|
||||
|
@ -114,10 +114,12 @@ function setupRoutes(app: Express) {
|
|||
//send out a formatted time saved total
|
||||
app.get('/api/getDaysSavedFormatted', getDaysSavedFormatted);
|
||||
|
||||
//submit video containing no segments
|
||||
app.post('/api/noSegments', postNoSegments);
|
||||
//submit video to lock categories
|
||||
app.post('/api/noSegments', postLockCategories);
|
||||
app.post('/api/lockCategories', postLockCategories);
|
||||
|
||||
app.delete('/api/noSegments', deleteNoSegmentsEndpoint);
|
||||
app.delete('/api/noSegments', deleteLockCategoriesEndpoint);
|
||||
app.delete('/api/lockCategories', deleteLockCategoriesEndpoint);
|
||||
|
||||
//get if user is a vip
|
||||
app.get('/api/isUserVIP', getIsUserVIP);
|
||||
|
|
|
@ -63,7 +63,7 @@ addDefaults(config, {
|
|||
name: "categoryVotes"
|
||||
},
|
||||
{
|
||||
name: "noSegments",
|
||||
name: "lockCategories",
|
||||
},
|
||||
{
|
||||
name: "warnings",
|
||||
|
|
|
@ -5,7 +5,7 @@ import {db} from '../databases/databases';
|
|||
import { Category, VideoID } from '../types/segments.model';
|
||||
import { UserID } from '../types/user.model';
|
||||
|
||||
export async function deleteNoSegmentsEndpoint(req: Request, res: Response) {
|
||||
export async function deleteLockCategoriesEndpoint(req: Request, res: Response) {
|
||||
// Collect user input data
|
||||
const videoID = req.body.videoID as VideoID;
|
||||
const userID = req.body.userID as UserID;
|
||||
|
@ -35,9 +35,9 @@ export async function deleteNoSegmentsEndpoint(req: Request, res: Response) {
|
|||
return;
|
||||
}
|
||||
|
||||
deleteNoSegments(videoID, categories);
|
||||
deleteLockCategories(videoID, categories);
|
||||
|
||||
res.status(200).json({message: 'Removed no segments entrys for video ' + videoID});
|
||||
res.status(200).json({message: 'Removed lock categories entrys for video ' + videoID});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,12 +45,12 @@ export async function deleteNoSegmentsEndpoint(req: Request, res: Response) {
|
|||
* @param videoID
|
||||
* @param categories If null, will remove all
|
||||
*/
|
||||
export async function deleteNoSegments(videoID: VideoID, categories: Category[]): Promise<void> {
|
||||
const entries = (await db.prepare("all", 'SELECT * FROM "noSegments" WHERE "videoID" = ?', [videoID])).filter((entry: any) => {
|
||||
export async function deleteLockCategories(videoID: VideoID, categories: Category[]): Promise<void> {
|
||||
const entries = (await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID])).filter((entry: any) => {
|
||||
return categories === null || categories.indexOf(entry.category) !== -1;
|
||||
});
|
||||
|
||||
for (const entry of entries) {
|
||||
await db.prepare('run', 'DELETE FROM "noSegments" WHERE "videoID" = ? AND "category" = ?', [videoID, entry.category]);
|
||||
await db.prepare('run', 'DELETE FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?', [videoID, entry.category]);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import {isUserVIP} from '../utils/isUserVIP';
|
|||
import {db} from '../databases/databases';
|
||||
import {Request, Response} from 'express';
|
||||
|
||||
export async function postNoSegments(req: Request, res: Response) {
|
||||
export async function postLockCategories(req: Request, res: Response) {
|
||||
// Collect user input data
|
||||
let videoID = req.body.videoID;
|
||||
let userID = req.body.userID;
|
||||
|
@ -34,12 +34,12 @@ export async function postNoSegments(req: Request, res: Response) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Get existing no segment markers
|
||||
let noSegmentList = await db.prepare('all', 'SELECT "category" from "noSegments" where "videoID" = ?', [videoID]);
|
||||
if (!noSegmentList || noSegmentList.length === 0) {
|
||||
noSegmentList = [];
|
||||
// Get existing lock categories markers
|
||||
let noCategoryList = await db.prepare('all', 'SELECT "category" from "lockCategories" where "videoID" = ?', [videoID]);
|
||||
if (!noCategoryList || noCategoryList.length === 0) {
|
||||
noCategoryList = [];
|
||||
} else {
|
||||
noSegmentList = noSegmentList.map((obj: any) => {
|
||||
noCategoryList = noCategoryList.map((obj: any) => {
|
||||
return obj.category;
|
||||
});
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export async function postNoSegments(req: Request, res: Response) {
|
|||
let categoriesToMark = categories.filter((category) => {
|
||||
return !!category.match(/^[_a-zA-Z]+$/);
|
||||
}).filter((category) => {
|
||||
return noSegmentList.indexOf(category) === -1;
|
||||
return noCategoryList.indexOf(category) === -1;
|
||||
});
|
||||
|
||||
// remove any duplicates
|
||||
|
@ -59,9 +59,9 @@ export async function postNoSegments(req: Request, res: Response) {
|
|||
// create database entry
|
||||
for (const category of categoriesToMark) {
|
||||
try {
|
||||
await db.prepare('run', `INSERT INTO "noSegments" ("videoID", "userID", "category") VALUES(?, ?, ?)`, [videoID, userID, category]);
|
||||
await db.prepare('run', `INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES(?, ?, ?)`, [videoID, userID, category]);
|
||||
} catch (err) {
|
||||
Logger.error("Error submitting 'noSegment' marker for category '" + category + "' for video '" + videoID + "'");
|
||||
Logger.error("Error submitting 'lockCategories' marker for category '" + category + "' for video '" + videoID + "'");
|
||||
Logger.error(err);
|
||||
res.status(500).json({
|
||||
message: "Internal Server Error: Could not write marker to the database.",
|
|
@ -14,7 +14,7 @@ import {Request, Response} from 'express';
|
|||
import { skipSegmentsHashKey, skipSegmentsKey } from '../middleware/redisKeys';
|
||||
import redis from '../utils/redis';
|
||||
import { Category, IncomingSegment, Segment, SegmentUUID, Service, VideoDuration, VideoID } from '../types/segments.model';
|
||||
import { deleteNoSegments } from './deleteNoSegments';
|
||||
import { deleteLockCategories } from './deleteLockCategories';
|
||||
|
||||
interface APIVideoInfo {
|
||||
err: string | boolean,
|
||||
|
@ -358,7 +358,7 @@ export async function postSkipSegments(req: Request, res: Response) {
|
|||
return res.status(403).send('Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes that are not malicious, and we just want to clarify the rules. Could you please send a message in Discord or Matrix so we can further help you?');
|
||||
}
|
||||
|
||||
let noSegmentList = (await db.prepare('all', 'SELECT category from "noSegments" where "videoID" = ?', [videoID])).map((list: any) => {
|
||||
let lockedCategoryList = (await db.prepare('all', 'SELECT category from "lockCategories" where "videoID" = ?', [videoID])).map((list: any) => {
|
||||
return list.category;
|
||||
});
|
||||
|
||||
|
@ -388,9 +388,9 @@ export async function postSkipSegments(req: Request, res: Response) {
|
|||
await db.prepare('run', `UPDATE "sponsorTimes" SET "hidden" = 1 WHERE "UUID" = ?`, [submission.UUID]);
|
||||
}
|
||||
|
||||
// Reset no segments
|
||||
noSegmentList = [];
|
||||
deleteNoSegments(videoID, null);
|
||||
// Reset lock categories
|
||||
lockedCategoryList = [];
|
||||
deleteLockCategories(videoID, null);
|
||||
}
|
||||
|
||||
// Check if all submissions are correct
|
||||
|
@ -406,8 +406,8 @@ export async function postSkipSegments(req: Request, res: Response) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Reject segemnt if it's in the no segments list
|
||||
if (!isVIP && noSegmentList.indexOf(segments[i].category) !== -1) {
|
||||
// Reject segment if it's in the locked categories list
|
||||
if (!isVIP && lockedCategoryList.indexOf(segments[i].category) !== -1) {
|
||||
// TODO: Do something about the fradulent submission
|
||||
Logger.warn("Caught a no-segment submission. userID: '" + userID + "', videoID: '" + videoID + "', category: '" + segments[i].category + "'");
|
||||
res.status(403).send(
|
||||
|
|
|
@ -43,8 +43,8 @@ export async function shadowBanUser(req: Request, res: Response) {
|
|||
//find all previous submissions and hide them
|
||||
if (unHideOldSubmissions) {
|
||||
await db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ?
|
||||
AND NOT EXISTS ( SELECT "videoID", "category" FROM "noSegments" WHERE
|
||||
"sponsorTimes"."videoID" = "noSegments"."videoID" AND "sponsorTimes"."category" = "noSegments"."category")`, [userID]);
|
||||
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
|
||||
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
|
||||
}
|
||||
} else if (!enabled && row.userCount > 0) {
|
||||
//remove them from the shadow ban list
|
||||
|
@ -53,7 +53,7 @@ export async function shadowBanUser(req: Request, res: Response) {
|
|||
//find all previous submissions and unhide them
|
||||
if (unHideOldSubmissions) {
|
||||
let segmentsToIgnore = (await db.prepare('all', `SELECT "UUID" FROM "sponsorTimes" st
|
||||
JOIN "noSegments" ns on "st"."videoID" = "ns"."videoID" AND st.category = ns.category WHERE "st"."userID" = ?`
|
||||
JOIN "lockCategories" ns on "st"."videoID" = "ns"."videoID" AND st.category = ns.category WHERE "st"."userID" = ?`
|
||||
, [userID])).map((item: {UUID: string}) => item.UUID);
|
||||
let allSegments = (await db.prepare('all', `SELECT "UUID" FROM "sponsorTimes" st WHERE "st"."userID" = ?`, [userID]))
|
||||
.map((item: {UUID: string}) => item.UUID);
|
||||
|
|
|
@ -272,8 +272,8 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
|
|||
// If not upvote
|
||||
if (!isVIP && type !== 1) {
|
||||
const isSegmentLocked = async () => !!(await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]))?.locked;
|
||||
const isVideoLocked = async () => !!(await db.prepare('get', 'SELECT "noSegments".category from "noSegments" left join "sponsorTimes"' +
|
||||
' on ("noSegments"."videoID" = "sponsorTimes"."videoID" and "noSegments".category = "sponsorTimes".category)' +
|
||||
const isVideoLocked = async () => !!(await db.prepare('get', 'SELECT "lockCategories".category from "lockCategories" left join "sponsorTimes"' +
|
||||
' on ("lockCategories"."videoID" = "sponsorTimes"."videoID" and "lockCategories".category = "sponsorTimes".category)' +
|
||||
' where "UUID" = ?', [UUID]));
|
||||
|
||||
if (await isSegmentLocked() || await isVideoLocked()) {
|
||||
|
|
|
@ -4,21 +4,21 @@ import {getHash} from '../../src/utils/getHash';
|
|||
import {db} from '../../src/databases/databases';
|
||||
|
||||
|
||||
describe('noSegmentRecords', () => {
|
||||
describe('lockCategoriesRecords', () => {
|
||||
before(async () => {
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('` + getHash("VIPUser-noSegments") + "')");
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('` + getHash("VIPUser-lockCategories") + "')");
|
||||
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'intro')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'no-segments-video-id', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'no-segments-video-id', 'intro')");
|
||||
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'intro')");
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'noSubmitVideo', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'no-segments-video-id-1', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'no-segments-video-id-1', 'intro')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'lockCategoryVideo', 'sponsor')");
|
||||
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'delete-record', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'delete-record', 'sponsor')");
|
||||
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'intro')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'delete-record-1', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-lockCategories") + "', 'delete-record-1', 'intro')");
|
||||
});
|
||||
|
||||
it('Should update the database version when starting the application', async () => {
|
||||
|
@ -30,7 +30,7 @@ describe('noSegmentRecords', () => {
|
|||
it('Should be able to submit categories not in video (http response)', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'no-segments-video-id',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'outro',
|
||||
'shilling',
|
||||
|
@ -48,7 +48,7 @@ describe('noSegmentRecords', () => {
|
|||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -75,7 +75,7 @@ describe('noSegmentRecords', () => {
|
|||
it('Should be able to submit categories not in video (sql check)', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'no-segments-video-id-1',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'outro',
|
||||
'shilling',
|
||||
|
@ -86,7 +86,7 @@ describe('noSegmentRecords', () => {
|
|||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -95,7 +95,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['no-segments-video-id-1']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id-1']);
|
||||
if (result.length !== 4) {
|
||||
console.log(result);
|
||||
done("Expected 4 entrys in db, got " + result.length);
|
||||
|
@ -114,13 +114,13 @@ describe('noSegmentRecords', () => {
|
|||
it('Should be able to submit categories with _ in the category', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'underscore',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'word_word',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -129,7 +129,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['underscore']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['underscore']);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
|
@ -148,13 +148,13 @@ describe('noSegmentRecords', () => {
|
|||
it('Should be able to submit categories with upper and lower case in the category', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'bothCases',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'wordWord',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -163,7 +163,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['bothCases']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['bothCases']);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
|
@ -182,13 +182,13 @@ describe('noSegmentRecords', () => {
|
|||
it('Should not be able to submit categories with $ in the category', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'specialChar',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'word&word',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -197,7 +197,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['specialChar']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['specialChar']);
|
||||
if (result.length !== 0) {
|
||||
console.log(result);
|
||||
done("Expected 0 entrys in db, got " + result.length);
|
||||
|
@ -214,7 +214,7 @@ describe('noSegmentRecords', () => {
|
|||
});
|
||||
|
||||
it('Should return 400 for missing params', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -238,7 +238,7 @@ describe('noSegmentRecords', () => {
|
|||
categories: [],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -262,7 +262,7 @@ describe('noSegmentRecords', () => {
|
|||
categories: ['sponsor'],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -286,7 +286,7 @@ describe('noSegmentRecords', () => {
|
|||
categories: ['sponsor'],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -310,7 +310,7 @@ describe('noSegmentRecords', () => {
|
|||
categories: {},
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -334,7 +334,7 @@ describe('noSegmentRecords', () => {
|
|||
categories: 'sponsor',
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -360,7 +360,7 @@ describe('noSegmentRecords', () => {
|
|||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -377,16 +377,16 @@ describe('noSegmentRecords', () => {
|
|||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to delete a noSegment record', (done: Done) => {
|
||||
it('Should be able to delete a lockCategories record', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'delete-record',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'sponsor',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -395,7 +395,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['delete-record']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record']);
|
||||
if (result.length === 0) {
|
||||
done();
|
||||
} else {
|
||||
|
@ -408,16 +408,16 @@ describe('noSegmentRecords', () => {
|
|||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to delete one noSegment record without removing another', (done: Done) => {
|
||||
it('Should be able to delete one lockCategories record without removing another', (done: Done) => {
|
||||
let json = {
|
||||
videoID: 'delete-record-1',
|
||||
userID: 'VIPUser-noSegments',
|
||||
userID: 'VIPUser-lockCategories',
|
||||
categories: [
|
||||
'sponsor',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/noSegments", {
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -426,7 +426,7 @@ describe('noSegmentRecords', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let result = await db.prepare('all', 'SELECT * FROM "noSegments" WHERE "videoID" = ?', ['delete-record-1']);
|
||||
let result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record-1']);
|
||||
if (result.length === 1) {
|
||||
done();
|
||||
} else {
|
||||
|
@ -445,7 +445,7 @@ describe('noSegmentRecords', () => {
|
|||
* To test the submission code properly see ./test/cases/postSkipSegments.js
|
||||
*/
|
||||
|
||||
it('Should not be able to submit a segment to a video with a no-segment record (single submission)', (done: Done) => {
|
||||
it('Should not be able to submit a segment to a video with a lock-category record (single submission)', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -453,7 +453,7 @@ describe('noSegmentRecords', () => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
userID: "testman42",
|
||||
videoID: "noSubmitVideo",
|
||||
videoID: "lockCategoryVideo",
|
||||
segments: [{
|
||||
segment: [20, 40],
|
||||
category: "sponsor",
|
||||
|
@ -478,7 +478,7 @@ describe('noSegmentRecords', () => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
userID: "testman42",
|
||||
videoID: "noSubmitVideo",
|
||||
videoID: "lockCategoryVideo",
|
||||
segments: [{
|
||||
segment: [20, 40],
|
||||
category: "sponsor",
|
||||
|
@ -507,7 +507,7 @@ describe('noSegmentRecords', () => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
userID: "testman42",
|
||||
videoID: "noSubmitVideo",
|
||||
videoID: "lockCategoryVideo",
|
||||
segments: [{
|
||||
segment: [20, 40],
|
||||
category: "intro",
|
|
@ -195,8 +195,8 @@ 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 "noSegments" ("userID", "videoID", "category")
|
||||
VALUES ('` + getHash("VIPUser-noSegments") + "', 'noDuration', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category")
|
||||
VALUES ('` + getHash("VIPUser-lockCategories") + "', 'noDuration', 'sponsor')");
|
||||
|
||||
try {
|
||||
const res = await fetch(getbaseURL()
|
||||
|
@ -217,13 +217,13 @@ describe('postSkipSegments', () => {
|
|||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
const noSegmentsRow = await db.prepare('get', `SELECT * from "noSegments" WHERE videoID = ?`, ["noDuration"]);
|
||||
const lockCategoriesRow = await db.prepare('get', `SELECT * from "lockCategories" WHERE videoID = ?`, ["noDuration"]);
|
||||
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"
|
||||
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, ["noDuration"]);
|
||||
if (noSegmentsRow === undefined && videoRows.length === 1 && hiddenVideoRows.length === 1 && videoRow.startTime === 1 && videoRow.endTime === 10
|
||||
if (lockCategoriesRow === undefined && videoRows.length === 1 && hiddenVideoRows.length === 1 && videoRow.startTime === 1 && videoRow.endTime === 10
|
||||
&& videoRow.locked === 0 && videoRow.category === "sponsor" && videoRow.videoDuration === 100) {
|
||||
return;
|
||||
} else {
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('unBan', () => {
|
|||
await privateDB.prepare("run", `INSERT INTO "shadowBannedUsers" VALUES('testEntity-unBan')`);
|
||||
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('` + getHash("VIPUser-unBan") + "')");
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')");
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES ('` + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')");
|
||||
|
||||
let startOfInsertSegmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES';
|
||||
await db.prepare("run", startOfInsertSegmentQuery + "('unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-0', 1) + "')");
|
||||
|
@ -47,7 +47,7 @@ describe('unBan', () => {
|
|||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to unban a user and re-enable shadow banned segments without noSegment entrys', (done) => {
|
||||
it('Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys', (done) => {
|
||||
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -72,7 +72,7 @@ describe('unBan', () => {
|
|||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to unban a user and re-enable shadow banned segments with a mix of noSegment entrys', (done) => {
|
||||
it('Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys', (done) => {
|
||||
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
|
@ -59,7 +59,7 @@ describe('voteOnSponsorTime', () => {
|
|||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('` + getHash("VIPUser") + "')");
|
||||
await privateDB.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES ('` + getHash("randomID4") + "')");
|
||||
|
||||
await db.prepare("run", `INSERT INTO "noSegments" ("videoID", "userID", "category") VALUES ('no-sponsor-segments-video', 'someUser', 'sponsor')`);
|
||||
await db.prepare("run", `INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES ('no-sponsor-segments-video', 'someUser', 'sponsor')`);
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue