From 120a5e16dd8e735383d24c154fd351146b282d0e Mon Sep 17 00:00:00 2001 From: Altay <9790196+altaywtf@users.noreply.github.com> Date: Wed, 10 May 2023 12:19:02 +0300 Subject: [PATCH] update File.GetHLSStreamURL method --- src/resources/Files/File.spec.ts | 35 ++++++++++++++++++++++++++++++++ src/resources/Files/File.ts | 11 +++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/resources/Files/File.spec.ts diff --git a/src/resources/Files/File.spec.ts b/src/resources/Files/File.spec.ts new file mode 100644 index 0000000..f2d46c6 --- /dev/null +++ b/src/resources/Files/File.spec.ts @@ -0,0 +1,35 @@ +import PutioAPIClient from '../../index' + +describe('resources/Files/File', () => { + const API = new PutioAPIClient({ + baseURL: '', + }) + + it('should create correct HLS stream URL when no params given', () => { + expect(API.File.GetHLSStreamURL(0)).toBe('/files/0/hls/media.m3u8') + }) + + it('should add token to HLS stream url if set', () => { + API.setToken('token') + + expect(API.File.GetHLSStreamURL(0)).toBe( + '/files/0/hls/media.m3u8?oauth_token=token', + ) + + API.clearToken() + }) + + it('should create correct HLS stream URL when params given', () => { + expect(API.File.GetHLSStreamURL(0, { playOriginal: true })).toBe( + '/files/0/hls/media.m3u8?original=1', + ) + + expect(API.File.GetHLSStreamURL(0, { maxSubtitleCount: 1 })).toBe( + '/files/0/hls/media.m3u8?max_subtitle_count=1', + ) + + expect( + API.File.GetHLSStreamURL(0, { playOriginal: true, maxSubtitleCount: 1 }), + ).toBe('/files/0/hls/media.m3u8?max_subtitle_count=1&original=1') + }) +}) diff --git a/src/resources/Files/File.ts b/src/resources/Files/File.ts index 4bf1ae1..e196823 100644 --- a/src/resources/Files/File.ts +++ b/src/resources/Files/File.ts @@ -56,8 +56,8 @@ export default class File { { token = '', subtitleLanguages = [], - maxSubtitleCount = -1, - playOriginal = false, + maxSubtitleCount, + playOriginal, }: { token?: string subtitleLanguages?: string[] @@ -72,7 +72,12 @@ export default class File { oauth_token: token || this.client.token, subtitle_languages: subtitleLanguages, max_subtitle_count: maxSubtitleCount, - original: playOriginal ? 1 : 0, + original: + typeof playOriginal === 'boolean' + ? playOriginal + ? 1 + : 0 + : undefined, }) .toString() }