Add getService helper function

This commit is contained in:
Haidang666
2021-09-13 14:49:17 +07:00
parent 1e05c04a39
commit 93c69248d9
7 changed files with 55 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ import {hashPrefixTester} from "../utils/hashPrefixTester";
import {getSegmentsByHash} from "./getSkipSegments";
import {Request, Response} from "express";
import { ActionType, Category, SegmentUUID, Service, VideoIDHash } from "../types/segments.model";
import { getService } from "../utils/getService";
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
let hashPrefix = req.params.prefix as VideoIDHash;
@@ -58,10 +59,7 @@ export async function getSkipSegmentsByHash(req: Request, res: Response): Promis
return res.status(400).send("Bad parameter: requiredSegments (invalid JSON)");
}
let service: Service = req.query.service ?? req.body.service ?? Service.YouTube;
if (!Object.values(Service).some((val) => val == service)) {
service = Service.YouTube;
}
const service = getService(req.query.service, req.body.service);
// filter out none string elements, only flat array with strings is valid
categories = categories.filter((item: any) => typeof item === "string");