mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Small adjustment to HN-Node
This commit is contained in:
parent
c5bd303076
commit
687f608714
|
@ -38,6 +38,10 @@ export class HackerNews implements INodeType {
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'All',
|
||||||
|
value: 'all',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Article',
|
name: 'Article',
|
||||||
value: 'article',
|
value: 'article',
|
||||||
|
@ -50,9 +54,32 @@ export class HackerNews implements INodeType {
|
||||||
default: 'article',
|
default: 'article',
|
||||||
description: 'Resource to consume.',
|
description: 'Resource to consume.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// Operations
|
// Operations
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'all',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all items',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getAll',
|
||||||
|
description: 'Operation to perform.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
|
@ -70,11 +97,6 @@ export class HackerNews implements INodeType {
|
||||||
value: 'get',
|
value: 'get',
|
||||||
description: 'Get a Hacker News article',
|
description: 'Get a Hacker News article',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Get All',
|
|
||||||
value: 'getAll',
|
|
||||||
description: 'Get all Hacker News articles',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
default: 'get',
|
default: 'get',
|
||||||
description: 'Operation to perform.',
|
description: 'Operation to perform.',
|
||||||
|
@ -148,7 +170,7 @@ export class HackerNews implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'article',
|
'all',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -160,12 +182,12 @@ export class HackerNews implements INodeType {
|
||||||
displayName: 'Limit',
|
displayName: 'Limit',
|
||||||
name: 'limit',
|
name: 'limit',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 5,
|
default: 100,
|
||||||
description: 'Limit of Hacker News articles to be returned for the query.',
|
description: 'Limit of Hacker News articles to be returned for the query.',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'article',
|
'all',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -211,7 +233,7 @@ export class HackerNews implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource: [
|
||||||
'article',
|
'all',
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
|
@ -285,15 +307,8 @@ export class HackerNews implements INodeType {
|
||||||
let endpoint = '';
|
let endpoint = '';
|
||||||
let includeComments = false;
|
let includeComments = false;
|
||||||
|
|
||||||
if (resource === 'article') {
|
if (resource === 'all') {
|
||||||
|
if (operation === 'getAll') {
|
||||||
if (operation === 'get') {
|
|
||||||
|
|
||||||
endpoint = `items/${this.getNodeParameter('articleId', i)}`;
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
|
||||||
includeComments = additionalFields.includeComments as boolean;
|
|
||||||
|
|
||||||
} else if (operation === 'getAll') {
|
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
const keyword = additionalFields.keyword as string;
|
const keyword = additionalFields.keyword as string;
|
||||||
|
@ -301,7 +316,7 @@ export class HackerNews implements INodeType {
|
||||||
|
|
||||||
qs = {
|
qs = {
|
||||||
query: keyword,
|
query: keyword,
|
||||||
tags: tags ? tags.join() : '',
|
tags: tags ? tags.join() : '',
|
||||||
};
|
};
|
||||||
|
|
||||||
returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
@ -315,6 +330,17 @@ export class HackerNews implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`The operation '${operation}' is unknown!`);
|
throw new Error(`The operation '${operation}' is unknown!`);
|
||||||
}
|
}
|
||||||
|
} else if (resource === 'article') {
|
||||||
|
|
||||||
|
if (operation === 'get') {
|
||||||
|
|
||||||
|
endpoint = `items/${this.getNodeParameter('articleId', i)}`;
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
includeComments = additionalFields.includeComments as boolean;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error(`The operation '${operation}' is unknown!`);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (resource === 'user') {
|
} else if (resource === 'user') {
|
||||||
|
|
||||||
|
@ -335,7 +361,7 @@ export class HackerNews implements INodeType {
|
||||||
responseData = await hackerNewsApiRequestAllItems.call(this, 'GET', endpoint, qs);
|
responseData = await hackerNewsApiRequestAllItems.call(this, 'GET', endpoint, qs);
|
||||||
} else {
|
} else {
|
||||||
responseData = await hackerNewsApiRequest.call(this, 'GET', endpoint, qs);
|
responseData = await hackerNewsApiRequest.call(this, 'GET', endpoint, qs);
|
||||||
if (resource === 'article' && operation === 'getAll') {
|
if (resource === 'all' && operation === 'getAll') {
|
||||||
responseData = responseData.hits;
|
responseData = responseData.hits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue