diff --git a/src/routes/getVideoLabel.ts b/src/routes/getVideoLabel.ts index 1ddc98b..02ba7c5 100644 --- a/src/routes/getVideoLabel.ts +++ b/src/routes/getVideoLabel.ts @@ -118,16 +118,11 @@ function chooseSegment(choices: T[]): Segment[] { return transformDBSegments(choices); } // sponsor > exclusive > selfpromo - const sponsorResult = choices.find((segment) => segment.category === "sponsor"); - const eaResult = choices.find((segment) => segment.category === "exclusive_access"); - const selfpromoResult = choices.find((segment) => segment.category === "selfpromo"); - if (sponsorResult) { - results.push(sponsorResult); - } else if (eaResult) { - results.push(eaResult); - } else if (selfpromoResult) { - results.push(selfpromoResult); - } + const findCategory = (category: string) => choices.find((segment) => segment.category === category); + + const categoryResult = findCategory("sponsor") ?? findCategory("exclusive_access") ?? findCategory("selfpromo"); + if (categoryResult) results.push(categoryResult); + return transformDBSegments(results); } @@ -167,6 +162,6 @@ async function endpoint(req: Request, res: Response): Promise { export { getLabelsByVideoID, - getLabelsbyHash, + getLabelsByHash, endpoint }; diff --git a/src/routes/getVideoLabelByHash.ts b/src/routes/getVideoLabelByHash.ts index 7ffc0e3..e3a3615 100644 --- a/src/routes/getVideoLabelByHash.ts +++ b/src/routes/getVideoLabelByHash.ts @@ -1,5 +1,5 @@ import { hashPrefixTester } from "../utils/hashPrefixTester"; -import { getLabelsbyHash } from "./getVideoLabel"; +import { getLabelsByHash } from "./getVideoLabel"; import { Request, Response } from "express"; import { VideoIDHash, Service } from "../types/segments.model"; import { getService } from "../utils/getService"; @@ -14,7 +14,7 @@ export async function getVideoLabelsByHash(req: Request, res: Response): Promise const service: Service = getService(req.query.service, req.body.service); // Get all video id's that match hash prefix - const segments = await getLabelsbyHash(hashPrefix, service); + const segments = await getLabelsByHash(hashPrefix, service); if (!segments) return res.status(404).json([]);