diff --git a/packages/nodes-base/nodes/Reddit/GenericFunctions.ts b/packages/nodes-base/nodes/Reddit/GenericFunctions.ts index 141927f729..8196ecaa2d 100644 --- a/packages/nodes-base/nodes/Reddit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Reddit/GenericFunctions.ts @@ -23,6 +23,7 @@ export async function redditApiRequest( ): Promise { // tslint:disable-line:no-any const resource = this.getNodeParameter('resource', 0) as string; + const authRequired = ['profile', 'post', 'postComment'].includes(resource); const options: OptionsWithUri = { @@ -40,7 +41,7 @@ export async function redditApiRequest( } try { - console.log(options); + // console.log(options); return authRequired ? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options) : await this.helpers.request.call(this, options); @@ -68,16 +69,21 @@ export async function redditApiRequestAllItems( let responseData; const returnData: IDataObject[] = []; + const resource = this.getNodeParameter('resource', 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; + do { - console.log(method); - console.log(endpoint); - console.log(qs); + // console.log(method); + // console.log(endpoint); + // console.log(qs); responseData = await redditApiRequest.call(this, method, endpoint, qs); console.log(responseData); qs.after = responseData.after; if (endpoint === 'api/search_subreddits.json') { responseData.subreddits.forEach((child: any) => returnData.push(child)); // tslint:disable-line:no-any + } else if (resource === 'postComment' && operation === 'getAll') { + responseData[1].data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any } else { responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any } diff --git a/packages/nodes-base/nodes/Reddit/PostCommentDescription.ts b/packages/nodes-base/nodes/Reddit/PostCommentDescription.ts index 00fa59fadb..964aef0997 100644 --- a/packages/nodes-base/nodes/Reddit/PostCommentDescription.ts +++ b/packages/nodes-base/nodes/Reddit/PostCommentDescription.ts @@ -122,6 +122,47 @@ export const postCommentFields = [ }, }, }, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + default: false, + description: 'Return all results.', + displayOptions: { + show: { + resource: [ + 'postComment', + ], + operation: [ + 'getAll', + ], + }, + }, + }, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + default: 5, + description: 'The number of results to return.', + typeOptions: { + minValue: 1, + maxValue: 100, + }, + displayOptions: { + show: { + resource: [ + 'postComment', + ], + operation: [ + 'getAll', + ], + returnAll: [ + false, + ], + }, + }, + }, // ---------------------------------- // postComment: delete // ---------------------------------- diff --git a/packages/nodes-base/nodes/Reddit/PostDescription.ts b/packages/nodes-base/nodes/Reddit/PostDescription.ts index fdd35e6a13..5af1db9651 100644 --- a/packages/nodes-base/nodes/Reddit/PostDescription.ts +++ b/packages/nodes-base/nodes/Reddit/PostDescription.ts @@ -18,7 +18,7 @@ export const postOperations = [ { name: 'Delete', value: 'delete', - description: 'Withdraw a post from a subreddit.', + description: 'Delete a post from a subreddit.', }, { name: 'Get', diff --git a/packages/nodes-base/nodes/Reddit/Reddit.node.ts b/packages/nodes-base/nodes/Reddit/Reddit.node.ts index b816e32a04..ab1ad07333 100644 --- a/packages/nodes-base/nodes/Reddit/Reddit.node.ts +++ b/packages/nodes-base/nodes/Reddit/Reddit.node.ts @@ -96,7 +96,7 @@ export class Reddit implements INodeType { value: 'user', }, ], - default: 'comment', + default: 'post', description: 'Resource to consume', }, ...postCommentOperations, @@ -152,6 +152,7 @@ export class Reddit implements INodeType { } responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs); + delete responseData.jquery; // ---------------------------------- // post: delete @@ -237,8 +238,10 @@ export class Reddit implements INodeType { const postId = this.getNodeParameter('postId', i) as string; const endpoint = `r/${subreddit}/comments/${postId}.json`; - responseData = await redditApiRequest.call(this, 'GET', endpoint, {}); - responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any + responseData = await handleListing.call(this, i, endpoint); + // console.log(responseData); + // responseData = await redditApiRequest.call(this, 'GET', endpoint, {}); + // responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any } else if (operation === 'remove') {