Remove use of "CategoryActionType"

This commit is contained in:
Ajay
2022-01-19 18:11:01 -05:00
parent 6ece944536
commit d367998d39
6 changed files with 15 additions and 27 deletions

View File

@@ -30,7 +30,7 @@ addDefaults(config, {
preview: ["skip", "mute"], preview: ["skip", "mute"],
filler: ["skip", "mute"], filler: ["skip", "mute"],
music_offtopic: ["skip"], music_offtopic: ["skip"],
poi_highlight: ["skip"], poi_highlight: ["poi"],
chapter: ["chapter"] chapter: ["chapter"]
}, },
maxNumberOfActiveWarnings: 1, maxNumberOfActiveWarnings: 1,

View File

@@ -4,8 +4,7 @@ import { config } from "../config";
import { db, privateDB } from "../databases/databases"; import { db, privateDB } from "../databases/databases";
import { skipSegmentsHashKey, skipSegmentsKey, skipSegmentGroupsKey } from "../utils/redisKeys"; import { skipSegmentsHashKey, skipSegmentsKey, skipSegmentGroupsKey } from "../utils/redisKeys";
import { SBRecord } from "../types/lib.model"; import { SBRecord } from "../types/lib.model";
import { ActionType, Category, CategoryActionType, DBSegment, HashedIP, IPAddress, OverlappingSegmentGroup, Segment, SegmentCache, SegmentUUID, Service, VideoData, VideoID, VideoIDHash, Visibility, VotableObject } from "../types/segments.model"; import { ActionType, Category, DBSegment, HashedIP, IPAddress, OverlappingSegmentGroup, Segment, SegmentCache, SegmentUUID, Service, VideoData, VideoID, VideoIDHash, Visibility, VotableObject } from "../types/segments.model";
import { getCategoryActionType } from "../utils/categoryInfo";
import { getHashCache } from "../utils/getHashCache"; import { getHashCache } from "../utils/getHashCache";
import { getIP } from "../utils/getIP"; import { getIP } from "../utils/getIP";
import { Logger } from "../utils/logger"; import { Logger } from "../utils/logger";
@@ -263,7 +262,7 @@ async function chooseSegments(videoID: VideoID, service: Service, segments: DBSe
// Filter for only 1 item for POI categories and Full video // Filter for only 1 item for POI categories and Full video
let chosenGroups = getWeightedRandomChoice(groups, 1, true, (choice) => choice.segments[0].actionType === ActionType.Full); let chosenGroups = getWeightedRandomChoice(groups, 1, true, (choice) => choice.segments[0].actionType === ActionType.Full);
chosenGroups = getWeightedRandomChoice(chosenGroups, 1, true, (choice) => getCategoryActionType(choice.segments[0].category) === CategoryActionType.POI); chosenGroups = getWeightedRandomChoice(chosenGroups, 1, true, (choice) => choice.segments[0].actionType === ActionType.Poi);
return chosenGroups.map(//randomly choose 1 good segment per group and return them return chosenGroups.map(//randomly choose 1 good segment per group and return them
group => getWeightedRandomChoice(group.segments, 1)[0] group => getWeightedRandomChoice(group.segments, 1)[0]
); );

View File

@@ -9,9 +9,8 @@ import { getIP } from "../utils/getIP";
import { getFormattedTime } from "../utils/getFormattedTime"; import { getFormattedTime } from "../utils/getFormattedTime";
import { dispatchEvent } from "../utils/webhookUtils"; import { dispatchEvent } from "../utils/webhookUtils";
import { Request, Response } from "express"; import { Request, Response } from "express";
import { ActionType, Category, CategoryActionType, IncomingSegment, IPAddress, SegmentUUID, Service, VideoDuration, VideoID } from "../types/segments.model"; import { ActionType, Category, IncomingSegment, IPAddress, SegmentUUID, Service, VideoDuration, VideoID } from "../types/segments.model";
import { deleteLockCategories } from "./deleteLockCategories"; import { deleteLockCategories } from "./deleteLockCategories";
import { getCategoryActionType } from "../utils/categoryInfo";
import { QueryCacher } from "../utils/queryCacher"; import { QueryCacher } from "../utils/queryCacher";
import { getReputation } from "../utils/reputation"; import { getReputation } from "../utils/reputation";
import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model"; import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model";
@@ -375,6 +374,11 @@ async function checkEachSegmentValid(rawIP: IPAddress, paramUserID: UserID, user
}; };
} }
// For old clients
if (segments[i].category === "poi_highlight" && segments[i].actionType !== ActionType.Poi) {
segments[i].actionType = ActionType.Poi;
}
if (!config.categorySupport[segments[i].category]?.includes(segments[i].actionType)) { if (!config.categorySupport[segments[i].category]?.includes(segments[i].actionType)) {
return { pass: false, errorMessage: "ActionType is not supported with this category.", errorCode: 400 }; return { pass: false, errorMessage: "ActionType is not supported with this category.", errorCode: 400 };
} }
@@ -384,16 +388,16 @@ async function checkEachSegmentValid(rawIP: IPAddress, paramUserID: UserID, user
if (isNaN(startTime) || isNaN(endTime) if (isNaN(startTime) || isNaN(endTime)
|| startTime === Infinity || endTime === Infinity || startTime < 0 || startTime > endTime || startTime === Infinity || endTime === Infinity || startTime < 0 || startTime > endTime
|| (getCategoryActionType(segments[i].category) === CategoryActionType.Skippable || (segments[i].actionType !== ActionType.Poi
&& segments[i].actionType !== ActionType.Full && startTime === endTime) && segments[i].actionType !== ActionType.Full && startTime === endTime)
|| (getCategoryActionType(segments[i].category) === CategoryActionType.POI && startTime !== endTime) || (segments[i].actionType === ActionType.Poi && startTime !== endTime)
|| (segments[i].actionType === ActionType.Full && (startTime !== 0 || endTime !== 0))) { || (segments[i].actionType === ActionType.Full && (startTime !== 0 || endTime !== 0))) {
//invalid request //invalid request
return { pass: false, errorMessage: "One of your segments times are invalid (too short, endTime before startTime, etc.)", errorCode: 400 }; return { pass: false, errorMessage: "One of your segments times are invalid (too short, endTime before startTime, etc.)", errorCode: 400 };
} }
// Check for POI segments before some seconds // Check for POI segments before some seconds
if (!isVIP && getCategoryActionType(segments[i].category) === CategoryActionType.POI && startTime < config.poiMinimumStartTime) { if (!isVIP && segments[i].actionType === ActionType.Poi && startTime < config.poiMinimumStartTime) {
return { pass: false, errorMessage: `POI cannot be that early`, errorCode: 400 }; return { pass: false, errorMessage: `POI cannot be that early`, errorCode: 400 };
} }

View File

@@ -10,8 +10,7 @@ import { getIP } from "../utils/getIP";
import { getHashCache } from "../utils/getHashCache"; import { getHashCache } from "../utils/getHashCache";
import { config } from "../config"; import { config } from "../config";
import { HashedUserID, UserID } from "../types/user.model"; import { HashedUserID, UserID } from "../types/user.model";
import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility, VideoDuration, ActionType } from "../types/segments.model"; import { Category, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility, VideoDuration, ActionType } from "../types/segments.model";
import { getCategoryActionType } from "../utils/categoryInfo";
import { QueryCacher } from "../utils/queryCacher"; import { QueryCacher } from "../utils/queryCacher";
import axios from "axios"; import axios from "axios";
import redis from "../utils/redis"; import redis from "../utils/redis";
@@ -211,8 +210,8 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i
if (!config.categoryList.includes(category)) { if (!config.categoryList.includes(category)) {
return { status: 400, message: "Category doesn't exist." }; return { status: 400, message: "Category doesn't exist." };
} }
if (getCategoryActionType(category) !== CategoryActionType.Skippable) { if (videoInfo.actionType === ActionType.Poi) {
return { status: 400, message: "Cannot vote for this category" }; return { status: 400, message: "Not allowed to change category for single point segments" };
} }
// Ignore vote if the next category is locked // Ignore vote if the next category is locked

View File

@@ -103,11 +103,6 @@ export interface SegmentCache {
userHashedIP?: HashedIP userHashedIP?: HashedIP
} }
export enum CategoryActionType {
Skippable,
POI
}
export interface DBLock { export interface DBLock {
videoID: VideoID, videoID: VideoID,
userID: HashedUserID, userID: HashedUserID,

View File

@@ -1,9 +0,0 @@
import { Category, CategoryActionType } from "../types/segments.model";
export function getCategoryActionType(category: Category): CategoryActionType {
if (category.startsWith("poi_")) {
return CategoryActionType.POI;
} else {
return CategoryActionType.Skippable;
}
}