Add highlight category

This commit is contained in:
Ajay Ramachandran
2021-04-04 23:12:26 -04:00
parent bc688a3d8d
commit 6554e142cc
6 changed files with 52 additions and 6 deletions

View File

@@ -22,7 +22,7 @@
"mode": "development",
"readOnly": false,
"webhooks": [],
"categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "music_offtopic"], // List of supported categories any other category will be rejected
"categoryList": ["sponsor", "intro", "outro", "interaction", "selfpromo", "preview", "music_offtopic", "highlight"], // List of supported categories any other category will be rejected
"getTopUsersCacheTimeMinutes": 5, // cacheTime for getTopUsers result in minutes
"maxNumberOfActiveWarnings": 3, // Users with this number of warnings will be blocked until warnings expire
"hoursAfterWarningExpire": 24,

View File

@@ -16,7 +16,7 @@ addDefaults(config, {
privateDBSchema: "./databases/_private.db.sql",
readOnly: false,
webhooks: [],
categoryList: ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic"],
categoryList: ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "highlight"],
maxNumberOfActiveWarnings: 3,
hoursAfterWarningExpires: 24,
adminUserID: "",

View File

@@ -4,7 +4,7 @@ import {db, privateDB} from '../databases/databases';
import {YouTubeAPI} from '../utils/youtubeApi';
import {getSubmissionUUID} from '../utils/getSubmissionUUID';
import fetch from 'node-fetch';
import isoDurations from 'iso8601-duration';
import isoDurations, { end } from 'iso8601-duration';
import {getHash} from '../utils/getHash';
import {getIP} from '../utils/getIP';
import {getFormattedTime} from '../utils/getFormattedTime';
@@ -425,7 +425,8 @@ export async function postSkipSegments(req: Request, res: Response) {
let endTime = parseFloat(segments[i].segment[1]);
if (isNaN(startTime) || isNaN(endTime)
|| startTime === Infinity || endTime === Infinity || startTime < 0 || startTime >= endTime) {
|| startTime === Infinity || endTime === Infinity || startTime < 0 || startTime > endTime
|| (segments[i].category !== "highlight" && startTime === endTime) || (segments[i].category === "highlight" && startTime !== endTime)) {
//invalid request
res.status(400).send("One of your segments times are invalid (too short, startTime before endTime, etc.)");
return;

View File

@@ -4,7 +4,7 @@ import { SBRecord } from "./lib.model";
export type SegmentUUID = string & { __segmentUUIDBrand: unknown };
export type VideoID = string & { __videoIDBrand: unknown };
export type VideoDuration = number & { __videoDurationBrand: unknown };
export type Category = string & { __categoryBrand: unknown };
export type Category = ("sponsor" | "selfpromo" | "interaction" | "intro" | "outro" | "preview" | "music_offtopic" | "highlight") & { __categoryBrand: unknown };
export type VideoIDHash = VideoID & HashedValue;
export type IPAddress = string & { __ipAddressBrand: unknown };
export type HashedIP = IPAddress & HashedValue;

View File

@@ -49,7 +49,7 @@
]
}
],
"categoryList": ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic"],
"categoryList": ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "highlight"],
"maxNumberOfActiveWarnings": 3,
"hoursAfterWarningExpires": 24,
"rateLimit": {

View File

@@ -500,6 +500,51 @@ describe('postSkipSegments', () => {
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if segment starts and ends at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testing&category=intro", {
method: 'POST',
})
.then(async res => {
if (res.status === 400) done(); // pass
else {
const body = await res.text();
done("non 400 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be accepted if highlight segment starts and ends at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testing&category=highlight", {
method: 'POST',
})
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if highlight segment doesn\'t start and end at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=highlight", {
method: 'POST',
})
.then(async res => {
if (res.status === 400) done(); // pass
else {
const body = await res.text();
done("non 400 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", {