Add listings for specific subreddits

This commit is contained in:
Iván Ovejero 2021-01-17 16:48:50 -03:00
parent dfd29f2e14
commit 272a4fb342
2 changed files with 61 additions and 12 deletions

View file

@ -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[];

View file

@ -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)