From be9d97ae2bf7654b7bd7743fa1a1bc5a8fd9b1e2 Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 18 Jan 2025 02:09:46 -0500 Subject: [PATCH] Add option to trim UUIDs in skip segments endpoint --- src/routes/getSkipSegments.ts | 4 ++-- src/routes/getSkipSegmentsByHash.ts | 4 ++-- src/utils/parseSkipSegments.ts | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/routes/getSkipSegments.ts b/src/routes/getSkipSegments.ts index 098813ee..c1408287 100644 --- a/src/routes/getSkipSegments.ts +++ b/src/routes/getSkipSegments.ts @@ -150,7 +150,7 @@ async function getSegmentsByVideoID(req: Request, videoID: VideoID, categories: } async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, categories: Category[], - actionTypes: ActionType[], requiredSegments: SegmentUUID[], service: Service): Promise> { + actionTypes: ActionType[], trimUUIDs: number, requiredSegments: SegmentUUID[], service: Service): Promise> { const cache: SegmentCache = { shadowHiddenSegmentIPs: {} }; const segments: SBRecord = {}; @@ -188,7 +188,7 @@ async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash, category: segment.category, actionType: segment.actionType, segment: segment.segment, - UUID: segment.UUID, + UUID: trimUUIDs ? segment.UUID.substring(0, trimUUIDs) as SegmentUUID : segment.UUID, videoDuration: segment.videoDuration, locked: segment.locked, votes: segment.votes, diff --git a/src/routes/getSkipSegmentsByHash.ts b/src/routes/getSkipSegmentsByHash.ts index d5b89bdb..2110c4d9 100644 --- a/src/routes/getSkipSegmentsByHash.ts +++ b/src/routes/getSkipSegmentsByHash.ts @@ -17,10 +17,10 @@ export async function getSkipSegmentsByHash(req: Request, res: Response): Promis if (parseResult.errors.length > 0) { return res.status(400).send(parseResult.errors); } - const { categories, actionTypes, requiredSegments, service } = parseResult; + const { categories, actionTypes, trimUUIDs, requiredSegments, service } = parseResult; // Get all video id's that match hash prefix - const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, requiredSegments, service); + const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, trimUUIDs, requiredSegments, service); try { await getEtag("skipSegmentsHash", hashPrefix, service) diff --git a/src/utils/parseSkipSegments.ts b/src/utils/parseSkipSegments.ts index 1e0378c0..acf0bf3a 100644 --- a/src/utils/parseSkipSegments.ts +++ b/src/utils/parseSkipSegments.ts @@ -9,12 +9,14 @@ const errorMessage = (parameter: string) => `${parameter} parameter does not mat export function parseSkipSegments(req: Request): { categories: Category[]; actionTypes: ActionType[]; + trimUUIDs: number | null; requiredSegments: SegmentUUID[]; service: Service; errors: string[]; } { const categories: Category[] = parseCategories(req, [ "sponsor" as Category ]); const actionTypes: ActionType[] = parseActionTypes(req, [ActionType.Skip]); + const trimUUIDs: number | null = req.query.trimUUIDs ? (parseInt(req.query.trimUUIDs as string) || null) : null; const requiredSegments: SegmentUUID[] = parseRequiredSegments(req); const service: Service = getService(req.query.service, req.body.services); const errors: string[] = []; @@ -27,6 +29,7 @@ export function parseSkipSegments(req: Request): { return { categories, actionTypes, + trimUUIDs, requiredSegments, service, errors