mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Refactor per feedback
This commit is contained in:
parent
04ad3f2b77
commit
0b0213549b
|
@ -1,106 +1,106 @@
|
||||||
import {
|
// import {
|
||||||
INodeProperties,
|
// INodeProperties,
|
||||||
} from 'n8n-workflow';
|
// } from 'n8n-workflow';
|
||||||
|
|
||||||
export const allRedditOperations = [
|
// export const allRedditOperations = [
|
||||||
{
|
// {
|
||||||
displayName: 'Operation',
|
// displayName: 'Operation',
|
||||||
name: 'operation',
|
// name: 'operation',
|
||||||
type: 'options',
|
// type: 'options',
|
||||||
default: 'get',
|
// default: 'get',
|
||||||
description: 'Operation to perform',
|
// description: 'Operation to perform',
|
||||||
options: [
|
// options: [
|
||||||
{
|
// {
|
||||||
name: 'Get',
|
// name: 'Get All',
|
||||||
value: 'get',
|
// value: 'getAll',
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
displayOptions: {
|
// displayOptions: {
|
||||||
show: {
|
// show: {
|
||||||
resource: [
|
// resource: [
|
||||||
'allReddit',
|
// 'allReddit',
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
] as INodeProperties[];
|
// ] as INodeProperties[];
|
||||||
|
|
||||||
export const allRedditFields = [
|
// export const allRedditFields = [
|
||||||
{
|
// {
|
||||||
displayName: 'Information',
|
// displayName: 'Information',
|
||||||
name: 'information',
|
// name: 'information',
|
||||||
type: 'options',
|
// type: 'options',
|
||||||
required: true,
|
// required: true,
|
||||||
default: 'trending',
|
// default: 'trending',
|
||||||
description: 'All-Reddit information to retrieve',
|
// description: 'All-Reddit information to retrieve',
|
||||||
options: [
|
// options: [
|
||||||
{
|
// {
|
||||||
name: 'Trending',
|
// name: 'Trending',
|
||||||
value: 'trending',
|
// value: 'trending',
|
||||||
description: 'Currently trending subreddits',
|
// description: 'Currently trending subreddits',
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
name: 'Best',
|
// name: 'Best',
|
||||||
value: 'best',
|
// value: 'best',
|
||||||
description: 'Top posts in all of Reddit',
|
// description: 'Top posts in all of Reddit',
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
displayOptions: {
|
// displayOptions: {
|
||||||
show: {
|
// show: {
|
||||||
resource: [
|
// resource: [
|
||||||
'allReddit',
|
// 'allReddit',
|
||||||
],
|
// ],
|
||||||
operation: [
|
// operation: [
|
||||||
'get',
|
// 'getAll',
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
displayName: 'Return All',
|
// displayName: 'Return All',
|
||||||
name: 'returnAll',
|
// name: 'returnAll',
|
||||||
type: 'boolean',
|
// type: 'boolean',
|
||||||
default: false,
|
// default: false,
|
||||||
description: 'Return all results',
|
// description: 'Return all results',
|
||||||
displayOptions: {
|
// displayOptions: {
|
||||||
show: {
|
// show: {
|
||||||
resource: [
|
// resource: [
|
||||||
'allReddit',
|
// 'allReddit',
|
||||||
],
|
// ],
|
||||||
operation: [
|
// operation: [
|
||||||
'get',
|
// 'getAll',
|
||||||
],
|
// ],
|
||||||
information: [
|
// information: [
|
||||||
'best',
|
// 'best',
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
displayName: 'Limit',
|
// displayName: 'Limit',
|
||||||
name: 'limit',
|
// name: 'limit',
|
||||||
type: 'number',
|
// type: 'number',
|
||||||
default: 5,
|
// default: 5,
|
||||||
description: 'The number of results to return',
|
// description: 'The number of results to return',
|
||||||
typeOptions: {
|
// typeOptions: {
|
||||||
minValue: 1,
|
// minValue: 1,
|
||||||
maxValue: 100,
|
// maxValue: 100,
|
||||||
},
|
// },
|
||||||
displayOptions: {
|
// displayOptions: {
|
||||||
show: {
|
// show: {
|
||||||
resource: [
|
// resource: [
|
||||||
'allReddit',
|
// 'allReddit',
|
||||||
],
|
// ],
|
||||||
operation: [
|
// operation: [
|
||||||
'get',
|
// 'getAll',
|
||||||
],
|
// ],
|
||||||
information: [
|
// information: [
|
||||||
'best',
|
// 'best',
|
||||||
],
|
// ],
|
||||||
returnAll: [
|
// returnAll: [
|
||||||
false,
|
// false,
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
] as INodeProperties[];
|
// ] as INodeProperties[];
|
||||||
|
|
68
packages/nodes-base/nodes/Reddit/CommentDescription.ts
Normal file
68
packages/nodes-base/nodes/Reddit/CommentDescription.ts
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
import {
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const commentOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
default: 'create',
|
||||||
|
description: 'Operation to perform',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Create',
|
||||||
|
value: 'create',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'comment',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const commentFields = [
|
||||||
|
// ----------------------------------
|
||||||
|
// comment: create
|
||||||
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Target',
|
||||||
|
name: 'target',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'ID of the comment target',
|
||||||
|
placeholder: 't3_15bfi0',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'comment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Text',
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'Text of the comment (Markdown supported)',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'comment',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
|
@ -20,35 +20,27 @@ export async function redditApiRequest(
|
||||||
method: string,
|
method: string,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
qs: IDataObject,
|
qs: IDataObject,
|
||||||
body: IDataObject,
|
|
||||||
): 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 operation = this.getNodeParameter('operation', 0) as string;
|
const authRequired = ['profile', 'post', 'comment'].includes(resource);
|
||||||
const requiresAuth = resource === 'myAccount' ||
|
|
||||||
(resource === 'submission' && ['post', 'comment'].includes(operation));
|
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'user-agent': 'n8n',
|
'user-agent': 'n8n',
|
||||||
},
|
},
|
||||||
method,
|
method,
|
||||||
uri: requiresAuth ? `https://oauth.reddit.com/${endpoint}` : `https://www.reddit.com/${endpoint}`,
|
uri: authRequired ? `https://oauth.reddit.com/${endpoint}` : `https://www.reddit.com/${endpoint}`,
|
||||||
qs,
|
qs,
|
||||||
body,
|
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Object.keys(body).length) {
|
|
||||||
delete options.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Object.keys(qs).length) {
|
if (!Object.keys(qs).length) {
|
||||||
delete options.qs;
|
delete options.qs;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return requiresAuth
|
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);
|
||||||
|
|
||||||
|
@ -70,16 +62,24 @@ export async function redditApiRequestAllItems(
|
||||||
method: string,
|
method: string,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
qs: IDataObject,
|
qs: IDataObject,
|
||||||
body: IDataObject,
|
|
||||||
): Promise<any> { // tslint:disable-line:no-any
|
): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
responseData = await redditApiRequest.call(this, method, endpoint, qs, body);
|
console.log(method);
|
||||||
|
console.log(endpoint);
|
||||||
|
console.log(qs);
|
||||||
|
responseData = await redditApiRequest.call(this, method, endpoint, qs);
|
||||||
|
console.log(responseData);
|
||||||
qs.after = responseData.after;
|
qs.after = responseData.after;
|
||||||
|
|
||||||
|
if (endpoint === 'api/search_reddit_names.json') {
|
||||||
|
responseData.names.forEach((name: IDataObject) => returnData.push(name));
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
|
||||||
if (qs.limit && returnData.length >= qs.limit) {
|
if (qs.limit && returnData.length >= qs.limit) {
|
||||||
return returnData;
|
return returnData;
|
||||||
|
@ -98,18 +98,30 @@ export async function handleListing(
|
||||||
i: number,
|
i: number,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
): Promise<any> { // tslint:disable-line:no-any
|
): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
let responseData;
|
let responseData;
|
||||||
|
|
||||||
const returnAll = this.getNodeParameter('returnAll', i);
|
const resource = this.getNodeParameter('resource', 0);
|
||||||
if (returnAll) {
|
const operation = this.getNodeParameter('operation', 0);
|
||||||
return await redditApiRequestAllItems.call(this, 'GET', endpoint, {}, {});
|
|
||||||
|
const qs: IDataObject = {};
|
||||||
|
|
||||||
|
if (resource === 'subreddit' && operation === 'getAll') {
|
||||||
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||||
|
if (filters.query) {
|
||||||
|
qs.query = filters.query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const qs: IDataObject = {
|
const returnAll = this.getNodeParameter('returnAll', i);
|
||||||
limit: this.getNodeParameter('limit', i),
|
|
||||||
};
|
if (returnAll) {
|
||||||
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs, {});
|
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
|
||||||
|
} else {
|
||||||
|
qs.limit = this.getNodeParameter('limit', i);
|
||||||
|
responseData = await redditApiRequestAllItems.call(this, 'GET', endpoint, qs);
|
||||||
responseData = responseData.splice(0, qs.limit);
|
responseData = responseData.splice(0, qs.limit);
|
||||||
|
}
|
||||||
|
|
||||||
return responseData;
|
return responseData;
|
||||||
}
|
}
|
|
@ -2,76 +2,51 @@ import {
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const submissionOperations = [
|
export const postOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
default: 'post',
|
default: 'create',
|
||||||
description: 'Operation to perform',
|
description: 'Operation to perform',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Post',
|
name: 'Create',
|
||||||
value: 'post',
|
value: 'create',
|
||||||
description: 'Post a submission to a subreddit',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Comment',
|
name: 'Get All',
|
||||||
value: 'comment',
|
value: 'getAll',
|
||||||
description: 'Comment on a submission in a subreddit',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Search',
|
|
||||||
value: 'search',
|
|
||||||
description: 'Search for a submission in a subreddit',
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
export const submissionFields = [
|
export const postFields = [
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// post submission
|
// post: create
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
|
||||||
displayName: 'Title',
|
|
||||||
name: 'title',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
default: '',
|
|
||||||
description: 'Title of the submission, up to 300 characters long',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'submission',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'post',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Subreddit',
|
displayName: 'Subreddit',
|
||||||
name: 'subreddit',
|
name: 'subreddit',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Subreddit to post the submission to',
|
description: 'Subreddit to create the post in',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'post',
|
'create',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -103,15 +78,33 @@ export const submissionFields = [
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'self',
|
default: 'self',
|
||||||
description: 'The kind of the submission to be posted',
|
description: 'The kind of the post to create',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Title',
|
||||||
|
name: 'title',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'Title of the post, up to 300 characters long',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
'post',
|
'post',
|
||||||
],
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -121,14 +114,14 @@ export const submissionFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'URL of the content of the submission',
|
description: 'URL of the post',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'post',
|
'create',
|
||||||
],
|
],
|
||||||
kind: [
|
kind: [
|
||||||
'link',
|
'link',
|
||||||
|
@ -145,14 +138,14 @@ export const submissionFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Text content of the submission (Markdown supported)',
|
description: 'Text of the post (Markdown supported)',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'post',
|
'create',
|
||||||
],
|
],
|
||||||
kind: [
|
kind: [
|
||||||
'self',
|
'self',
|
||||||
|
@ -165,14 +158,14 @@ export const submissionFields = [
|
||||||
name: 'resubmit',
|
name: 'resubmit',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'If toggled on, the URL will be submitted even if<br>it was already submitted to the subreddit before.<br>Otherwise, a resubmission will trigger an error.',
|
description: 'If toggled on, the URL will be posted even if<br>it was already posted to the subreddit before.<br>Otherwise, the re-posting will trigger an error.',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'post',
|
'create',
|
||||||
],
|
],
|
||||||
kind: [
|
kind: [
|
||||||
'link',
|
'link',
|
||||||
|
@ -184,79 +177,128 @@ export const submissionFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// comment on submission
|
// post: getAll
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Target',
|
displayName: 'Best',
|
||||||
name: 'target',
|
name: 'best',
|
||||||
type: 'string',
|
type: 'boolean',
|
||||||
default: '',
|
default: false,
|
||||||
description: 'ID of the target of the comment. The target can be either<br>the top-level submission or a reply in that submission.',
|
description: 'Best posts in all of Reddit',
|
||||||
placeholder: 't3_15bfi0',
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'comment',
|
'getAll',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Text',
|
|
||||||
name: 'text',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
default: '',
|
|
||||||
description: 'Text content of the comment (Markdown supported)',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'submission',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'comment',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// ----------------------------------
|
|
||||||
// search for submission
|
|
||||||
// ----------------------------------
|
|
||||||
{
|
{
|
||||||
displayName: 'Subreddit',
|
displayName: 'Subreddit',
|
||||||
name: 'subreddit',
|
name: 'subreddit',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Subreddit to search for posts',
|
description: 'The name of subreddit to retrieve the posts from',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'search',
|
'getAll',
|
||||||
|
],
|
||||||
|
best: [
|
||||||
|
false,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Keyword',
|
displayName: 'Content',
|
||||||
name: 'keyword',
|
name: 'content',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
required: true,
|
required: true,
|
||||||
default: '',
|
default: 'top',
|
||||||
description: 'The keyword for the subreddit post search',
|
description: 'Content of posts to retrieve',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Top Posts',
|
||||||
|
value: 'top',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Hot Posts',
|
||||||
|
value: 'hot',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'New Posts',
|
||||||
|
value: 'new',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Rising Posts',
|
||||||
|
value: 'rising',
|
||||||
|
},
|
||||||
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'submission',
|
'post',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'search',
|
'getAll',
|
||||||
|
],
|
||||||
|
best: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Return all results',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'post',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
best: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
default: 5,
|
||||||
|
description: 'The number of results to return',
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'post',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
best: [
|
||||||
|
false,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
|
@ -2,7 +2,7 @@ import {
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export const myAccountOperations = [
|
export const profileOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
|
@ -10,7 +10,7 @@ export const myAccountOperations = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'myAccount',
|
'profile',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -26,7 +26,7 @@ export const myAccountOperations = [
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
|
||||||
export const myAccountFields = [
|
export const profileFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Details',
|
displayName: 'Details',
|
||||||
name: 'details',
|
name: 'details',
|
||||||
|
@ -69,7 +69,7 @@ export const myAccountFields = [
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'myAccount',
|
'profile',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'get',
|
'get',
|
|
@ -15,19 +15,19 @@ import {
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
allRedditFields,
|
commentFields,
|
||||||
allRedditOperations,
|
commentOperations,
|
||||||
} from './AllRedditDescription';
|
} from './CommentDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
myAccountFields,
|
postFields,
|
||||||
myAccountOperations,
|
postOperations,
|
||||||
} from './MyAccountDescription';
|
} from './PostDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
submissionFields,
|
profileFields,
|
||||||
submissionOperations,
|
profileOperations,
|
||||||
} from './SubmissionDescription';
|
} from './ProfileDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
subredditFields,
|
subredditFields,
|
||||||
|
@ -61,13 +61,9 @@ export class Reddit implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'myAccount',
|
'profile',
|
||||||
'submission',
|
'comment',
|
||||||
],
|
'post',
|
||||||
},
|
|
||||||
hide: {
|
|
||||||
operation: [
|
|
||||||
'search',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -80,16 +76,16 @@ export class Reddit implements INodeType {
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'All Reddit',
|
name: 'Comment',
|
||||||
value: 'allReddit',
|
value: 'comment',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'My Account',
|
name: 'Post',
|
||||||
value: 'myAccount',
|
value: 'post',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Submission',
|
name: 'Profile',
|
||||||
value: 'submission',
|
value: 'profile',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Subreddit',
|
name: 'Subreddit',
|
||||||
|
@ -100,27 +96,17 @@ export class Reddit implements INodeType {
|
||||||
value: 'user',
|
value: 'user',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'myAccount',
|
default: 'comment',
|
||||||
description: 'Resource to consume',
|
description: 'Resource to consume',
|
||||||
},
|
},
|
||||||
|
...commentOperations,
|
||||||
// allReddit
|
...commentFields,
|
||||||
...allRedditOperations,
|
...profileOperations,
|
||||||
...allRedditFields,
|
...profileFields,
|
||||||
|
|
||||||
// myAccount
|
|
||||||
...myAccountOperations,
|
|
||||||
...myAccountFields,
|
|
||||||
|
|
||||||
// submission
|
|
||||||
...submissionOperations,
|
|
||||||
...submissionFields,
|
|
||||||
|
|
||||||
// subreddit
|
|
||||||
...subredditOperations,
|
...subredditOperations,
|
||||||
...subredditFields,
|
...subredditFields,
|
||||||
|
...postOperations,
|
||||||
// user
|
...postFields,
|
||||||
...userOperations,
|
...userOperations,
|
||||||
...userFields,
|
...userFields,
|
||||||
],
|
],
|
||||||
|
@ -137,33 +123,23 @@ export class Reddit implements INodeType {
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
if (resource === 'allReddit') {
|
if (resource === 'comment') {
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// allReddit: get
|
// comment: create
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
if (operation === 'get') {
|
const qs: IDataObject = {
|
||||||
|
thing_id: this.getNodeParameter('target', i),
|
||||||
|
text: this.getNodeParameter('text', i),
|
||||||
|
};
|
||||||
|
|
||||||
const information = this.getNodeParameter('information', i) as string;
|
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs);
|
||||||
|
|
||||||
if (information === 'trending') {
|
} else if (resource === 'profile') {
|
||||||
|
|
||||||
const endpoint = 'api/trending_subreddits.json';
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, {}, {});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
const endpoint = 'best.json';
|
|
||||||
responseData = await handleListing.call(this, i, endpoint);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (resource === 'myAccount') {
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// myAccount: get
|
// profile: get
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
|
@ -178,7 +154,8 @@ export class Reddit implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
const details = this.getNodeParameter('details', i) as string;
|
const details = this.getNodeParameter('details', i) as string;
|
||||||
responseData = await redditApiRequest.call(this, 'GET', `api/v1/${endpoints[details]}`, {}, {});
|
const endpoint = `api/v1/${endpoints[details]}`;
|
||||||
|
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
if (details === 'identity') {
|
if (details === 'identity') {
|
||||||
responseData = responseData.features;
|
responseData = responseData.features;
|
||||||
|
@ -186,13 +163,50 @@ export class Reddit implements INodeType {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (resource === 'submission') {
|
} else if (resource === 'subreddit') {
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// submission: post
|
// subreddit: get
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
if (operation === 'post') {
|
if (operation === 'get') {
|
||||||
|
|
||||||
|
const qs: IDataObject = {};
|
||||||
|
|
||||||
|
const subreddit = this.getNodeParameter('subreddit', i);
|
||||||
|
const content = this.getNodeParameter('content', i) as string;
|
||||||
|
const endpoint = `r/${subreddit}/about/${content}.json`;
|
||||||
|
|
||||||
|
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs);
|
||||||
|
|
||||||
|
if (content === 'rules') {
|
||||||
|
responseData = responseData.rules;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// subreddit: getAll
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
} else if (operation === 'getAll') {
|
||||||
|
|
||||||
|
const trending = this.getNodeParameter('trending', i) as IDataObject;
|
||||||
|
|
||||||
|
if (trending) {
|
||||||
|
const endpoint = 'api/trending_subreddits.json';
|
||||||
|
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
} else {
|
||||||
|
const endpoint = 'api/search_reddit_names.json';
|
||||||
|
responseData = await handleListing.call(this, i, endpoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (resource === 'post') {
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// post: create
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
if (operation === 'create') {
|
||||||
|
|
||||||
const qs: IDataObject = {
|
const qs: IDataObject = {
|
||||||
title: this.getNodeParameter('title', i),
|
title: this.getNodeParameter('title', i),
|
||||||
|
@ -208,76 +222,24 @@ export class Reddit implements INodeType {
|
||||||
qs.resubmit = this.getNodeParameter('resubmit', i);
|
qs.resubmit = this.getNodeParameter('resubmit', i);
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs, {});
|
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs);
|
||||||
|
|
||||||
// ----------------------------------
|
|
||||||
// submission: comment
|
|
||||||
// ----------------------------------
|
|
||||||
|
|
||||||
} else if (operation === 'comment') {
|
|
||||||
|
|
||||||
const qs: IDataObject = {
|
|
||||||
thing_id: this.getNodeParameter('target', i),
|
|
||||||
text: this.getNodeParameter('text', i),
|
|
||||||
};
|
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'POST', 'api/comment', qs, {});
|
|
||||||
|
|
||||||
} else if (operation === 'search') {
|
|
||||||
|
|
||||||
const subreddit = this.getNodeParameter('subreddit', i);
|
|
||||||
|
|
||||||
const qs: IDataObject = {
|
|
||||||
q: this.getNodeParameter('keyword', i),
|
|
||||||
restrict_sr: 'on',
|
|
||||||
};
|
|
||||||
|
|
||||||
const endpoint = `r/${subreddit}/search.json`;
|
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (resource === 'subreddit') {
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// subreddit: get
|
// post: getAll
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
if (operation === 'get') {
|
else if (operation === 'getAll') {
|
||||||
|
|
||||||
const qs: IDataObject = {};
|
|
||||||
|
|
||||||
const content = this.getNodeParameter('content', i) as string;
|
|
||||||
const subreddit = this.getNodeParameter('subreddit', i);
|
const subreddit = this.getNodeParameter('subreddit', i);
|
||||||
|
const content = this.getNodeParameter('content', i);
|
||||||
if (['about', 'rules', 'sidebar', 'sticky'].includes(content)) {
|
|
||||||
|
|
||||||
const endpoint = `r/${subreddit}/about/${content}.json`;
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
|
|
||||||
|
|
||||||
if (content === 'rules') {
|
|
||||||
responseData = responseData.rules;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (['top', 'hot', 'new', 'rising'].includes(content)) {
|
|
||||||
|
|
||||||
const endpoint = `r/${subreddit}/${content}.json`;
|
const endpoint = `r/${subreddit}/${content}.json`;
|
||||||
|
|
||||||
responseData = await handleListing.call(this, i, endpoint);
|
responseData = await handleListing.call(this, i, endpoint);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (operation === 'search') {
|
|
||||||
|
|
||||||
const endpoint = `api/search_reddit_names.json`;
|
|
||||||
const qs: IDataObject = {
|
|
||||||
query: this.getNodeParameter('keyword', i),
|
|
||||||
};
|
|
||||||
|
|
||||||
responseData = await redditApiRequest.call(this, 'GET', endpoint, qs, {});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (resource === 'user') {
|
} else if (resource === 'user') {
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -291,7 +253,7 @@ export class Reddit implements INodeType {
|
||||||
const endpoint = `user/${username}/${details}.json`;
|
const endpoint = `user/${username}/${details}.json`;
|
||||||
|
|
||||||
responseData = ['about', 'gilded'].includes(details)
|
responseData = ['about', 'gilded'].includes(details)
|
||||||
? await redditApiRequest.call(this, 'GET', endpoint, {}, {})
|
? await redditApiRequest.call(this, 'GET', endpoint, {})
|
||||||
: await handleListing.call(this, i, endpoint);
|
: await handleListing.call(this, i, endpoint);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ export const subredditOperations = [
|
||||||
value: 'get',
|
value: 'get',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Search',
|
name: 'Get All',
|
||||||
value: 'search',
|
value: 'getAll',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
|
@ -31,7 +31,7 @@ export const subredditOperations = [
|
||||||
|
|
||||||
export const subredditFields = [
|
export const subredditFields = [
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// get: subreddit
|
// subreddit: get
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Content',
|
displayName: 'Content',
|
||||||
|
@ -57,22 +57,6 @@ export const subredditFields = [
|
||||||
name: 'Sticky Posts',
|
name: 'Sticky Posts',
|
||||||
value: 'sticky',
|
value: 'sticky',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Top Posts',
|
|
||||||
value: 'top',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Hot Posts',
|
|
||||||
value: 'hot',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'New Posts',
|
|
||||||
value: 'new',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Rising Posts',
|
|
||||||
value: 'rising',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
@ -117,12 +101,6 @@ export const subredditFields = [
|
||||||
operation: [
|
operation: [
|
||||||
'get',
|
'get',
|
||||||
],
|
],
|
||||||
content: [
|
|
||||||
'top',
|
|
||||||
'hot',
|
|
||||||
'new',
|
|
||||||
'rising',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -144,12 +122,6 @@ export const subredditFields = [
|
||||||
operation: [
|
operation: [
|
||||||
'get',
|
'get',
|
||||||
],
|
],
|
||||||
content: [
|
|
||||||
'top',
|
|
||||||
'hot',
|
|
||||||
'new',
|
|
||||||
'rising',
|
|
||||||
],
|
|
||||||
returnAll: [
|
returnAll: [
|
||||||
false,
|
false,
|
||||||
],
|
],
|
||||||
|
@ -157,22 +129,21 @@ export const subredditFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// search: subreddit
|
// subreddit: getAll
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'Keyword',
|
displayName: 'Trending',
|
||||||
name: 'keyword',
|
name: 'trending',
|
||||||
type: 'string',
|
type: 'boolean',
|
||||||
required: true,
|
default: false,
|
||||||
default: '',
|
description: 'Currently trending subreddits in all of Reddit',
|
||||||
description: 'The keyword for the subreddit name search',
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'subreddit',
|
'subreddit',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'search',
|
'getAll',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -189,7 +160,10 @@ export const subredditFields = [
|
||||||
'subreddit',
|
'subreddit',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'search',
|
'getAll',
|
||||||
|
],
|
||||||
|
trending: [
|
||||||
|
false,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -210,11 +184,43 @@ export const subredditFields = [
|
||||||
'subreddit',
|
'subreddit',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'search',
|
'getAll',
|
||||||
],
|
],
|
||||||
returnAll: [
|
returnAll: [
|
||||||
false,
|
false,
|
||||||
],
|
],
|
||||||
|
trending: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Filters',
|
||||||
|
name: 'filters',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Query',
|
||||||
|
name: 'query',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'The term for the subreddit name search',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'subreddit',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
trending: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue