From 0e91a08ae2194a07defc4b1e12ff3edbe13b72df Mon Sep 17 00:00:00 2001 From: Luan Date: Thu, 8 Aug 2024 09:01:14 -0300 Subject: [PATCH] fix(PlayerEndpoint): Don't set `undefined` fields --- src/core/endpoints/PlayerEndpoint.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/core/endpoints/PlayerEndpoint.ts b/src/core/endpoints/PlayerEndpoint.ts index a25b3123e..1c4c5152b 100644 --- a/src/core/endpoints/PlayerEndpoint.ts +++ b/src/core/endpoints/PlayerEndpoint.ts @@ -8,7 +8,7 @@ export const PATH = '/player'; * @returns The payload. */ export function build(opts: PlayerEndpointOptions): IPlayerRequest { - return { + const payload: IPlayerRequest = { playbackContext: { contentPlaybackContext: { vis: 0, @@ -33,14 +33,22 @@ export function build(opts: PlayerEndpointOptions): IPlayerRequest { }, racyCheckOk: true, contentCheckOk: true, - videoId: opts.video_id, - ...{ - client: opts.client, - playlistId: opts.playlist_id, - params: opts.params, - serviceIntegrityDimensions: { - poToken: opts.po_token || '' - } - } + videoId: opts.video_id }; + + if (opts.client) + payload.client = opts.client; + + if (opts.playlist_id) + payload.playlistId = opts.playlist_id; + + if (opts.params) + payload.params = opts.params; + + if (opts.po_token) + payload.serviceIntegrityDimensions = { + poToken: opts.po_token + }; + + return payload; } \ No newline at end of file