From 2e309bef7fed9d8f2f633a243d0ab0111550e8e0 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Sun, 8 Aug 2021 03:58:04 -0400 Subject: [PATCH] :bug: Fix Spotify pagination bug (#2061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed missing value Fixed infinite amount of interval triggered nodes executions * Fixed inifite loop on Spotify Node * Hide Limit parameter * Logic operator fix * Spotify getFollowingArtists returnAll fix * :zap: Small improvements to #2054 * :shirt: Fix lint issue Co-authored-by: Лебедев Иван <11215636+X-pech@users.noreply.github.com> Co-authored-by: X-pech --- .../nodes/Spotify/GenericFunctions.ts | 2 +- .../nodes-base/nodes/Spotify/Spotify.node.ts | 31 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Spotify/GenericFunctions.ts b/packages/nodes-base/nodes/Spotify/GenericFunctions.ts index e07a6d71df..e4f437275a 100644 --- a/packages/nodes-base/nodes/Spotify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Spotify/GenericFunctions.ts @@ -71,7 +71,7 @@ export async function spotifyApiRequestAllItems(this: IHookFunctions | IExecuteF } } while ( (responseData['next'] !== null && responseData['next'] !== undefined) || - responseData[propertyName.split('.')[0]].next !== null + (responseData[propertyName.split('.')[0]].next !== null && responseData[propertyName.split('.')[0]].next !== undefined) ); return returnData; diff --git a/packages/nodes-base/nodes/Spotify/Spotify.node.ts b/packages/nodes-base/nodes/Spotify/Spotify.node.ts index e896ca83ea..daa913284c 100644 --- a/packages/nodes-base/nodes/Spotify/Spotify.node.ts +++ b/packages/nodes-base/nodes/Spotify/Spotify.node.ts @@ -715,6 +715,7 @@ export class Spotify implements INodeType { 'myData', 'playlist', 'track', + 'player', ], operation: [ 'getTracks', @@ -724,6 +725,7 @@ export class Spotify implements INodeType { 'getLikedTracks', 'getFollowingArtists', 'search', + 'recentlyPlayed', ], }, }, @@ -779,6 +781,9 @@ export class Spotify implements INodeType { 'getFollowingArtists', 'recentlyPlayed', ], + returnAll: [ + false, + ], }, }, typeOptions: { @@ -908,6 +913,7 @@ export class Spotify implements INodeType { endpoint = `/me/player/pause`; + responseData = await spotifyApiRequest.call(this, requestMethod, endpoint, body, qs); responseData = { success: true }; @@ -917,15 +923,22 @@ export class Spotify implements INodeType { endpoint = `/me/player/recently-played`; - const limit = this.getNodeParameter('limit', i) as number; + returnAll = this.getNodeParameter('returnAll', i) as boolean; - qs = { - limit, - }; + propertyName = 'items'; - responseData = await spotifyApiRequest.call(this, requestMethod, endpoint, body, qs); + if (!returnAll) { - responseData = responseData.items; + const limit = this.getNodeParameter('limit', i) as number; + + qs = { + limit, + }; + + responseData = await spotifyApiRequest.call(this, requestMethod, endpoint, body, qs); + + responseData = responseData.items; + } } else if (operation === 'currentlyPlaying') { requestMethod = 'GET'; @@ -1384,8 +1397,14 @@ export class Spotify implements INodeType { endpoint = `/me/following`; + returnAll = this.getNodeParameter('returnAll', i) as boolean; + propertyName = 'artists.items'; + qs = { + type: 'artist', + }; + if (!returnAll) { const limit = this.getNodeParameter('limit', i) as number; qs = {