Spotify improvements (#1884)

* Add search resource

* Add resume, volume functions to player resource

*  Improvements to #1870

*  Improvements

*  Minor improvements

Co-authored-by: smamudhan <sm.amudhan@live.com>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza
2021-06-18 17:41:57 -04:00
committed by GitHub
parent a49624a17c
commit 8c693ba6e3
2 changed files with 310 additions and 11 deletions

View File

@@ -13,6 +13,10 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
get,
} from 'lodash';
/**
* Make an API request to Spotify
*
@@ -40,7 +44,6 @@ export async function spotifyApiRequest(this: IHookFunctions | IExecuteFunctions
if (Object.keys(body).length > 0) {
options.body = body;
}
try {
return await this.helpers.requestOAuth2.call(this, 'spotifyOAuth2Api', options);
} catch (error) {
@@ -59,11 +62,16 @@ export async function spotifyApiRequestAllItems(this: IHookFunctions | IExecuteF
do {
responseData = await spotifyApiRequest.call(this, method, endpoint, body, query, uri);
returnData.push.apply(returnData, responseData[propertyName]);
uri = responseData.next;
returnData.push.apply(returnData, get(responseData, propertyName));
uri = responseData.next || responseData[propertyName.split('.')[0]].next;
//remove the query as the query parameters are already included in the next, else api throws error.
query = {};
if (uri?.includes('offset=1000')) {
return returnData;
}
} while (
responseData['next'] !== null
(responseData['next'] !== null && responseData['next'] !== undefined) ||
responseData[propertyName.split('.')[0]].next !== null
);
return returnData;