mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Fix postComment:getAll
This commit is contained in:
parent
19d11664e6
commit
3545303a3b
|
@ -23,6 +23,7 @@ export async function redditApiRequest(
|
||||||
): Promise<any> { // tslint:disable-line:no-any
|
): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
|
||||||
const authRequired = ['profile', 'post', 'postComment'].includes(resource);
|
const authRequired = ['profile', 'post', 'postComment'].includes(resource);
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
|
@ -40,7 +41,7 @@ export async function redditApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(options);
|
// console.log(options);
|
||||||
return authRequired
|
return authRequired
|
||||||
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
|
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
|
||||||
: await this.helpers.request.call(this, options);
|
: await this.helpers.request.call(this, options);
|
||||||
|
@ -68,16 +69,21 @@ export async function redditApiRequestAllItems(
|
||||||
let responseData;
|
let responseData;
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
console.log(method);
|
// console.log(method);
|
||||||
console.log(endpoint);
|
// console.log(endpoint);
|
||||||
console.log(qs);
|
// console.log(qs);
|
||||||
responseData = await redditApiRequest.call(this, method, endpoint, qs);
|
responseData = await redditApiRequest.call(this, method, endpoint, qs);
|
||||||
console.log(responseData);
|
console.log(responseData);
|
||||||
qs.after = responseData.after;
|
qs.after = responseData.after;
|
||||||
|
|
||||||
if (endpoint === 'api/search_subreddits.json') {
|
if (endpoint === 'api/search_subreddits.json') {
|
||||||
responseData.subreddits.forEach((child: any) => returnData.push(child)); // tslint:disable-line:no-any
|
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 {
|
} else {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// postComment: delete
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const postOperations = [
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Delete',
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
description: 'Withdraw a post from a subreddit.',
|
description: 'Delete a post from a subreddit.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get',
|
name: 'Get',
|
||||||
|
|
|
@ -96,7 +96,7 @@ export class Reddit implements INodeType {
|
||||||
value: 'user',
|
value: 'user',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'comment',
|
default: 'post',
|
||||||
description: 'Resource to consume',
|
description: 'Resource to consume',
|
||||||
},
|
},
|
||||||
...postCommentOperations,
|
...postCommentOperations,
|
||||||
|
@ -152,6 +152,7 @@ export class Reddit implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs);
|
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs);
|
||||||
|
delete responseData.jquery;
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// post: delete
|
// post: delete
|
||||||
|
@ -237,8 +238,10 @@ export class Reddit implements INodeType {
|
||||||
const postId = this.getNodeParameter('postId', i) as string;
|
const postId = this.getNodeParameter('postId', i) as string;
|
||||||
const endpoint = `r/${subreddit}/comments/${postId}.json`;
|
const endpoint = `r/${subreddit}/comments/${postId}.json`;
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
responseData = await handleListing.call(this, i, endpoint);
|
||||||
responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any
|
// 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') {
|
} else if (operation === 'remove') {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue