Skip to content

Commit 9a8a51e

Browse files
feat(reddit): add reddit_subreddit target
feat(reddit): add reddit_subreddit target
2 parents 6e43031 + 841bba5 commit 9a8a51e

File tree

9 files changed

+74
-3
lines changed

9 files changed

+74
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Scrape Wikipedia and tell me who won the NBA in 2025.
9494

9595
## Parameters
9696

97-
When used as an AI tool, the following parameters are inferred automatically from messages:
97+
When used as an AI tool, most parameters can be inferred automatically from messages, for example:
9898

9999
| Parameter | Description | Example message |
100100
| ---------- | ---------------------------------------------- | ----------------------------------------------------------------------- |
@@ -103,7 +103,7 @@ When used as an AI tool, the following parameters are inferred automatically fro
103103
| `geo` | The country name from which to scrape | Scrape https://ip.decodo.com/json with United States geolocation. |
104104
| `markdown` | Receive Markdown type responce instead of HTML | Scrape https://ip.decodo.com/json and return result in markdown format. |
105105

106-
If used as an individual node, these parameters can be manually configured by double-clicking on the node.
106+
If used as an individual node, all parameters can be manually configured by double-clicking on the node.
107107

108108
## Development & releases
109109

nodes/Decodo/constants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ export enum TARGET {
33
GOOGLE_SEARCH = 'google_search',
44
AMAZON = 'amazon',
55
YOUTUBE_TRANSCRIPT = 'youtube_transcript',
6+
REDDIT_SUBDREDDIT = 'reddit_subreddit',
67
}
78

89
export const URL_TARGETS = [TARGET.UNIVERSAL, TARGET.AMAZON];
910
export const QUERY_TARGETS = [TARGET.GOOGLE_SEARCH];
1011
export const HEADLESS_TARGETS = [TARGET.UNIVERSAL, TARGET.GOOGLE_SEARCH];
11-
export const GEO_TARGETS = [TARGET.UNIVERSAL, TARGET.GOOGLE_SEARCH, TARGET.AMAZON];
12+
export const GEO_TARGETS = [
13+
TARGET.UNIVERSAL,
14+
TARGET.GOOGLE_SEARCH,
15+
TARGET.AMAZON,
16+
TARGET.REDDIT_SUBDREDDIT,
17+
];
1218
export const LOCALE_TARGETS = [TARGET.GOOGLE_SEARCH];
1319
export const MARKDOWN_TARGETS = [TARGET.UNIVERSAL, TARGET.GOOGLE_SEARCH];
1420
export const PARSE_TARGETS = [TARGET.GOOGLE_SEARCH, TARGET.AMAZON];

nodes/Decodo/properties/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export * from './limit.property';
1010
export * from './markdown.property';
1111
export * from './transcript-origin.property';
1212
export * from './language-code.property';
13+
export * from './subreddit.property';
14+
export * from './reddit-sort.property';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { INodeProperties } from 'n8n-workflow';
2+
import { TARGET } from '../constants';
3+
4+
export class RedditSortProperty {
5+
static property = {
6+
displayName: 'Sort',
7+
name: 'reddit_sort',
8+
description: 'How to sort the posts of the chosen subreddit',
9+
type: 'options',
10+
default: '',
11+
required: false,
12+
options: [
13+
{ name: 'Best', value: 'best' },
14+
{ name: 'Default', value: '' },
15+
{ name: 'Hot', value: 'hot' },
16+
{ name: 'New', value: 'new' },
17+
{ name: 'Rising', value: 'rising' },
18+
{ name: 'Top', value: 'top' },
19+
],
20+
displayOptions: { show: { target: [TARGET.REDDIT_SUBDREDDIT] } },
21+
} satisfies INodeProperties;
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { INodeProperties } from 'n8n-workflow';
2+
import { TARGET } from '../constants';
3+
4+
export class SubredditProperty {
5+
static property = {
6+
displayName: 'Subreddit',
7+
name: 'subreddit',
8+
description: "Name of the subreddit, example: 'nba'",
9+
type: 'string',
10+
default: '',
11+
required: true,
12+
displayOptions: {
13+
show: { target: [TARGET.REDDIT_SUBDREDDIT] },
14+
},
15+
} satisfies INodeProperties;
16+
}

nodes/Decodo/properties/target.property.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class TargetProperty {
2727
name: 'Youtube Transcript',
2828
value: TARGET.YOUTUBE_TRANSCRIPT,
2929
},
30+
{
31+
name: 'Reddit Subreddit',
32+
value: TARGET.REDDIT_SUBDREDDIT,
33+
},
3034
],
3135
} satisfies INodeProperties;
3236
}

nodes/Decodo/services/parameter-transformer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { INodeProperties } from 'n8n-workflow';
22
import { ScraperApiParams } from '../types';
3+
import { Utils } from './utils';
34
import {
45
TargetProperty,
56
UrlProperty,
@@ -13,6 +14,8 @@ import {
1314
VideoIdProperty,
1415
TranscriptOriginProperty,
1516
LanguageCodeProperty,
17+
SubredditProperty,
18+
RedditSortProperty,
1619
} from '../properties';
1720

1821
export class PropertyHandler {
@@ -21,6 +24,7 @@ export class PropertyHandler {
2124
UrlProperty.property,
2225
QueryProperty.property,
2326
VideoIdProperty.property,
27+
SubredditProperty.property,
2428
HeadlessProperty.property,
2529
ParseProperty.property,
2630
TranscriptOriginProperty.property,
@@ -29,6 +33,7 @@ export class PropertyHandler {
2933
LocaleProperty.property,
3034
LimitProperty.property,
3135
MarkdownProperty.property,
36+
RedditSortProperty.property,
3237
];
3338

3439
static getParameters = (
@@ -49,6 +54,7 @@ export class PropertyHandler {
4954
return {
5055
target: params.target,
5156
...(params.url && { url: params.url }),
57+
...(params.subreddit && { url: Utils.getSubredditUrl(params.subreddit, params.reddit_sort) }),
5258
...(params.query && { query: params.query }),
5359
...(params.video_id && { query: params.video_id }),
5460
...(params.headless && { headless: 'html' }),

nodes/Decodo/services/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { RedditSort } from '../types';
2+
3+
export class Utils {
4+
static getSubredditUrl = (subreddit: string, sort?: RedditSort) => {
5+
const baseUrl = `https://www.reddit.com/r/${subreddit}`;
6+
if (sort) {
7+
return `${baseUrl}/${sort}`;
8+
}
9+
return baseUrl;
10+
};
11+
}

nodes/Decodo/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { TARGET } from './constants';
22

3+
export type RedditSort = 'best' | 'hot' | 'new' | 'rising' | 'top';
4+
35
export type ScraperApiParams = {
46
target?: TARGET;
57
url?: string;
@@ -13,4 +15,6 @@ export type ScraperApiParams = {
1315
language_code?: string;
1416
results_limit?: string;
1517
markdown?: boolean;
18+
subreddit?: string;
19+
reddit_sort?: RedditSort;
1620
};

0 commit comments

Comments
 (0)