Skip to content

Commit

Permalink
Make hasStartSegment result optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jan 18, 2025
1 parent e2a9976 commit 2455d2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/routes/getVideoLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function getLabelsByVideoID(videoID: VideoID, service: Service): Promise<F
}
}

async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Service): Promise<SBRecord<VideoID, FullVideoSegmentVideoData>> {
async function getLabelsByHash(hashedVideoIDPrefix: VideoIDHash, service: Service, checkHasStartSegment: boolean): Promise<SBRecord<VideoID, FullVideoSegmentVideoData>> {
const segments: SBRecord<VideoID, FullVideoSegmentVideoData> = {};

try {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ async function handleGetLabel(req: Request, res: Response): Promise<FullVideoSeg
return false;
}

const hasStartSegment = !!req.query.hasStartSegment;
const hasStartSegment = req.query.hasStartSegment === "true";

const service = getService(req.query.service, req.body.service);
const segmentData = await getLabelsByVideoID(videoID, service);
Expand Down
4 changes: 3 additions & 1 deletion src/routes/getVideoLabelByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export async function getVideoLabelsByHash(req: Request, res: Response): Promise
}
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;

const checkHasStartSegment = req.query.hasStartSegment === "true";

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, checkHasStartSegment);

if (!segments) return res.status(404).json([]);

Expand Down
7 changes: 4 additions & 3 deletions test/cases/getVideoLabelByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ describe("getVideoLabelHash", () => {
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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 2455d2c

Please sign in to comment.