mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
Refactor resources into resource descriptions
This commit is contained in:
parent
6506937751
commit
05545183da
52
packages/nodes-base/nodes/Reddit/MyAccountDescription.ts
Normal file
52
packages/nodes-base/nodes/Reddit/MyAccountDescription.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const myAccountOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'myAccount',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get identity',
|
||||
value: 'getIdentity',
|
||||
description: 'Return the identity of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get blocked users',
|
||||
value: 'getBlockedUsers',
|
||||
description: 'Return the identity of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get friends',
|
||||
value: 'getFriends',
|
||||
description: 'Return a list of friends for the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get karma',
|
||||
value: 'getKarma',
|
||||
description: 'Return a breakdown of subreddit karma',
|
||||
},
|
||||
{
|
||||
name: 'Get preferences',
|
||||
value: 'getPrefs',
|
||||
description: 'Return the preference settings of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get trophies',
|
||||
value: 'getTrophies',
|
||||
description: 'Return a list of trophies for the logged-in user',
|
||||
},
|
||||
],
|
||||
default: 'getIdentity',
|
||||
description: 'Operation to perform',
|
||||
},
|
||||
] as INodeProperties[];
|
|
@ -14,6 +14,15 @@ import {
|
|||
redditApiRequestAllItems,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
myAccountOperations,
|
||||
} from './MyAccountDescription';
|
||||
|
||||
import {
|
||||
submissionFields,
|
||||
submissionOperations,
|
||||
} from './SubmissionDescription';
|
||||
|
||||
export class Reddit implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Reddit',
|
||||
|
@ -36,9 +45,6 @@ export class Reddit implements INodeType {
|
|||
},
|
||||
],
|
||||
properties: [
|
||||
// ----------------------------------
|
||||
// Resources
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
|
@ -57,223 +63,12 @@ export class Reddit implements INodeType {
|
|||
description: 'Resource to consume',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// My Account operations
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'myAccount',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Get identity',
|
||||
value: 'getIdentity',
|
||||
description: 'Return the identity of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get blocked users',
|
||||
value: 'getBlockedUsers',
|
||||
description: 'Return the identity of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get friends',
|
||||
value: 'getFriends',
|
||||
description: 'Return a list of friends for the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get karma',
|
||||
value: 'getKarma',
|
||||
description: 'Return a breakdown of subreddit karma',
|
||||
},
|
||||
{
|
||||
name: 'Get preferences',
|
||||
value: 'getPrefs',
|
||||
description: 'Return the preference settings of the logged-in user',
|
||||
},
|
||||
{
|
||||
name: 'Get trophies',
|
||||
value: 'getTrophies',
|
||||
description: 'Return a list of trophies for the logged-in user',
|
||||
},
|
||||
],
|
||||
default: 'getIdentity',
|
||||
description: 'Operation to perform',
|
||||
},
|
||||
// myAccount
|
||||
...myAccountOperations,
|
||||
|
||||
// ----------------------------------
|
||||
// Submission operations
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Post',
|
||||
value: 'post',
|
||||
description: 'Post a submission to a subreddit',
|
||||
},
|
||||
],
|
||||
default: 'post',
|
||||
description: 'Operation to perform',
|
||||
},
|
||||
{
|
||||
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',
|
||||
name: 'subreddit',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Subreddit to post the submission to',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Kind',
|
||||
name: 'kind',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text Post',
|
||||
value: 'self',
|
||||
},
|
||||
{
|
||||
name: 'Link Post',
|
||||
value: 'link',
|
||||
},
|
||||
{
|
||||
name: 'Image Post',
|
||||
value: 'image',
|
||||
},
|
||||
{
|
||||
name: 'Video Post',
|
||||
value: 'video',
|
||||
},
|
||||
{
|
||||
name: 'Video GIF Post',
|
||||
value: 'videogif',
|
||||
},
|
||||
],
|
||||
default: 'text',
|
||||
description: 'The kind of the submission to be posted',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'URL',
|
||||
name: 'url',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'URL of the content of the submission',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'link',
|
||||
'image',
|
||||
'video',
|
||||
'videogif',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Text',
|
||||
name: 'text',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Text content of the submission (Markdown supported)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'self',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Resubmit',
|
||||
name: 'resubmit',
|
||||
type: 'boolean',
|
||||
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.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'link',
|
||||
'image',
|
||||
'video',
|
||||
'videogif',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
// submission
|
||||
...submissionFields,
|
||||
...submissionOperations,
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -295,25 +90,17 @@ export class Reddit implements INodeType {
|
|||
responseData = await redditApiRequest.call(this, 'GET', 'me');
|
||||
responseData = responseData.features;
|
||||
|
||||
} else if (operation === 'getBlockedUsers') {
|
||||
} else {
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', 'me/blocked');
|
||||
const endpoints: {[key: string]: string} = {
|
||||
getBlockedUsers: 'blocked',
|
||||
getFriends: 'friends',
|
||||
getKarma: 'karma',
|
||||
getPrefs: 'prefs',
|
||||
getTrophies: 'trophies',
|
||||
};
|
||||
|
||||
} else if (operation === 'getFriends') {
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', 'me/friends');
|
||||
|
||||
} else if (operation === 'getKarma') {
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', 'me/karma');
|
||||
|
||||
} else if (operation === 'getPrefs') {
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', 'me/prefs');
|
||||
|
||||
} else if (operation === 'getTrophies') {
|
||||
|
||||
responseData = await redditApiRequest.call(this, 'GET', 'me/trophies');
|
||||
responseData = await redditApiRequest.call(this, 'GET', `me/${endpoints[operation]}`);
|
||||
|
||||
}
|
||||
|
||||
|
@ -350,4 +137,4 @@ export class Reddit implements INodeType {
|
|||
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
173
packages/nodes-base/nodes/Reddit/SubmissionDescription.ts
Normal file
173
packages/nodes-base/nodes/Reddit/SubmissionDescription.ts
Normal file
|
@ -0,0 +1,173 @@
|
|||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const submissionOperations = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Post',
|
||||
value: 'post',
|
||||
description: 'Post a submission to a subreddit',
|
||||
},
|
||||
],
|
||||
default: 'post',
|
||||
description: 'Operation to perform',
|
||||
},
|
||||
] as INodeProperties[];
|
||||
|
||||
export const submissionFields = [
|
||||
{
|
||||
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',
|
||||
name: 'subreddit',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Subreddit to post the submission to',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Kind',
|
||||
name: 'kind',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Text Post',
|
||||
value: 'self',
|
||||
},
|
||||
{
|
||||
name: 'Link Post',
|
||||
value: 'link',
|
||||
},
|
||||
{
|
||||
name: 'Image Post',
|
||||
value: 'image',
|
||||
},
|
||||
{
|
||||
name: 'Video Post',
|
||||
value: 'video',
|
||||
},
|
||||
{
|
||||
name: 'Video GIF Post',
|
||||
value: 'videogif',
|
||||
},
|
||||
],
|
||||
default: 'text',
|
||||
description: 'The kind of the submission to be posted',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'URL',
|
||||
name: 'url',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'URL of the content of the submission',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'link',
|
||||
'image',
|
||||
'video',
|
||||
'videogif',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Text',
|
||||
name: 'text',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Text content of the submission (Markdown supported)',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'self',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Resubmit',
|
||||
name: 'resubmit',
|
||||
type: 'boolean',
|
||||
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.',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'submission',
|
||||
],
|
||||
operation: [
|
||||
'post',
|
||||
],
|
||||
kind: [
|
||||
'link',
|
||||
'image',
|
||||
'video',
|
||||
'videogif',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
] as INodeProperties[];
|
Loading…
Reference in a new issue