mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 08:58:23 +03:00
Add hiding dearrow submissions in ban code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Request } from "express";
|
||||
import { ActionType, SegmentUUID, Category } from "../types/segments.model";
|
||||
import { ActionType, SegmentUUID, Category, DeArrowType } from "../types/segments.model";
|
||||
import { config } from "../config";
|
||||
|
||||
type fn = (req: Request, fallback: any) => any[];
|
||||
@@ -11,15 +11,21 @@ const syntaxErrorWrapper = (fn: fn, req: Request, fallback: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getCategories = (req: Request, fallback: Category[] ): string[] | Category[] =>
|
||||
req.query.categories
|
||||
? JSON.parse(req.query.categories as string)
|
||||
: req.query.category
|
||||
? Array.isArray(req.query.category)
|
||||
? req.query.category
|
||||
: [req.query.category]
|
||||
const getQueryList = <T>(req: Request, fallback: T[], param: string, paramPlural: string): string[] | T[] =>
|
||||
req.query[paramPlural]
|
||||
? JSON.parse(req.query[paramPlural] as string)
|
||||
: req.query[param]
|
||||
? Array.isArray(req.query[param])
|
||||
? req.query[param]
|
||||
: [req.query[param]]
|
||||
: fallback;
|
||||
|
||||
const getCategories = (req: Request, fallback: Category[] ): string[] | Category[] =>
|
||||
getQueryList(req, fallback, "category", "categories");
|
||||
|
||||
const getDeArrowTypes = (req: Request, fallback: DeArrowType[] ): string[] | DeArrowType[] =>
|
||||
getQueryList(req, fallback, "deArrowType", "deArrowTypes");
|
||||
|
||||
const validateString = (array: any[]): any[] => {
|
||||
if (!Array.isArray(array)) return undefined;
|
||||
return array
|
||||
@@ -71,6 +77,11 @@ export const parseActionTypes = (req: Request, fallback: ActionType[]): ActionTy
|
||||
return actionTypes ? validateString(actionTypes) : undefined;
|
||||
};
|
||||
|
||||
export const parseDeArrowTypes = (req: Request, fallback: DeArrowType[]): DeArrowType[] => {
|
||||
const deArrowTypes = syntaxErrorWrapper(getDeArrowTypes, req, fallback);
|
||||
return deArrowTypes ? validateString(deArrowTypes) : undefined;
|
||||
};
|
||||
|
||||
export const parseRequiredSegments = (req: Request): SegmentUUID[] | undefined =>
|
||||
syntaxErrorWrapper(getRequiredSegments, req, []); // never fall back
|
||||
|
||||
|
||||
Reference in New Issue
Block a user