Fix pagination to enforce limit

This commit is contained in:
Iván Ovejero 2021-02-01 16:06:10 -03:00
parent 52dd2502fd
commit 72548d9523
2 changed files with 6 additions and 6 deletions

View file

@ -83,8 +83,6 @@ export async function redditApiRequestAllItems(
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
qs.limit = 100;
do { do {
responseData = await redditApiRequest.call(this, method, endpoint, qs); responseData = await redditApiRequest.call(this, method, endpoint, qs);
if (!Array.isArray(responseData)) { if (!Array.isArray(responseData)) {
@ -99,6 +97,10 @@ export async function redditApiRequestAllItems(
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
} }
if (qs.limit && responseData.data.children.length >= qs.limit) {
return returnData;
}
} while (responseData.data && responseData.data.after); } while (responseData.data && responseData.data.after);
return returnData; return returnData;

View file

@ -402,13 +402,11 @@ export class Reddit implements INodeType {
const details = this.getNodeParameter('details', i) as string; const details = this.getNodeParameter('details', i) as string;
const endpoint = `user/${username}/${details}.json`; const endpoint = `user/${username}/${details}.json`;
responseData = ['about', 'gilded'].includes(details) responseData = details === 'about'
? await redditApiRequest.call(this, 'GET', endpoint, {}) ? await redditApiRequest.call(this, 'GET', endpoint, {})
: await handleListing.call(this, i, endpoint); : await handleListing.call(this, i, endpoint);
if (details === 'gilded') { if (details === 'about') {
responseData = responseData.data.children;
} else if (details === 'about') {
responseData = responseData.data; responseData = responseData.data;
} }
} }