From 2455d2cd7e70bd0c3da72065454222e232f440d6 Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 17 Jan 2025 23:59:17 -0500 Subject: [PATCH] Make hasStartSegment result optional --- src/routes/getVideoLabel.ts | 8 ++++---- src/routes/getVideoLabelByHash.ts | 4 +++- test/cases/getVideoLabelByHash.ts | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/routes/getVideoLabel.ts b/src/routes/getVideoLabel.ts index 84e62278..29a897a9 100644 --- a/src/routes/getVideoLabel.ts +++ b/src/routes/getVideoLabel.ts @@ -34,7 +34,7 @@ async function getLabelsByVideoID(videoID: VideoID, service: Service): Promise> { +async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Service, checkHasStartSegment: boolean): Promise> { const segments: SBRecord = {}; try { @@ -57,10 +57,10 @@ async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Servic const result = chooseSegment(videoData.segments); const data: FullVideoSegmentVideoData = { segments: result.segments, - hasStartSegment: result.hasStartSegment + hasStartSegment: checkHasStartSegment ? result.hasStartSegment : undefined }; - if (data.segments.length > 0 || data.hasStartSegment) { + if (data.segments.length > 0 || (data.hasStartSegment && checkHasStartSegment)) { segments[videoID] = data; } } @@ -153,7 +153,7 @@ async function handleGetLabel(req: Request, res: Response): Promise { assert.strictEqual(data[0].segments.length, 1); } - const get = (videoID: string) => client.get(`${endpoint}/${getHash(videoID, 1).substring(0, 4)}`); + const get = (videoID: string, hasStartSegment = false) => client.get(`${endpoint}/${getHash(videoID, 1).substring(0, 4)}?hasStartSegment=${hasStartSegment}`); it("Should be able to get sponsor only label", (done) => { const videoID = "getLabelHashSponsor"; - get(videoID) + get(videoID, true) .then(res => { assert.strictEqual(res.status, 200); const data = res.data; @@ -55,7 +55,7 @@ describe("getVideoLabelHash", () => { it("Should be able to get exclusive access only label", (done) => { const videoID = "getLabelHashEA"; - get(videoID) + get(videoID, true) .then(res => { assert.strictEqual(res.status, 200); const data = res.data; @@ -77,6 +77,7 @@ describe("getVideoLabelHash", () => { validateLabel(data, videoID); const result = data[0].segments[0]; assert.strictEqual(result.category, "selfpromo"); + assert.strictEqual(data[0].hasStartSegment, undefined); done(); }) .catch(err => done(err));