mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Add listings for specific subreddits
This commit is contained in:
parent
dfd29f2e14
commit
272a4fb342
|
@ -37,10 +37,32 @@ export const listingFields = [
|
|||
{
|
||||
name: 'Trending',
|
||||
value: 'trending',
|
||||
description: 'Currently trending subreddits',
|
||||
},
|
||||
{
|
||||
name: 'Best',
|
||||
value: 'best',
|
||||
description: 'Top posts in all of Reddit',
|
||||
},
|
||||
{
|
||||
name: 'Top',
|
||||
value: 'top',
|
||||
description: 'Top posts in a specifc subreddit',
|
||||
},
|
||||
{
|
||||
name: 'Hot',
|
||||
value: 'hot',
|
||||
description: 'Hot posts in a specifc subreddit',
|
||||
},
|
||||
{
|
||||
name: 'New',
|
||||
value: 'new',
|
||||
description: 'New posts in a specifc subreddit',
|
||||
},
|
||||
{
|
||||
name: 'Rising',
|
||||
value: 'rising',
|
||||
description: 'Rising posts in a specifc subreddit',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
|
@ -70,6 +92,10 @@ export const listingFields = [
|
|||
],
|
||||
type: [
|
||||
'best',
|
||||
'top',
|
||||
'hot',
|
||||
'new',
|
||||
'rising',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -94,6 +120,10 @@ export const listingFields = [
|
|||
],
|
||||
type: [
|
||||
'best',
|
||||
'top',
|
||||
'hot',
|
||||
'new',
|
||||
'rising',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
|
@ -101,4 +131,28 @@ export const listingFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Subreddit',
|
||||
name: 'subreddit',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'The subreddit to retrieve the listing from',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'listing',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
],
|
||||
type: [
|
||||
'top',
|
||||
'hot',
|
||||
'new',
|
||||
'rising',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
|
|
@ -160,29 +160,24 @@ export class Reddit implements INodeType {
|
|||
const endpoint = 'api/trending_subreddits.json';
|
||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {}, true);
|
||||
|
||||
} else if (type === 'best') {
|
||||
} else {
|
||||
|
||||
const endpoint = type === 'best'
|
||||
? 'best.json'
|
||||
: `r/${this.getNodeParameter('subreddit', i)}/${type}.json`;
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i);
|
||||
|
||||
if (returnAll) {
|
||||
|
||||
const endpoint = 'best.json';
|
||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {}, true);
|
||||
|
||||
} else {
|
||||
|
||||
const qs: IDataObject = {
|
||||
limit: this.getNodeParameter('limit', i),
|
||||
};
|
||||
const endpoint = 'best.json';
|
||||
const qs: IDataObject = { limit: this.getNodeParameter('limit', i) };
|
||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {}, true);
|
||||
responseData = responseData.splice(0, qs.limit);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Array.isArray(responseData)
|
||||
|
|
Loading…
Reference in a new issue